PayPal沙盒最近仅限于TLS 1.2连接。这使得我们的网站无法与PayPal沙盒进行通信,尽管它仍然能够与生产PayPal进行通信。未来,生产PayPal也将有同样的限制。我们正在使用经典ASP和Microsoft WinHTTP.WinHTTPRequest.5.1组件与PayPal进行通信。以下是代码,objHttp.StatusText返回“Bad Request”。我们使用的是Windows Server 2008 R2。我试图使用MSXML2.ServerXMLHTTP.6.0替代,但它只在我的Windows 8.1开发机器上工作,而不在我们的Windows Server 2008 R2上工作。虽然MSXML2.ServerXMLHTTP.6.0是WinHTTP.WinHTTPRequest.5.1的超集,但它比WinHTTP.WinHTTPRequest.5.1不可靠。我们的代码每天使用MSXML2.ServerXMLHTTP.6.0失败几次,因此我更喜欢使用WinHTTP.WinHTTPRequest.5.1。我对这行代码也不太自信:objHttp.Option(9) = &H0AA0。我们正在使用的解决方法是调用WebAPI向PayPal发送消息;但是,这会导致额外的轻微延迟。
dim objHttp
Set objHttp = Server.CreateObject("WinHTTP.WinHTTPRequest.5.1")
dim WinHttpRequestOption_EnableHttp1_1 : WinHttpRequestOption_EnableHttp1_1 = 17
objHttp.Option(WinHttpRequestOption_EnableHttp1_1) = False
dim WinHttpRequestOption_SslErrorIgnoreFlags : WinHttpRequestOption_SslErrorIgnoreFlags=4
objHttp.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300
objHttp.setTimeouts 0, 120000, 120000, 120000
objHttp.Option(9) = &H0AA0 '2720
objHttp.open "post", "" & "https://api-3t.sandbox.paypal.com/2.0/" & "", False
strRequest = SetExpressCheckoutSOAP(returnURL, cancelURL)
objHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objHttp.setRequestHeader "Content-Length", Len(strRequest)
objHttp.setRequestHeader "Host", "api-3t.sandbox.paypal.com"
Call objHttp.send(strRequest)
if objHttp.Status = 200 then
resp = objHttp.responseText
else
response.write objHttp.StatusText
end if
WebAPI调用代码:
dim webapiresp, webapidata
webapidata = "{""url"":""" & gv_APIEndpoint & """, ""message"":""" & nvpStrComplete & """,""soap"":0}"
webapiresp=InvokeWebAPI(strApiDomain, "POST", "comm/send", "", webapidata)
set reply=JSON.parse(webapiresp)
resp = reply.xml
Function InvokeWebAPI(strApiDomain, method, funcname, param, data)
dim HttpReq, apiURI, resp
set HttpReq=Server.CreateObject("MSXML2.ServerXMLHTTP")
'apiURI=strApiDomain & funcname & param
apiURI=strApiDomain & "api/" & funcname & param
HttpReq.open method, apiURI, false
HttpReq.setRequestHeader "Content-Type", "application/json; charset=UTF-8"
HttpReq.setRequestHeader "SOAPAction", apiURI
HttpReq.setRequestHeader "Authorization", "Basic " & Base64Encode("xxx:xxx")
if data <> "" then
HttpReq.send data
else
HttpReq.send
end if
resp = HttpReq.responseText
set HttpReq=Nothing
InvokeWebAPI = resp
End Function