/// <summary> /// 支付回调 /// </summary> /// <returns></returns> public ActionResult GetPayResult() { string resultFromWx = getPostStr(); if (string.IsNullOrEmpty(resultFromWx)) { return(View()); } //string path = Path.Combine(Server.MapPath("~/data"), "data" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"); //FileInfo f = new FileInfo(path); //if (!Directory.Exists(f.DirectoryName)) // Directory.CreateDirectory(f.DirectoryName); //using (StreamWriter writer = new StreamWriter(path)) //{ // writer.Write(resultFromWx); //} var res = XDocument.Parse(resultFromWx); //通信成功 try { if (res.Element("xml").Element("return_code").Value == "SUCCESS") { if (res.Element("xml").Element("result_code").Value == "SUCCESS") { //交易成功 string transaction_id = res.Element("xml").Element("transaction_id").Value; //微信订单号 string trade_no = res.Element("xml").Element("out_trade_no").Value; //商户订单号 //查询订单是否存在 OrderViewModel model = BOrder.SearchByTradeNo(trade_no); if (model != null) { //存在 BOrder.Update("update Orders set LocalStatus='已付款' where Id=" + model.Id); } return(Content(CallWxSuccess())); } else { return(Content("支付出现问题,请返回重试")); } } } catch (Exception e) { } return(Content("failed")); }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { //Notify aliNotify = new Notify(); Notify aliNotify = new Notify(Config.charset, Config.sign_type, Config.pid, Config.mapiUrl, Config.alipay_public_key); //对异步通知进行验签 bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); //对验签结果 //bool isSign = Aop.Api.Util.AlipaySignature.RSACheckV2(sPara, Config.alipay_public_key ,Config.charset,Config.sign_type,false ); if (verifyResult && CheckParams()) //验签成功 && 关键业务参数校验成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //商户订单号 string out_trade_no = Request.Form["out_trade_no"]; //支付宝交易号 string trade_no = Request.Form["trade_no"]; //交易状态 //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,才是买家付款成功。 string trade_status = Request.Form["trade_status"]; if (trade_status.ToUpper() == "TRADE_SUCCESS" || trade_status.ToUpper() == "TRADE_FINISHED") { //查询订单是否存在 OrderViewModel model = BOrder.SearchByTradeNo(out_trade_no); if (model != null) { //存在 BOrder.Update("update Orders set LocalStatus='已付款' where Id=" + model.Id); } } //判断是否在商户网站中已经做过了这次通知返回的处理 //如果没有做过处理,那么执行商户的业务程序 //如果有做过处理,那么不执行商户的业务程序 Response.Write("success"); //请不要修改或删除 //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }