iT邦幫忙

1

可否 ASP+.NET 串 藍新金流呢?

  • 分享至 

  • xImage

網站是ASP,要串藍新金流,
可否ASP網站+.NET 來串藍新金流呢?
PS:網站伺服器是可以跑.NET的
可否請各位先進,有範例可以給我參考呢?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
純真的人
iT邦大師 1 級 ‧ 2022-12-01 11:33:44
最佳解答

藍新只有PHP範例~
當初根據PHP用法改成.net方式~研究一段時間了吧@@"
只是這購物網後來長官們就沒繼續用了..我節一頁程式碼給你參考...

有問題可以問藍新Mail客服...沒電話給你問..
https://ithelp.ithome.com.tw/upload/images/20221201/20061369nUV7ukL6ii.jpg

程式碼有稍微刪除一些~因為我習慣都寫在一頁~你參考看看..

<%@ Page Title="" Language="VB" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<script runat="server">
    Public Sql As String = ""
    Public func As Object = New func '宣告自定義的函數
    Public ds As New System.Data.DataSet, ds2 As New System.Data.DataSet
    
    Public Web_Url As String = ""
    
    'AES加密
    Public Function EncryptAES256(ByVal source As String, sSecretKey As String, iv As String) As String
        
        Dim sourceBytes As Byte() = AddPKCS7Padding(Encoding.UTF8.GetBytes(source), 32)
        
        Dim Aes As RijndaelManaged = New RijndaelManaged()
        Aes.Key = Encoding.UTF8.GetBytes(sSecretKey)
        Aes.IV = Encoding.UTF8.GetBytes(iv)
        Aes.Mode = CipherMode.CBC
        Aes.Padding = PaddingMode.None
        Dim transform As ICryptoTransform = Aes.CreateEncryptor()
        
        Return ByteArrayToHex(transform.TransformFinalBlock(sourceBytes, 0, sourceBytes.Length)).ToLower()
    End Function
    
    '將字串補位為可32位數整除的長度
    Private Shared Function AddPKCS7Padding(ByVal data As Byte(), iBlockSize As Integer) As Byte()
        '取得字串長度
        Dim iLength As Integer = data.Length
        Dim i As Integer
        '區塊長度 - 取計算長度的餘數 = 設定要補位Byte數
        Dim cPadding As Byte = CByte((iBlockSize - (iLength Mod iBlockSize)))
        '重新變更新的Byte空間陣列
        Dim output = New Byte(iLength + cPadding - 1) {}
        '複製原始的data Byte空間資料到新的output Byte空間資料位置
        System.Buffer.BlockCopy(data, 0, output, 0, iLength)
        '開始補位(可被32位數整除)
        For i = iLength To output.Length - 1
            output(i) = CByte(cPadding)
        Next
        Return output
    End Function
        
    '將位元轉換成字串顯示(將10進制轉換成16進制符號)
    Private Shared Function ByteArrayToHex(ByVal barray As Byte()) As String
        Dim c As Char() = New Char(barray.Length * 2 - 1) {}
        Dim b As Byte

        For i As Integer = 0 To barray.Length - 1
            b = (CByte((barray(i) >> 4)))
            c(i * 2) = ChrW((If(b > 9, b + &H37, b + &H30)))
            b = (CByte((barray(i) And &HF)))
            c(i * 2 + 1) = ChrW((If(b > 9, b + &H37, b + &H30)))
        Next

        Return New String(c)
    End Function

    'AES解密
    Public Function DecryptAES256(ByVal encryptData As String, sSecretKey As String, iv As String) As String
        Dim encryptDataChar() As Char = encryptData.ToUpper().ToCharArray
        
        Dim encryptBytes As Byte() = HexStringToByteArray(encryptDataChar)
        Dim aes = New RijndaelManaged()
        aes.Key = Encoding.UTF8.GetBytes(sSecretKey)
        aes.IV = Encoding.UTF8.GetBytes(iv)
        aes.Mode = CipherMode.CBC
        aes.Padding = PaddingMode.None
        Dim transform As ICryptoTransform = aes.CreateDecryptor()
        Return Encoding.UTF8.GetString(RemovePKCS7Padding(transform.TransformFinalBlock(encryptBytes, 0, encryptBytes.Length)))
    End Function
    
    '將字串轉換成位元顯示(將16進制轉換成10進制符號)
    Private Shared Function HexStringToByteArray(ByVal hexString() As Char) As Byte()
        Dim hexStringLength As Integer = hexString.Length
        Dim b As Byte() = New Byte(hexStringLength / 2 - 1) {}

        For i As Integer = 0 To hexStringLength - 1 Step 2
            Dim topAes As Integer = AscW(hexString(i))
            Dim topChar As Integer = If(topAes > &H40, topAes - &H37, topAes - &H30) << 4
            Dim bottomAes As Integer = AscW(hexString(i + 1))
            Dim bottomChar As Integer = If(bottomAes > &H40, bottomAes - &H37, bottomAes - &H30)
            b(i / 2) = Convert.ToByte(topChar + bottomChar)
        Next

        Return b
    End Function

    '剔除字串補位符號
    Private Shared Function RemovePKCS7Padding(ByVal data As Byte()) As Byte()
        Dim iLength As Integer = data(data.Length - 1)
        Dim output = New Byte(data.Length - iLength - 1) {}
        System.Buffer.BlockCopy(data, 0, output, 0, output.Length)
        Return output
    End Function

    Public Function SHA256_Encrypt(ByVal Content As String) As String
        Dim sha256 As New System.Security.Cryptography.SHA256CryptoServiceProvider
        Dim ByteString() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
        ByteString = sha256.ComputeHash(ByteString)
        Dim ReturnString As String = Nothing
        For Each bt As Byte In ByteString
            ReturnString &= bt.ToString("x2")
        Next
        Return ReturnString
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim HashKey As String = "xxxxxxxxxxxxxxxx"
        Dim HashIV As String = "xxxxxxxxxxxxxxxx"
        Dim PostUrl As String = "https://core.newebpay.com/MPG/mpg_gateway"

        Web_Url = Request.ServerVariables("SERVER_NAME")
        
        '前端資料
        Dim Orders_ID As Integer = func.CkNum(Request("Orders_ID"))
        
        '建立藍新交易訂單
        Sql = ""
        Sql &= " declare @Orders_ID int = " & Orders_ID
        Sql &= " declare @bPayOrders_ID int = 0"

        Sql &= " insert into bPayOrders("
        Sql &= " 	bPayOrders_ID"
        Sql &= " 	,bPayOrders_OrdID"
        Sql &= " 	,bPayOrders_MerchantID"
        Sql &= " 	,bPayOrders_RespondType"
        Sql &= " 	,bPayOrders_TimeStamp"
        Sql &= " 	,bPayOrders_Version"
        Sql &= " 	,bPayOrders_MerchantOrderNo"
        Sql &= " 	,bPayOrders_Amt"
        Sql &= " 	,bPayOrders_ItemDesc"
        Sql &= " 	,bPayOrders_ReturnURL"
        Sql &= " 	,bPayOrders_NotifyURL"
        Sql &= " 	,bPayOrders_CustomerURL"
        Sql &= " 	,bPayOrders_Email"
        Sql &= " 	,bPayOrders_LoginType"
        Sql &= " 	,bPayOrders_CREDIT"
        Sql &= " 	,bPayOrders_InstFlag"
        Sql &= " 	,bPayOrders_WEBATM"
        Sql &= " 	,bPayOrders_VACC"
        Sql &= " 	,bPayOrders_BARCODE"
        Sql &= " 	,bPayOrders_Create_Date"
        Sql &= " )"
        Sql &= " select isNull((select max(bPayOrders_ID) from bPayOrders),0) + 1 as bPayOrders_ID"
        Sql &= " ,Orders_ID as bPayOrders_OrdID"
        Sql &= " ,isNull((select top 1 Coding_Contents from Coding where Coding_Group_Num = 30),'') as bPayOrders_MerchantID"
        Sql &= " ,'JSON' as bPayOrders_RespondType"
        Sql &= " ,DATEDIFF(SECOND,'1970-01-01',dateadd(hour,-8,GETUTCDATE())) as bPayOrders_TimeStamp"
        Sql &= " ,'1.5' as bPayOrders_Version"
        Sql &= " ,'TA' "
        Sql &= " + Convert(varchar,Year(GetDate()) - 1911)"
        Sql &= " + Right('0' + Convert(varchar,Month(GetDate())),2)"
        Sql &= " + Right('0' + Convert(varchar,Day(GetDate())),2)"
        Sql &= " + Right('00' + Convert(varchar,isNull(("
        Sql &= " 	select count(0)"
        Sql &= " 	from bPayOrders"
        Sql &= " ),0) + 1),3) "
        Sql &= " as bPayOrders_MerchantOrderNo"
        Sql &= " ,(Orders_TotalCash - Orders_DiscountCash + Orders_Shipping) as bPayOrders_Amt"
        Sql &= " ,N'JedaGo' as bPayOrders_ItemDesc"
        Sql &= " ,'https://" & Web_Url & "/Orders/URL1.aspx' as bPayOrders_ReturnURL"
        Sql &= " ,'https://" & Web_Url & "/Orders/URL2.aspx' as bPayOrders_NotifyURL"
        Sql &= " ,'https://" & Web_Url & "/Orders/URL3.aspx' as bPayOrders_CustomerURL"
        Sql &= " ,Orders_MemAD bPayOrders_Email"
        Sql &= " ,0 as bPayOrders_LoginType"
        Sql &= " ,(case when Orders_Pay_To = 1 then 1 else 0 end) as bPayOrders_CREDIT"
        Sql &= " ,(case when Orders_Pay_To = 1 then 1 else 0 end) as bPayOrders_InstFlag"
        Sql &= " ,(case when Orders_Pay_To = 2 then 1 else 0 end) as bPayOrders_WEBATM"
        Sql &= " ,(case when Orders_Pay_To = 2 then 1 else 0 end) as bPayOrders_VACC"
        Sql &= " ,(case when Orders_Pay_To = 3 then 1 else 0 end) as bPayOrders_BARCODE"
        Sql &= " ,GetDate() bPayOrders_Create_Date"
        Sql &= " from Orders"
        Sql &= " where Orders_ID = @Orders_ID"

        Sql &= " select @bPayOrders_ID=max(bPayOrders_ID)"
        Sql &= " from bPayOrders"
        Sql &= " where bPayOrders_OrdID = @Orders_ID"

        Sql &= " insert into bPay("
        Sql &= " 	bPay_ID"
        Sql &= " 	,bPay_FromID"
        Sql &= " 	,bPay_OrdID"
        Sql &= " 	,bPay_To"
        Sql &= " 	,bPay_MerchantID"
        Sql &= " 	,bPay_TradeInfo"
        Sql &= " 	,bPay_TradeSha"
        Sql &= " 	,bPay_Version"
        Sql &= " 	,bPay_Create_Date"
        Sql &= " )"
        Sql &= " select isNull((select max(bPay_ID) from bPay),0) + 1 as bPay_ID"
        Sql &= " ,@bPayOrders_ID as bPay_FromID"
        Sql &= " ,@Orders_ID as bPay_OrdID"
        Sql &= " ,1 as bPay_To"
        Sql &= " ,bPayOrders_MerchantID as bPay_MerchantID"
        Sql &= " ,'' as bPay_TradeInfo"
        Sql &= " ,'' as bPay_TradeSha"
        Sql &= " ,bPayOrders_Version as bPay_Version"
        Sql &= " ,GetDate() as bPay_Create_Date"
        Sql &= " from bPayOrders"
        Sql &= " where bPayOrders_ID = @bPayOrders_ID"

        Sql &= " select *"
        Sql &= " from bPayOrders"
        Sql &= " where bPayOrders_ID = @bPayOrders_ID"
        ds = func.Data_OP("MSSQL", Sql, "select")
        If ds.Tables(0).Rows.Count > 0 Then
            Dim Rs As System.Data.DataRow = ds.Tables(0).Rows(0)
            
            Dim bPayOrders_ID As Integer = Rs.Item("bPayOrders_ID")
            
            Dim bPayOrders_MerchantID As String = Rs.Item("bPayOrders_MerchantID") & ""
            Dim bPayOrders_RespondType As String = Rs.Item("bPayOrders_RespondType") & ""
            Dim bPayOrders_TimeStamp As String = Rs.Item("bPayOrders_TimeStamp") & ""
            Dim bPayOrders_Version As String = Rs.Item("bPayOrders_Version") & ""
            Dim bPayOrders_MerchantOrderNo As String = Rs.Item("bPayOrders_MerchantOrderNo") & ""
            Dim bPayOrders_Amt As Integer = Rs.Item("bPayOrders_Amt") & ""
            Dim bPayOrders_ItemDesc As String = Rs.Item("bPayOrders_ItemDesc") & ""
            Dim bPayOrders_ReturnURL As String = Rs.Item("bPayOrders_ReturnURL") & ""
            Dim bPayOrders_NotifyURL As String = Rs.Item("bPayOrders_NotifyURL") & ""
            Dim bPayOrders_CustomerURL As String = Rs.Item("bPayOrders_CustomerURL") & ""
            Dim bPayOrders_Email As String = Rs.Item("bPayOrders_Email") & ""
            Dim bPayOrders_LoginType As Integer = Rs.Item("bPayOrders_LoginType") & ""
            Dim bPayOrders_CREDIT As Integer = Rs.Item("bPayOrders_CREDIT") & ""
            Dim bPayOrders_InstFlag As String = Rs.Item("bPayOrders_InstFlag") & ""
            Dim bPayOrders_WEBATM As Integer = Rs.Item("bPayOrders_WEBATM") & ""
            Dim bPayOrders_VACC As Integer = Rs.Item("bPayOrders_VACC") & ""
            Dim bPayOrders_BARCODE As Integer = Rs.Item("bPayOrders_BARCODE") & ""

            '建立Json資料開始編碼
            Dim Json As String = ""
            Json &= "{"
            Json &= """MerchantID"":""" & bPayOrders_MerchantID & """"
            Json &= ",""RespondType"":""" & bPayOrders_RespondType & """"
            Json &= ",""TimeStamp"":""" & bPayOrders_TimeStamp & """"
            Json &= ",""Version"":""" & bPayOrders_Version & """"
            Json &= ",""MerchantOrderNo"":""" & bPayOrders_MerchantOrderNo & """"
            Json &= ",""Amt"":" & bPayOrders_Amt & ""
            Json &= ",""ItemDesc"":""" & bPayOrders_ItemDesc & """"
            Json &= ",""ReturnURL"":""" & bPayOrders_ReturnURL & """"
            Json &= ",""NotifyURL"":""" & bPayOrders_NotifyURL & """"
            Json &= ",""CustomerURL"":""" & bPayOrders_CustomerURL & """"
            Json &= ",""Email"":""" & bPayOrders_Email & """"
            Json &= ",""LoginType"":" & bPayOrders_LoginType & ""
            Json &= ",""CREDIT"":" & bPayOrders_CREDIT & ""
            Json &= ",""InstFlag"":""" & bPayOrders_InstFlag & """"
            Json &= ",""WEBATM"":" & bPayOrders_WEBATM & ""
            Json &= ",""VACC"":" & bPayOrders_VACC & ""
            Json &= ",""BARCODE"":" & bPayOrders_BARCODE & ""
            Json &= "}"
        
            '建立網址參數開始編碼
            Dim SetUrl As String = "MerchantID=" & bPayOrders_MerchantID
            SetUrl &= "&RespondType=" & bPayOrders_RespondType
            SetUrl &= "&TimeStamp=" & bPayOrders_TimeStamp
            SetUrl &= "&Version=" & bPayOrders_Version
            SetUrl &= "&MerchantOrderNo=" & bPayOrders_MerchantOrderNo
            SetUrl &= "&Amt=" & bPayOrders_Amt
            SetUrl &= "&ItemDesc=" & bPayOrders_ItemDesc
            SetUrl &= "&ReturnURL=" & Server.UrlEncode(bPayOrders_ReturnURL)
            SetUrl &= "&NotifyURL=" & Server.UrlEncode(bPayOrders_NotifyURL)
            SetUrl &= "&CustomerURL=" & Server.UrlEncode(bPayOrders_CustomerURL)
            SetUrl &= "&Email=" & Server.UrlEncode(bPayOrders_Email)
            SetUrl &= "&LoginType=" & bPayOrders_LoginType
            SetUrl &= "&CREDIT=" & bPayOrders_CREDIT
            SetUrl &= "&InstFlag=" & bPayOrders_InstFlag
            SetUrl &= "&WEBATM=" & bPayOrders_WEBATM
            SetUrl &= "&VACC=" & bPayOrders_VACC
            SetUrl &= "&BARCODE=" & bPayOrders_BARCODE
            
            Dim En_Aes As String = ""
            En_Aes = EncryptAES256(SetUrl, HashKey, HashIV)
            
            Dim Aes_Str As String = "HashKey=" & HashKey & "&" & En_Aes & "&HashIV=" & HashIV
            
            Dim SHA256 As String = SHA256_Encrypt(Aes_Str).ToUpper
            
            '紀錄交易加密驗證
            Sql = "update bPay"
            Sql &= " set bPay_TradeInfo = N'" & En_Aes & "'"
            Sql &= " ,bPay_TradeSha = N'" & SHA256 & "'"
            Sql &= " where bPay_FromID = " & bPayOrders_ID
            Call func.Data_OP("MSSQL", Sql, "update")
            
            '傳送到藍新金流開始交易
            Dim bPay As SortedDictionary(Of String, String) = New SortedDictionary(Of String, String)
            bPay.Add("MerchantID", bPayOrders_MerchantID)
            bPay.Add("TradeInfo", En_Aes)
            bPay.Add("TradeSha", SHA256)
            bPay.Add("Version", bPayOrders_Version)
            
            System.Net.ServicePointManager.SecurityProtocol = CType(3072, System.Net.SecurityProtocolType)
            Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
        
            sb.Append("<html><body>").AppendLine()
            sb.Append("<form name='postdata'  id='postdata' action='" + PostUrl + "' method='POST'>").AppendLine()
            For Each aa In bPay
                sb.Append("<input type='hidden' name='" + aa.Key + "' value='" + aa.Value + "'>").AppendLine()
            Next

            sb.Append("</form>").AppendLine()
            sb.Append("<" & "script > var theForm = document.forms['postdata'];  if (!theForm) { theForm = document.postdata; } theForm.submit(); </" & "script>").AppendLine()
            sb.Append("<html><body>").AppendLine()

            Response.Write(sb.ToString())
            Response.End()

        End If
        
    End Sub
</script>

看更多先前的回應...收起先前的回應...
addwe iT邦新手 5 級 ‧ 2022-12-01 16:04:41 檢舉

感謝你的回覆,我會好好研究。
再請問您,接收端也要解密...是否回傳的接收端也是需要.NET網頁,
處理好之後,再轉到ASP網頁呢?

接收端~當然也是.net網頁~因為需要解密回去~

URL1.aspx 從藍新交易完成的導回頁

<%@ Page Title="" Language="VB"  %>
<%@ Import Namespace="System.Security.Cryptography" %>
<script runat="server">
    Public Sql As String = ""
    Public func As Object = New func '宣告自定義的函數
    Public ds As New System.Data.DataSet, ds2 As New System.Data.DataSet

    'AES加密
    Public Function EncryptAES256(ByVal source As String, sSecretKey As String, iv As String) As String
        
        Dim sourceBytes As Byte() = AddPKCS7Padding(Encoding.UTF8.GetBytes(source), 32)
        
        Dim Aes As RijndaelManaged = New RijndaelManaged()
        Aes.Key = Encoding.UTF8.GetBytes(sSecretKey)
        Aes.IV = Encoding.UTF8.GetBytes(iv)
        Aes.Mode = CipherMode.CBC
        Aes.Padding = PaddingMode.None
        Dim transform As ICryptoTransform = Aes.CreateEncryptor()
        
        Return ByteArrayToHex(transform.TransformFinalBlock(sourceBytes, 0, sourceBytes.Length)).ToLower()
    End Function
    
    '將字串補位為可32位數整除的長度
    Private Shared Function AddPKCS7Padding(ByVal data As Byte(), iBlockSize As Integer) As Byte()
        '取得字串長度
        Dim iLength As Integer = data.Length
        Dim i As Integer
        '區塊長度 - 取計算長度的餘數 = 設定要補位Byte數
        Dim cPadding As Byte = CByte((iBlockSize - (iLength Mod iBlockSize)))
        '重新變更新的Byte空間陣列
        Dim output = New Byte(iLength + cPadding - 1) {}
        '複製原始的data Byte空間資料到新的output Byte空間資料位置
        System.Buffer.BlockCopy(data, 0, output, 0, iLength)
        '開始補位(可被32位數整除)
        For i = iLength To output.Length - 1
            output(i) = CByte(cPadding)
        Next
        Return output
    End Function
        
    '將位元轉換成字串顯示(將10進制轉換成16進制符號)
    Private Shared Function ByteArrayToHex(ByVal barray As Byte()) As String
        Dim c As Char() = New Char(barray.Length * 2 - 1) {}
        Dim b As Byte

        For i As Integer = 0 To barray.Length - 1
            b = (CByte((barray(i) >> 4)))
            c(i * 2) = ChrW((If(b > 9, b + &H37, b + &H30)))
            b = (CByte((barray(i) And &HF)))
            c(i * 2 + 1) = ChrW((If(b > 9, b + &H37, b + &H30)))
        Next

        Return New String(c)
    End Function

    'AES解密
    Public Function DecryptAES256(ByVal encryptData As String, sSecretKey As String, iv As String) As String
        Dim encryptDataChar() As Char = encryptData.ToUpper().ToCharArray
        
        Dim encryptBytes As Byte() = HexStringToByteArray(encryptDataChar)
        Dim aes = New RijndaelManaged()
        aes.Key = Encoding.UTF8.GetBytes(sSecretKey)
        aes.IV = Encoding.UTF8.GetBytes(iv)
        aes.Mode = CipherMode.CBC
        aes.Padding = PaddingMode.None
        Dim transform As ICryptoTransform = aes.CreateDecryptor()
        Return Encoding.UTF8.GetString(RemovePKCS7Padding(transform.TransformFinalBlock(encryptBytes, 0, encryptBytes.Length)))
    End Function
    
    '將字串轉換成位元顯示(將16進制轉換成10進制符號)
    Private Shared Function HexStringToByteArray(ByVal hexString() As Char) As Byte()
        Dim hexStringLength As Integer = hexString.Length
        Dim b As Byte() = New Byte(hexStringLength / 2 - 1) {}

        For i As Integer = 0 To hexStringLength - 1 Step 2
            Dim topAes As Integer = AscW(hexString(i))
            Dim topChar As Integer = If(topAes > &H40, topAes - &H37, topAes - &H30) << 4
            Dim bottomAes As Integer = AscW(hexString(i + 1))
            Dim bottomChar As Integer = If(bottomAes > &H40, bottomAes - &H37, bottomAes - &H30)
            b(i / 2) = Convert.ToByte(topChar + bottomChar)
        Next

        Return b
    End Function

    '剔除字串補位符號
    Private Shared Function RemovePKCS7Padding(ByVal data As Byte()) As Byte()
        Dim iLength As Integer = data(data.Length - 1)
        Dim output = New Byte(data.Length - iLength - 1) {}
        System.Buffer.BlockCopy(data, 0, output, 0, output.Length)
        Return output
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        Dim Str_Query As String = ""
        Dim Str_Form As String = ""
        
        Dim Item As String = ""
        Dim TradeInfo As String = ""
        
        For Each Item In Request.QueryString
            If Str_Query = "" Then
                Str_Query = "?" & Item & "=" & Request.QueryString(Item)
            Else
                Str_Query &= "&" & Item & "=" & Request.QueryString(Item)
            End If

            Select Case Item
                Case "TradeInfo"
                    TradeInfo = func.CkStr(Request.QueryString(Item))
            End Select

        Next
        
        For Each Item In Request.Form
            If Str_Form = "" Then
                Str_Form = "?" & Item & "=" & Request.Form(Item)
            Else
                Str_Form &= "&" & Item & "=" & Request.Form(Item)
            End If

            Select Case Item
                Case "TradeInfo"
                    TradeInfo = func.CkStr(Request.Form(Item))
            End Select

        Next
        
        '紀錄藍新原始傳送資料
        If Str_Query <> "" Or Str_Form <> "" Then
            
            Sql = "insert into RequestData("
            Sql &= " RequestData_ID"
            Sql &= " ,RequestData_Query"
            Sql &= " ,RequestData_Form"
            Sql &= " ,RequestData_Create_Date"
            Sql &= " ,RequestData_To"
            Sql &= ") select isNull((select max(RequestData_ID) from RequestData),0) + 1 as RequestData_ID"
            Sql &= ",N'" & Str_Query & "' as RequestData_Query"
            Sql &= ",N'" & Str_Form & "' as RequestData_Form"
            Sql &= ",GetDate() as RequestData_Create_Date"
            Sql &= ",1 as RequestData_To"
            Call func.Data_OP("MSSQL", Sql, "insert")

        End If
        
        Dim HashKey As String = "xxxxxxxxxxxxxxx"
        Dim HashIV As String = "xxxxxxxxxxxxxxx"
        
        Dim bPayOrders_OrdID As Integer = 0

        If TradeInfo <> "" Then

            Dim De_Aes As String = DecryptAES256(TradeInfo, HashKey, HashIV)

            Dim Obj As Newtonsoft.Json.Linq.JObject
            Dim Json As String = ""
        
            Obj = Newtonsoft.Json.Linq.JObject.Parse(De_Aes)

            Dim Status As String = ""
            Dim Message As String = ""
            Dim Result As String = ""
            
            Dim MerchantID As String = ""
            Dim Amt As String = "0"
            Dim TradeNo As String = ""
            Dim MerchantOrderNo As String = ""
            Dim PaymentType As String = ""
            Dim RespondType As String = ""
            Dim PayTime As String = ""
            Dim IP As String = ""
            Dim EscrowBank As String = ""
            Dim AuthBank As String = ""
            Dim RespondCode As String = ""
            Dim Auth As String = ""
            Dim Card6No As String = ""
            Dim Card4No As String = ""
            Dim Inst As String = "0"
            Dim InstFirst As String = "0"
            Dim InstEach As String = "0"
            Dim ECI As String = ""
            Dim TokenUseStatus As String = "0"
            Dim RedAmt As String = "0"
            Dim PaymentMethod As String = ""
            Dim DCC_Amt As String = "0"
            Dim DCC_Rate As String = "0"
            Dim DCC_Markup As String = "0"
            Dim DCC_Currency As String = ""
            Dim DCC_Currency_Code As String = "0"
            Dim PayBankCode As String = ""
            Dim PayerAccount5Code As String = ""
            Dim CodeNo As String = ""
            Dim StoreType As String = ""
            Dim StoreID As String = ""
            Dim Barcode_1 As String = ""
            Dim Barcode_2 As String = ""
            Dim Barcode_3 As String = ""
            Dim PayStore As String = ""
            Dim P2GTradeNo As String = ""
            Dim P2GPaymentType As String = ""
            Dim P2GAmt As String = "0"
            Dim StoreCode As String = ""
            Dim StoreName As String = ""
            Dim StoreAddr As String = ""
            Dim TradeType As String = "0"
            Dim CVSCOMName As String = ""
            Dim CVSCOMPhone As String = ""
            Dim ChannelID As String = ""
            Dim ChannelNo As String = ""
            Dim Create_Date As String = ""

            Status = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Status")), """", "")
            Message = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Message")), """", "")
            Result = Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Result"))
        
            If Result <> "" Then
            
                Obj = Newtonsoft.Json.Linq.JObject.Parse(Result)
            
                MerchantID = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("MerchantID")), """", "")
                Amt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Amt")), """", ""))
                TradeNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("TradeNo")), """", "")
                MerchantOrderNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("MerchantOrderNo")), """", "")
                PaymentType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PaymentType")), """", "")
                RespondType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("RespondType")), """", "")
                PayTime = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayTime")), """", "")
                IP = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("IP")), """", "")
                EscrowBank = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("EscrowBank")), """", "")
                AuthBank = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("AuthBank")), """", "")
                RespondCode = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("RespondCode")), """", "")
                Auth = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Auth")), """", "")
                Auth = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Auth")), """", "")
                Card4No = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Card4No")), """", "")
                Inst = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Inst")), """", ""))
                InstFirst = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("InstFirst")), """", ""))
                InstEach = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("InstEach")), """", ""))
                ECI = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("ECI")), """", "")
                TokenUseStatus = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("TokenUseStatus")), """", ""))
                RedAmt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("RedAmt")), """", ""))
                PaymentMethod = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PaymentMethod")), """", "")
                DCC_Amt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Amt")), """", ""))
                DCC_Rate = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Rate")), """", ""))
                DCC_Markup = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Markup")), """", ""))
                DCC_Currency = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Currency")), """", "")
                DCC_Currency_Code = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Currency_Code")), """", ""))
                PayBankCode = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayBankCode")), """", "")
                PayerAccount5Code = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayerAccount5Code")), """", "")
                CodeNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("CodeNo")), """", "")
                StoreType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreType")), """", "")
                StoreID = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreID")), """", "")
                Barcode_1 = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Barcode_1")), """", "")
                Barcode_2 = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Barcode_2")), """", "")
                Barcode_3 = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Barcode_3")), """", "")
                PayStore = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayStore")), """", "")
                P2GTradeNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("P2GTradeNo")), """", "")
                P2GPaymentType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("P2GPaymentType")), """", "")
                P2GAmt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("P2GAmt")), """", ""))
                StoreCode = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreCode")), """", "")
                StoreName = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreName")), """", "")
                StoreAddr = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreAddr")), """", "")
                TradeType = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("TradeType")), """", ""))
                CVSCOMName = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("CVSCOMName")), """", "")
                CVSCOMPhone = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("CVSCOMPhone")), """", "")
                ChannelID = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("ChannelID")), """", "")
                ChannelNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("ChannelNo")), """", "")

            End If

            Sql = ""
            Sql &= " select bPayOrders_OrdID"
            Sql &= " from bPayOrders"
            Sql &= " where bPayOrders_MerchantOrderNo = '" & MerchantOrderNo & "'"
            ds = func.Data_OP("MSSQL", Sql, "select")
            If ds.Tables(0).Rows.Count > 0 Then
                Dim Rs As System.Data.DataRow = ds.Tables(0).Rows(0)
                bPayOrders_OrdID = Rs.Item("bPayOrders_OrdID")
            End If

        End If

        Response.Redirect("Orders.aspx?Orders_ID=" & bPayOrders_OrdID)
        
    End Sub
</script>

URL2.aspx 交易完成結果紀錄頁

<%@ Page Title="" Language="VB"  %>
<%@ Import Namespace="System.Security.Cryptography" %>
<script runat="server">
    Public Sql As String = ""
    Public func As Object = New func '宣告自定義的函數
    Public ds As New System.Data.DataSet, ds2 As New System.Data.DataSet

    'AES加密
    Public Function EncryptAES256(ByVal source As String, sSecretKey As String, iv As String) As String
        
        Dim sourceBytes As Byte() = AddPKCS7Padding(Encoding.UTF8.GetBytes(source), 32)
        
        Dim Aes As RijndaelManaged = New RijndaelManaged()
        Aes.Key = Encoding.UTF8.GetBytes(sSecretKey)
        Aes.IV = Encoding.UTF8.GetBytes(iv)
        Aes.Mode = CipherMode.CBC
        Aes.Padding = PaddingMode.None
        Dim transform As ICryptoTransform = Aes.CreateEncryptor()
        
        Return ByteArrayToHex(transform.TransformFinalBlock(sourceBytes, 0, sourceBytes.Length)).ToLower()
    End Function
    
    '將字串補位為可32位數整除的長度
    Private Shared Function AddPKCS7Padding(ByVal data As Byte(), iBlockSize As Integer) As Byte()
        '取得字串長度
        Dim iLength As Integer = data.Length
        Dim i As Integer
        '區塊長度 - 取計算長度的餘數 = 設定要補位Byte數
        Dim cPadding As Byte = CByte((iBlockSize - (iLength Mod iBlockSize)))
        '重新變更新的Byte空間陣列
        Dim output = New Byte(iLength + cPadding - 1) {}
        '複製原始的data Byte空間資料到新的output Byte空間資料位置
        System.Buffer.BlockCopy(data, 0, output, 0, iLength)
        '開始補位(可被32位數整除)
        For i = iLength To output.Length - 1
            output(i) = CByte(cPadding)
        Next
        Return output
    End Function
        
    '將位元轉換成字串顯示(將10進制轉換成16進制符號)
    Private Shared Function ByteArrayToHex(ByVal barray As Byte()) As String
        Dim c As Char() = New Char(barray.Length * 2 - 1) {}
        Dim b As Byte

        For i As Integer = 0 To barray.Length - 1
            b = (CByte((barray(i) >> 4)))
            c(i * 2) = ChrW((If(b > 9, b + &H37, b + &H30)))
            b = (CByte((barray(i) And &HF)))
            c(i * 2 + 1) = ChrW((If(b > 9, b + &H37, b + &H30)))
        Next

        Return New String(c)
    End Function

    'AES解密
    Public Function DecryptAES256(ByVal encryptData As String, sSecretKey As String, iv As String) As String
        Dim encryptDataChar() As Char = encryptData.ToUpper().ToCharArray
        
        Dim encryptBytes As Byte() = HexStringToByteArray(encryptDataChar)
        Dim aes = New RijndaelManaged()
        aes.Key = Encoding.UTF8.GetBytes(sSecretKey)
        aes.IV = Encoding.UTF8.GetBytes(iv)
        aes.Mode = CipherMode.CBC
        aes.Padding = PaddingMode.None
        Dim transform As ICryptoTransform = aes.CreateDecryptor()
        Return Encoding.UTF8.GetString(RemovePKCS7Padding(transform.TransformFinalBlock(encryptBytes, 0, encryptBytes.Length)))
    End Function
    
    '將字串轉換成位元顯示(將16進制轉換成10進制符號)
    Private Shared Function HexStringToByteArray(ByVal hexString() As Char) As Byte()
        Dim hexStringLength As Integer = hexString.Length
        Dim b As Byte() = New Byte(hexStringLength / 2 - 1) {}

        For i As Integer = 0 To hexStringLength - 1 Step 2
            Dim topAes As Integer = AscW(hexString(i))
            Dim topChar As Integer = If(topAes > &H40, topAes - &H37, topAes - &H30) << 4
            Dim bottomAes As Integer = AscW(hexString(i + 1))
            Dim bottomChar As Integer = If(bottomAes > &H40, bottomAes - &H37, bottomAes - &H30)
            b(i / 2) = Convert.ToByte(topChar + bottomChar)
        Next

        Return b
    End Function

    '剔除字串補位符號
    Private Shared Function RemovePKCS7Padding(ByVal data As Byte()) As Byte()
        Dim iLength As Integer = data(data.Length - 1)
        Dim output = New Byte(data.Length - iLength - 1) {}
        System.Buffer.BlockCopy(data, 0, output, 0, output.Length)
        Return output
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        Dim Str_Query As String = ""
        Dim Str_Form As String = ""
        
        Dim Item As String = ""
        Dim TradeInfo As String = ""

        For Each Item In Request.QueryString
            If Str_Query = "" Then
                Str_Query = "?" & Item & "=" & Request.QueryString(Item)
            Else
                Str_Query &= "&" & Item & "=" & Request.QueryString(Item)
            End If

            Select Case Item
                Case "TradeInfo"
                    TradeInfo = func.CkStr(Request.QueryString(Item))
            End Select

        Next
        
        For Each Item In Request.Form
            If Str_Form = "" Then
                Str_Form = "?" & Item & "=" & Request.Form(Item)
            Else
                Str_Form &= "&" & Item & "=" & Request.Form(Item)
            End If

            Select Case Item
                Case "TradeInfo"
                    TradeInfo = func.CkStr(Request.Form(Item))
            End Select

        Next
        
        '紀錄藍新原始傳送資料
        If Str_Query <> "" Or Str_Form <> "" Then
            
            Sql = "insert into RequestData("
            Sql &= " RequestData_ID"
            Sql &= " ,RequestData_Query"
            Sql &= " ,RequestData_Form"
            Sql &= " ,RequestData_Create_Date"
            Sql &= " ,RequestData_To"
            Sql &= ") select isNull((select max(RequestData_ID) from RequestData),0) + 1 as RequestData_ID"
            Sql &= ",N'" & Str_Query & "' as RequestData_Query"
            Sql &= ",N'" & Str_Form & "' as RequestData_Form"
            Sql &= ",GetDate() as RequestData_Create_Date"
            Sql &= ",2 as RequestData_To"
            Call func.Data_OP("MSSQL", Sql, "insert")

        End If
        
        Dim HashKey As String = "xxxxxxxxxxxxxxx"
        Dim HashIV As String = "xxxxxxxxxxxxxxx"
        
        If TradeInfo <> "" Then

            Dim De_Aes As String = DecryptAES256(TradeInfo, HashKey, HashIV)
        
            Dim Obj As Newtonsoft.Json.Linq.JObject
            Dim Json As String = ""
        
            Obj = Newtonsoft.Json.Linq.JObject.Parse(De_Aes)

            Dim Status As String = ""
            Dim Message As String = ""
            Dim Result As String = ""
            
            Dim MerchantID As String = ""
            Dim Amt As String = "0"
            Dim TradeNo As String = ""
            Dim MerchantOrderNo As String = ""
            Dim PaymentType As String = ""
            Dim RespondType As String = ""
            Dim PayTime As String = ""
            Dim IP As String = ""
            Dim EscrowBank As String = ""
            Dim AuthBank As String = ""
            Dim RespondCode As String = ""
            Dim Auth As String = ""
            Dim Card6No As String = ""
            Dim Card4No As String = ""
            Dim Inst As String = "0"
            Dim InstFirst As String = "0"
            Dim InstEach As String = "0"
            Dim ECI As String = ""
            Dim TokenUseStatus As String = "0"
            Dim RedAmt As String = "0"
            Dim PaymentMethod As String = ""
            Dim DCC_Amt As String = "0"
            Dim DCC_Rate As String = "0"
            Dim DCC_Markup As String = "0"
            Dim DCC_Currency As String = ""
            Dim DCC_Currency_Code As String = "0"
            Dim PayBankCode As String = ""
            Dim PayerAccount5Code As String = ""
            Dim CodeNo As String = ""
            Dim StoreType As String = ""
            Dim StoreID As String = ""
            Dim Barcode_1 As String = ""
            Dim Barcode_2 As String = ""
            Dim Barcode_3 As String = ""
            Dim PayStore As String = ""
            Dim P2GTradeNo As String = ""
            Dim P2GPaymentType As String = ""
            Dim P2GAmt As String = "0"
            Dim StoreCode As String = ""
            Dim StoreName As String = ""
            Dim StoreAddr As String = ""
            Dim TradeType As String = "0"
            Dim CVSCOMName As String = ""
            Dim CVSCOMPhone As String = ""
            Dim ChannelID As String = ""
            Dim ChannelNo As String = ""
            Dim Create_Date As String = ""

            Status = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Status")), """", "")
            Message = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Message")), """", "")
            Result = Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Result"))
        
            If Result <> "" Then
            
                Obj = Newtonsoft.Json.Linq.JObject.Parse(Result)
            
                MerchantID = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("MerchantID")), """", "")
                Amt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Amt")), """", ""))
                TradeNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("TradeNo")), """", "")
                MerchantOrderNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("MerchantOrderNo")), """", "")
                PaymentType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PaymentType")), """", "")
                RespondType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("RespondType")), """", "")
                PayTime = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayTime")), """", "")
                IP = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("IP")), """", "")
                EscrowBank = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("EscrowBank")), """", "")
                AuthBank = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("AuthBank")), """", "")
                RespondCode = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("RespondCode")), """", "")
                Auth = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Auth")), """", "")
                Auth = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Auth")), """", "")
                Card4No = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Card4No")), """", "")
                Inst = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Inst")), """", ""))
                InstFirst = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("InstFirst")), """", ""))
                InstEach = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("InstEach")), """", ""))
                ECI = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("ECI")), """", "")
                TokenUseStatus = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("TokenUseStatus")), """", ""))
                RedAmt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("RedAmt")), """", ""))
                PaymentMethod = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PaymentMethod")), """", "")
                DCC_Amt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Amt")), """", ""))
                DCC_Rate = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Rate")), """", ""))
                DCC_Markup = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Markup")), """", ""))
                DCC_Currency = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Currency")), """", "")
                DCC_Currency_Code = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("DCC_Currency_Code")), """", ""))
                PayBankCode = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayBankCode")), """", "")
                PayerAccount5Code = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayerAccount5Code")), """", "")
                CodeNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("CodeNo")), """", "")
                StoreType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreType")), """", "")
                StoreID = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreID")), """", "")
                Barcode_1 = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Barcode_1")), """", "")
                Barcode_2 = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Barcode_2")), """", "")
                Barcode_3 = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("Barcode_3")), """", "")
                PayStore = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("PayStore")), """", "")
                P2GTradeNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("P2GTradeNo")), """", "")
                P2GPaymentType = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("P2GPaymentType")), """", "")
                P2GAmt = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("P2GAmt")), """", ""))
                StoreCode = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreCode")), """", "")
                StoreName = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreName")), """", "")
                StoreAddr = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("StoreAddr")), """", "")
                TradeType = func.CkNum(Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("TradeType")), """", ""))
                CVSCOMName = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("CVSCOMName")), """", "")
                CVSCOMPhone = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("CVSCOMPhone")), """", "")
                ChannelID = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("ChannelID")), """", "")
                ChannelNo = Replace(Newtonsoft.Json.JsonConvert.SerializeObject(Obj.Item("ChannelNo")), """", "")

                Sql = ""
                Sql &= " insert into bPayPost("
                Sql &= " [bPayPost_ID]"
                Sql &= " ,[bPayPost_OrdID]"
                Sql &= " ,[bPayPost_Status]"
                Sql &= " ,[bPayPost_Message]"
                Sql &= " ,[bPayPost_MerchantID]"
                Sql &= " ,[bPayPost_Amt]"
                Sql &= " ,[bPayPost_TradeNo]"
                Sql &= " ,[bPayPost_MerchantOrderNo]"
                Sql &= " ,[bPayPost_PaymentType]"
                Sql &= " ,[bPayPost_RespondType]"
                Sql &= " ,[bPayPost_PayTime]"
                Sql &= " ,[bPayPost_IP]"
                Sql &= " ,[bPayPost_EscrowBank]"
                Sql &= " ,[bPayPost_AuthBank]"
                Sql &= " ,[bPayPost_RespondCode]"
                Sql &= " ,[bPayPost_Auth]"
                Sql &= " ,[bPayPost_Card6No]"
                Sql &= " ,[bPayPost_Card4No]"
                Sql &= " ,[bPayPost_Inst]"
                Sql &= " ,[bPayPost_InstFirst]"
                Sql &= " ,[bPayPost_InstEach]"
                Sql &= " ,[bPayPost_ECI]"
                Sql &= " ,[bPayPost_TokenUseStatus]"
                Sql &= " ,[bPayPost_RedAmt]"
                Sql &= " ,[bPayPost_PaymentMethod]"
                Sql &= " ,[bPayPost_DCC_Amt]"
                Sql &= " ,[bPayPost_DCC_Rate]"
                Sql &= " ,[bPayPost_DCC_Markup]"
                Sql &= " ,[bPayPost_DCC_Currency]"
                Sql &= " ,[bPayPost_DCC_Currency_Code]"
                Sql &= " ,[bPayPost_PayBankCode]"
                Sql &= " ,[bPayPost_PayerAccount5Code]"
                Sql &= " ,[bPayPost_CodeNo]"
                Sql &= " ,[bPayPost_StoreType]"
                Sql &= " ,[bPayPost_StoreID]"
                Sql &= " ,[bPayPost_Barcode_1]"
                Sql &= " ,[bPayPost_Barcode_2]"
                Sql &= " ,[bPayPost_Barcode_3]"
                Sql &= " ,[bPayPost_PayStore]"
                Sql &= " ,[bPayPost_P2GTradeNo]"
                Sql &= " ,[bPayPost_P2GPaymentType]"
                Sql &= " ,[bPayPost_P2GAmt]"
                Sql &= " ,[bPayPost_StoreCode]"
                Sql &= " ,[bPayPost_StoreName]"
                Sql &= " ,[bPayPost_StoreAddr]"
                Sql &= " ,[bPayPost_TradeType]"
                Sql &= " ,[bPayPost_CVSCOMName]"
                Sql &= " ,[bPayPost_CVSCOMPhone]"
                Sql &= " ,[bPayPost_ChannelID]"
                Sql &= " ,[bPayPost_ChannelNo]"
                Sql &= " ,[bPayPost_Create_Date]"
                Sql &= " )"
                Sql &= " select isNull((select max([bPayPost_ID]) from bPayPost ),0) + 1 as [bPayPost_ID]"
                Sql &= " ,bPayOrders_OrdID [bPayPost_OrdID]"
                Sql &= " ,N'" & Status & "' [bPayPost_Status]"
                Sql &= " ,N'" & Message & "' [bPayPost_Message]"
                Sql &= " ,N'" & MerchantID & "' [bPayPost_MerchantID]"
                Sql &= " ,'" & Amt & "' [bPayPost_Amt]"
                Sql &= " ,N'" & TradeNo & "' [bPayPost_TradeNo]"
                Sql &= " ,bPayOrders_MerchantOrderNo [bPayPost_MerchantOrderNo]"
                Sql &= " ,N'" & PaymentType & "' [bPayPost_PaymentType]"
                Sql &= " ,N'" & RespondType & "' [bPayPost_RespondType]"
                Sql &= " ,(case when isDate('" & PayTime & "') = 1 then '" & PayTime & "' else GetDate() end) [bPayPost_PayTime]"
                Sql &= " ,N'" & IP & "' [bPayPost_IP]"
                Sql &= " ,N'" & EscrowBank & "' [bPayPost_EscrowBank]"
                Sql &= " ,N'" & AuthBank & "' [bPayPost_AuthBank]"
                Sql &= " ,N'" & RespondCode & "' [bPayPost_RespondCode]"
                Sql &= " ,N'" & Auth & "' [bPayPost_Auth]"
                Sql &= " ,N'" & Card6No & "' [bPayPost_Card6No]"
                Sql &= " ,N'" & Card4No & "' [bPayPost_Card4No]"
                Sql &= " ,'" & Inst & "' [bPayPost_Inst]"
                Sql &= " ,'" & InstFirst & "' [bPayPost_InstFirst]"
                Sql &= " ,'" & InstEach & "' [bPayPost_InstEach]"
                Sql &= " ,N'" & ECI & "' [bPayPost_ECI]"
                Sql &= " ,'" & TokenUseStatus & "' [bPayPost_TokenUseStatus]"
                Sql &= " ,'" & RedAmt & "' [bPayPost_RedAmt]"
                Sql &= " ,N'" & PaymentMethod & "' [bPayPost_PaymentMethod]"
                Sql &= " ,'" & DCC_Amt & "' [bPayPost_DCC_Amt]"
                Sql &= " ,'" & DCC_Rate & "' [bPayPost_DCC_Rate]"
                Sql &= " ,'" & DCC_Markup & "' [bPayPost_DCC_Markup]"
                Sql &= " ,N'" & DCC_Currency & "' [bPayPost_DCC_Currency]"
                Sql &= " ,'" & DCC_Currency_Code & "' [bPayPost_DCC_Currency_Code]"
                Sql &= " ,N'" & PayBankCode & "' [bPayPost_PayBankCode]"
                Sql &= " ,N'" & PayerAccount5Code & "' [bPayPost_PayerAccount5Code]"
                Sql &= " ,N'" & CodeNo & "' [bPayPost_CodeNo]"
                Sql &= " ,N'" & StoreType & "' [bPayPost_StoreType]"
                Sql &= " ,N'" & StoreID & "' [bPayPost_StoreID]"
                Sql &= " ,N'" & Barcode_1 & "' [bPayPost_Barcode_1]"
                Sql &= " ,N'" & Barcode_2 & "' [bPayPost_Barcode_2]"
                Sql &= " ,N'" & Barcode_3 & "' [bPayPost_Barcode_3]"
                Sql &= " ,N'" & PayStore & "' [bPayPost_PayStore]"
                Sql &= " ,N'" & P2GTradeNo & "' [bPayPost_P2GTradeNo]"
                Sql &= " ,N'" & P2GPaymentType & "' [bPayPost_P2GPaymentType]"
                Sql &= " ,'" & P2GAmt & "' [bPayPost_P2GAmt]"
                Sql &= " ,N'" & StoreCode & "' [bPayPost_StoreCode]"
                Sql &= " ,N'" & StoreName & "' [bPayPost_StoreName]"
                Sql &= " ,N'" & StoreAddr & "' [bPayPost_StoreAddr]"
                Sql &= " ,'" & TradeType & "' [bPayPost_TradeType]"
                Sql &= " ,N'" & CVSCOMName & "' [bPayPost_CVSCOMName]"
                Sql &= " ,N'" & CVSCOMPhone & "' [bPayPost_CVSCOMPhone]"
                Sql &= " ,N'" & ChannelID & "' [bPayPost_ChannelID]"
                Sql &= " ,N'" & ChannelNo & "' [bPayPost_ChannelNo]"
                Sql &= " ,GetDate() [bPayPost_Create_Date]"
                Sql &= " from bPayOrders"
                Sql &= " where bPayOrders_MerchantOrderNo = '" & MerchantOrderNo & "'"

                Call func.Data_OP("MSSQL", Sql, "insert")
            
                If Message = "SUCCESS" Then
                    '訂單狀態紀錄
                    Sql = ""
                    Sql &= " declare @Orders_ID int = '0'"
                    Sql &= " declare @bPayOrders_MerchantOrderNo nvarchar(50) = '" & MerchantOrderNo & "'"

                    Sql &= " select @Orders_ID = bPayOrders_OrdID"
                    Sql &= " from bPayOrders"
                    Sql &= " where bPayOrders_MerchantOrderNo = @bPayOrders_MerchantOrderNo"

                    Sql &= " if(@Orders_ID > 0)"
                    Sql &= " begin"
                    Sql &= " 	insert into OrdersStatus("
                    Sql &= " 	OrdersStatus_ID"
                    Sql &= " 	,OrdersStatus_OrdID "
                    Sql &= " 	,OrdersStatus_Type_To "
                    Sql &= " 	,OrdersStatus_EmpAD "
                    Sql &= " 	,OrdersStatus_Create_Date "
                    Sql &= " 	)"
                    Sql &= " 	select isNull((select max(OrdersStatus_ID) + 1 from OrdersStatus),1) as OrdersStatus_ID "
                    Sql &= " 	,@Orders_ID as OrdersStatus_OrdID "
                    Sql &= " 	,2 as OrdersStatus_Type_To "
                    Sql &= " 	,N'System' as OrdersStatus_EmpAD "
                    Sql &= " 	,GetDate() as OrdersStatus_Create_Date "

                    Sql &= " 	update Orders"
                    Sql &= " 	set Orders_Type_To = isNull((select top 1 OrdersStatus_Type_To from OrdersStatus where OrdersStatus_OrdID = Orders_ID order by OrdersStatus_Create_Date desc),0)"
                    Sql &= " 	where Orders_ID = @Orders_ID"
                    Sql &= " end"
                    Call func.Data_OP("MSSQL", Sql, "update")

                End If

            End If

        End If

        Response.Write("1|OK")
        
    End Sub
</script>

URL3.aspx 程式碼同URL2.aspx 但這是給ATM之類交易完成通知頁的

addwe iT邦新手 5 級 ‧ 2022-12-01 22:42:29 檢舉

太棒了!!!!
感謝你的回覆,有方向了,謝謝你

1
souda
iT邦高手 1 級 ‧ 2022-11-30 13:00:20

建議您可以這麼做:
藍新官網有範例
https://www.newebpay.com/website/Page/content/download_api

1

只要是可以form data行為的任何動作。(如網頁、APP。)
都可以串接任何API。

藍新的話,你直接去他們的官網找。可以下載範例程式來看。

我要發表回答

立即登入回答