13,347
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// liuyt 2014.01.05 add
/// paypal支付 同步回调函数
/// 返回值说明:Success:True/False,Success为True时 为支付成功!
/// PayPalNum:PayPal返回的支付ID,OrderNum:我们自己的订单ID,BeforeValidation:验证前返回的数据,AfterTheValidation:验证后返回的数据
/// 建议把返回值全部序列化后保存到数据库中。以方便以后核对数据
/// </summary>
/// <returns></returns>
#region paypal 同步支付回调函数+static Dictionary<string, string> PaypalCallBack()
public static Dictionary<string, string> PaypalCallBack()
{
Dictionary<string, string> rsDic = new Dictionary<string, string>();
string strFormValues = System.Web.HttpContext.Current.Request.Params.ToString();
string strNewValue;
string strResponse;
string serverURL = PayPalParameter.SERVERURL;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serverURL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
strNewValue = "cmd=_notify-synch&tx=" + System.Web.HttpContext.Current.Request.QueryString["tx"] + "&at=" + PayPalParameter.BusinessToken;
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
Dictionary<string, string> sPara = AlipayCommon.GetRequestGet();
rsDic.Add("BeforeValidation", JSON.Serialize(sPara));
rsDic.Add("AfterTheValidation", strResponse);
rsDic.Add("OrderNum", System.Web.HttpContext.Current.Request.QueryString["item_number"]);
rsDic.Add("PayPalNum", System.Web.HttpContext.Current.Request.QueryString["tx"]);
if (strResponse.StartsWith("SUCCESS"))
{
rsDic.Add("Success", "True");
}
else
{
rsDic.Add("Success", "False");
}
return rsDic;
}
#endregion