Payplug API身份验证失败

时间:2018-10-25 08:08:38

标签: c# asp.net asp.net-web-api

我正在尝试使用payplug api创建付款,我将文档中的代码复制并粘贴到我的网站,但始终会遇到以下异常:

身份验证失败,因为远程方已关闭传输流。

这是我使用的代码

Configuration.SecretKey = "sk_test_11111111111111111111";

    var paymentData = new Dictionary<string, dynamic>
    {
        { "amount", 3300 },
        { "currency", "EUR" },
        { "customer", new Dictionary<string, object>
            {
                { "email", "john.watson@example.net" },
                { "first_name", "John" },
                { "last_name", "Watson" }
            }
        },
        { "hosted_payment", new Dictionary<string, object>
            {
                { "return_url", "https://example.net/success?id=42710" },
                { "cancel_url", "https://example.net/cancel?id=42710" }
            }
        },
        { "notification_url", "https://example.net/notifications?id=42710" },
        { "metadata", new Dictionary<string, object>
            {
                { "customer_id", "42710" }
            }
        },
        { "save_card", false },
        { "force_3ds", true }
    };
            var payment = Payment.Create(paymentData);

这是堆栈跟踪

[IOException: Authentication failed because the remote party has closed 

the transport stream.]
   System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +6815104
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +132
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +281
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +49
   System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +162
   System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +542
   System.Net.TlsStream.CallProcessAuthentication(Object state) +42
   System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +228
   System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +21
   System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +64
   System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +778
   System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +52
   System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +21
   System.Net.ConnectStream.WriteHeaders(Boolean async) +388

[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
   System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) +916
   System.Net.HttpWebRequest.GetRequestStream() +13
   Payplug.Core.Service.Request(String method, Uri uri, String data, String authorizationHeader) +672
   Payplug.Core.Service.Post(Uri uri, String data) +27
   Payplug.Payment.CreateRaw(String payment) +56
   Payplug.Payment.Create(Dictionary`2 payment) +34
   p_payplug.Page_Load(Object sender, EventArgs e) in d:\inetpub\tredwebcom\p\payplug.aspx.cs:40
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +95
   System.Web.UI.Control.LoadRecursive() +59
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678

2 个答案:

答案 0 :(得分:0)

您的网站的网址是什么?

我相信您会收到此消息,因为您的服务器与TLS 1.2协议不兼容。

使用PHP,这意味着您应该更新OpenSSL和libcurl的版本,但使用.NET,我不知道等效的版本。

因此,您应该研究TLS和CACERT并升级所需的组件。我想您必须为此升级到.net版本4.6。

答案 1 :(得分:0)

我已经解决了,将其添加到请求之前

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;