更新时间:2023-02-07 14:49:26
我对PayPal集成一无所知,但有可能两次指定business =
令人困惑的事情?
此外,您在redirectUrl
中包含的值是否适当地进行了Url编码? (参见 HttpUtility.UrlEncode Method(String)(System.Web) [ ^ ]和/或 HttpUtility.UrlPathEncode方法(字符串)(System.Web) [ ^ ]。)
您所拥有的代码有点草率;-)
以下是我如何构建它(我没有解决编码潜在问题。)
选项1:
I don't know anything about PayPal integration, but is it possible that having thebusiness=
specified twice is confusing things?
Also, are the values you are including in theredirectUrl
are appropriately Url encoded? (See HttpUtility.UrlEncode Method (String) (System.Web)[^] and/or HttpUtility.UrlPathEncode Method (String) (System.Web)[^].)
The code you have is a bit sloppy ;-)
Here's how I'd structure it (I'm not addressing the encoding potential issue.)
Option 1:
const string redirectUrlFormat =
"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business={0}" +
"&first_name=name" +
"&item_name={1}" +
"&amount={2}" +
// "&business=Paypalmail" // This was the duplication!!!
"&quantity=1" +
"&return={3}"
"&cancel_return={4}";
string redirectUrl = string.Format(redirectUrlFormat,
ConfigurationManager.AppSettings["paypalemail"],
Name, Price,
ConfigurationManager.AppSettings["SuccessURL"],
ConfigurationManager.AppSettings["FailedURL"]);
Response.Redirect(redirectUrl);
选项2:
Option 2:
StringBuilder redirectUrl = new StringBuilder();
redirectUrl.Add("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=");
redirectUrl.Add(ConfigurationManager.AppSettings["paypalemail"]);
redirectUrl.Add("&first_name=name&item_name=");
redirectUrl.Add(Name);
redirectUrl.Add("&amount=");
redirectUrl.Add(Price);
redirectUrl.Add("&quantity=1&return=");
redirectUrl.Add(ConfigurationManager.AppSettings["SuccessURL"]);
redirectUrl.Add("&cancel_return=");
redirectUrl.Add(ConfigurationManager.AppSettings["FailedURL"]);
Response.Redirect(redirectUrl.ToString());