PayGate PayXML集成使用 asp.net 抛出“身份验证失败,因为远程方已关闭传输流”
本文关键字:因为 传输 失败 集成 PayXML asp net 身份验证 抛出 PayGate | 更新日期: 2023-09-27 18:31:39
如何将Paygate支付网关的PayGate PayXML与 asp.net 集成,与c#或vb一起使用。当我运行paygate开发人员登录名提供的示例应用程序时,出现错误"身份验证失败,因为远程方已关闭传输流"。希望这个论坛的任何专家都能帮助我。提前谢谢。
这是我
的代码,如果有人坚持使用Paygate,它可以工作,您需要从nuget导入restsharp
Imports RestSharp
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Net
Imports System.Collections.Specialized
Imports System.Text
Imports WebApplication1.ServiceReference1
Imports System.Security.Cryptography.HashAlgorithm
Public Class _Default
'Inherits Page
Inherits System.Web.UI.Page
Private encryptionKey As String = "secret" ' Addd secret in from comes from Paygate
Public PAYGATE_ID As String = "10011072130"
Public RETURN_URL As String = "http://www.webbis.co.za"
Dim CheckSum As String
Dim PaymentRequestId As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'amount in cents
Paygate("James@webbis.co.za", "12399", "TEST001")
Response.Write(PaygateForm().ToString)
Me.PaygatePostScript(Page)
End Sub
Private Sub PaygatePostScript(ByVal Page As System.Web.UI.Page)
'This registers Javascript to the page which is used to post the Netcash Form details
Dim strScript As New StringBuilder()
strScript.Append("<script language='javascript'>")
strScript.Append("var ctlForm = document.getElementById('Paygate');")
strScript.Append("ctlForm.submit();")
strScript.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType, "PPSubmit", strScript.ToString)
End Sub
Private Function PaygateForm()
Dim client = New RestClient("https://secure.paygate.co.za/payweb3/process.trans")
client.Timeout = -1
Dim request = New RestRequest(Method.POST)
request.AddHeader("Content-Type", "application/x-www-form-urlencoded")
request.AddHeader("Cookie", "paygate_payweb3=u9tjr031eluc6jsflq952uatup")
request.AddParameter("PAY_REQUEST_ID", PaymentRequestId)
request.AddParameter("CHECKSUM", CheckSum)
Dim response As IRestResponse = client.Execute(request)
Dim ppForm As New StringBuilder
'<form action="https://secure.paygate.co.za/payweb3/process.trans" method="POST" >
ppForm.Append("<Form method=" + """" + "post" + """" + """" + " id=" + """" + "Paygate" + """" + " action=" + """" + "https://secure.paygate.co.za/payweb3/process.trans" + """" + ">")
ppForm.Append(response.Content.ToString)
Return ppForm.ToString
End Function
Public Function generateChecksum(ByVal postData As Dictionary(Of String, String)) As String
Dim checksum As String = ""
For Each item In postData
If item.Value <> "" Then
checksum += item.Value
End If
Next
checksum += Me.getEncryptionKey()
Dim hash = System.Security.Cryptography.MD5.Create().ComputeHash(System.Text.Encoding.ASCII.GetBytes(checksum))
Dim sb As StringBuilder = New StringBuilder()
For i As Integer = 0 To hash.Length - 1
sb.Append(hash(i).ToString("x2"))
Next
Return sb.ToString()
End Function
Public Function getEncryptionKey() As String
Return Me.encryptionKey
End Function
Private Sub Paygate(ByVal EMAIL As String, ByVal AMOUNT As String, ByVal REFERENCE As String)
Dim client = New RestClient("https://secure.paygate.co.za/payweb3/initiate.trans")
Dim postData As New Dictionary(Of String, String)
client.Timeout = -1
Dim request = New RestRequest(Method.POST)
request.AddHeader("Content-Type", "application/x-www-form-urlencoded")
request.AddHeader("Cookie", "paygate_payweb3=u9tjr031eluc6jsflq952uatup")
request.AddParameter("PAYGATE_ID", PAYGATE_ID)
postData.Add("PAYGATE_ID", PAYGATE_ID)
request.AddParameter("REFERENCE", REFERENCE)
postData.Add("REFERENCE", REFERENCE)
request.AddParameter("AMOUNT", AMOUNT)
postData.Add("AMOUNT", AMOUNT)
request.AddParameter("CURRENCY", "ZAR")
postData.Add("CURRENCY", "ZAR")
request.AddParameter("RETURN_URL", "https://my.return.url/page")
postData.Add("RETURN_URL", "https://my.return.url/page")
Dim adate As Date = DateTime.Now
Dim sDate As String = adate.Year.ToString("D4") & "-" & adate.Month.ToString("D2") & "-" & adate.Day.ToString("D2") & " " & adate.Hour.ToString("D2") & ":" & adate.Minute.ToString("D2") & ":" & adate.Second.ToString("D2")
request.AddParameter("TRANSACTION_DATE", sDate)
postData.Add("TRANSACTION_DATE", sDate)
request.AddParameter("LOCALE", "en-za")
postData.Add("LOCALE", "en-za")
request.AddParameter("COUNTRY", "ZAF")
postData.Add("COUNTRY", "ZAF")
request.AddParameter("EMAIL", EMAIL)
postData.Add("EMAIL", EMAIL)
'System.Security.Cryptography.HashAlgorithm
Dim checksum1 As String = generateChecksum(postData)
request.AddParameter("CHECKSUM", checksum1)
'request.AddParameter("CHECKSUM", "59229d9c6cb336ae4bd287c87e6f0220")
Dim response As IRestResponse = client.Execute(request)
CheckSum = response.Content.ToString
Dim array1 As String() = CheckSum.Split("&")
CheckSum = array1(3)
CheckSum = Replace(CheckSum, "CHECKSUM=", "")
PaymentRequestId = array1(1)
PaymentRequestId = Replace(PaymentRequestId, "PAY_REQUEST_ID=", "")
' GetCheckSumPayGate()
End Sub
End Class
我在尝试使用 .Net Framework 4.0 集成到他们的 PayWeb 模块时收到此错误。我创建了简单的 WebRequest POST 来 https://secure.paygate.co.za/payweb3/initiate.trans,并会收到"身份验证失败,因为远程方已关闭传输流"错误。
所有关于此错误的堆栈溢出帖子都指向 .Net 4.0 的 TLS1 问题,但是在托管服务器上激活 TLS1.1 和 TLS1.2 并不能解决问题。即使更改防火墙上的例外也无法解决错误。PayGate不知道如何解决此错误,即使在来回发送60封电子邮件之后也是如此。
最后,我在服务器上升级到.Net 4.5.2,从而解决了问题。