【发布时间】:2016-04-20 12:06:38
【问题描述】:
我遇到了一种非常奇怪的问题,即在成功支付交易后,我无法获得附加返回 URL 的 TransactionId。由于 Paypal 自动将我重定向到我在 PDT 设置页面中提到的 ReturnUrl,并且 Paypal 将 trasactionId 附加到此名为 tx 的返回Url 并使用该 trasactionId 我向此 Url 发出 Post 请求
https://www.sandbox.paypal.com/cgi-bin/webscr
但问题是我无法获得该 transactionId?任何人都可以帮助我解决这个问题,这可能是什么问题。这是我用来发出 HTTP 发布请求的代码。
string authTokenTest = "sMfRi9rJN3AjqsejnMxFfkeIwhwrCmVZz3nplUy9V6a9Yq0_2YdugSvZYNa";
//used this but could not retrieved "tx"
//string txToken = Request.QueryString.Get("tx");
//Then used this but no use
var queryValues = HttpUtility.ParseQueryString(Request.Url.Query);
var txToken = queryValues["tx"];
string query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authTokenTest);
//// Create the request back
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string url = strSandbox;
/// to use HTTP 1.1 and TLS 1.2
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;
// Write the request back IPN strings
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(query);
stOut.Close();
// Do the request to PayPal and get the response
HttpWebResponse payResp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(payResp.GetResponseStream());
string strResponse = sr.ReadToEnd();
sr.Close();
如果我通过浏览器直接请求此 URL 并附加 TransactionId 和 IdentityToken ,那么我会得到成功响应,但是这样我就不会得到 transactionId 并且我的响应总是失败。请帮助我解决这个问题。我的代码中可能有什么问题或解决此问题的任何其他问题。感谢您的宝贵时间。
【问题讨论】: