/// <summary> /// 阿里支付成功同步回调地址 /// </summary> /// <returns></returns> public ActionResult CallBack() { SortedDictionary <string, string> sPara = GetRequestGet(); if (sPara.Count > 0)//判断是否有带返回参数 { AlipayNotify aliNotify = new AlipayNotify(); bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]); if (verifyResult)//验证成功 { //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 string trade_no = Request.QueryString["trade_no"]; //支付宝交易号 string order_no = Request.QueryString["out_trade_no"]; //获取订单号 string total_fee = Request.QueryString["total_fee"]; //获取总金额 string subject = Request.QueryString["subject"]; //商品名称、订单名称 string body = Request.QueryString["body"]; //商品描述、订单备注、描述 string buyer_email = Request.QueryString["buyer_email"]; //买家支付宝账号 string trade_status = Request.QueryString["trade_status"]; //交易状态 if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 BaseResponse br = DBOrderBLL.OrderPaySuccess(order_no, decimal.Parse(total_fee), buyer_email); if (br.IsSuccess) { return(RedirectToAction("success", "order", new { ordercode = order_no })); } else { ViewBag.Msg = "对不起未能成功处理您的订单[" + order_no + "],原因是:" + br.Message; return(View("error")); } } else { ViewBag.Msg = "对不起您的订单[" + order_no + "]支付失败了,交易状态:" + trade_status; Logger.Info(ViewBag.Msg); return(View("error")); } } else//验证失败 { ViewBag.Msg = "对不起您的订单[" + Request.QueryString["trade_no"] + "]支付失败了,支付返回数据异常"; Logger.Info(ViewBag.Msg); return(View("error")); } } else { ViewBag.Msg = "对不起您的订单[" + Request.QueryString["trade_no"] + "]订单支付失败了,支付返回参数为空"; Logger.Info(ViewBag.Msg); return(View("error")); } }
/// <summary> /// 阿里异步对账地址 /// </summary> /// <returns></returns> public ActionResult Notify() { SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { AlipayNotify aliNotify = new AlipayNotify(); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult)//验证成功 { //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 string trade_no = Request.Form["trade_no"]; //支付宝交易号 string order_no = Request.Form["out_trade_no"]; //获取订单号 string total_fee = Request.Form["total_fee"]; //获取总金额 string subject = Request.Form["subject"]; //商品名称、订单名称 string body = Request.Form["body"]; //商品描述、订单备注、描述 string buyer_email = Request.Form["buyer_email"]; //买家支付宝账号 string trade_status = Request.Form["trade_status"]; //交易状态 if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 BaseResponse br = DBOrderBLL.OrderPaySuccess(order_no, decimal.Parse(total_fee), buyer_email); Logger.Info("Notify-1收到alipay的通知更新订单:" + order_no + "交易状态:" + trade_status); } else { Logger.Info("Notify-2收到alipay的通知更新订单:" + order_no + "交易状态:" + trade_status); } return(Content("success")); //请不要修改或删除 } else//验证失败 { return(Content("fail")); } } else { Logger.Info("Notify-3收到alipay的通知更新订单参数为空"); return(Content("无通知参数")); } }
public ActionResult Receive() { //人民币网关账号,该账号为11位人民币网关商户编号+01,该值与提交时相同。 string merchantAcctId = Request.QueryString["merchantAcctId"].ToString(); //网关版本,固定值:v2.0,该值与提交时相同。 string version = Request.QueryString["version"].ToString(); //语言种类,1代表中文显示,2代表英文显示。默认为1,该值与提交时相同。 string language = Request.QueryString["language"].ToString(); //签名类型,该值为4,代表PKI加密方式,该值与提交时相同。 string signType = Request.QueryString["signType"].ToString(); //支付方式,一般为00,代表所有的支付方式。如果是银行直连商户,该值为10,该值与提交时相同。 string payType = Request.QueryString["payType"].ToString(); //银行代码,如果payType为00,该值为空;如果payType为10,该值与提交时相同。 string bankId = Request.QueryString["bankId"].ToString(); //商户订单号,,该值与提交时相同。 string orderId = Request.QueryString["orderId"].ToString(); //订单提交时间,格式:yyyyMMddHHmmss,如:20071117020101,该值与提交时相同。 string orderTime = Request.QueryString["orderTime"].ToString(); //订单金额,金额以“分”为单位,商户测试以1分测试即可,切勿以大金额测试,该值与支付时相同。 string orderAmount = Request.QueryString["orderAmount"].ToString(); // 快钱交易号,商户每一笔交易都会在快钱生成一个交易号。 string dealId = Request.QueryString["dealId"].ToString(); //银行交易号 ,快钱交易在银行支付时对应的交易号,如果不是通过银行卡支付,则为空 string bankDealId = Request.QueryString["bankDealId"].ToString(); //快钱交易时间,快钱对交易进行处理的时间,格式:yyyyMMddHHmmss,如:20071117020101 string dealTime = Request.QueryString["dealTime"].ToString(); //商户实际支付金额 以分为单位。比方10元,提交时金额应为1000。该金额代表商户快钱账户最终收到的金额。 string payAmount = Request.QueryString["payAmount"].ToString(); //费用,快钱收取商户的手续费,单位为分。 string fee = Request.QueryString["fee"].ToString(); //扩展字段1,该值与提交时相同。 string ext1 = Request.QueryString["ext1"].ToString(); //扩展字段2,该值与提交时相同。 string ext2 = Request.QueryString["ext2"].ToString(); //处理结果, 10支付成功,11 支付失败,00订单申请成功,01 订单申请失败 string payResult = Request.QueryString["payResult"].ToString(); //错误代码 ,请参照《人民币网关接口文档》最后部分的详细解释。 string errCode = Request.QueryString["errCode"].ToString(); //签名字符串 string signMsg = Request.QueryString["signMsg"].ToString(); string signMsgVal = ""; signMsgVal = appendParam(signMsgVal, "merchantAcctId", merchantAcctId); signMsgVal = appendParam(signMsgVal, "version", version); signMsgVal = appendParam(signMsgVal, "language", language); signMsgVal = appendParam(signMsgVal, "signType", signType); signMsgVal = appendParam(signMsgVal, "payType", payType); signMsgVal = appendParam(signMsgVal, "bankId", bankId); signMsgVal = appendParam(signMsgVal, "orderId", orderId); signMsgVal = appendParam(signMsgVal, "orderTime", orderTime); signMsgVal = appendParam(signMsgVal, "orderAmount", orderAmount); signMsgVal = appendParam(signMsgVal, "dealId", dealId); signMsgVal = appendParam(signMsgVal, "bankDealId", bankDealId); signMsgVal = appendParam(signMsgVal, "dealTime", dealTime); signMsgVal = appendParam(signMsgVal, "payAmount", payAmount); signMsgVal = appendParam(signMsgVal, "fee", fee); signMsgVal = appendParam(signMsgVal, "ext1", ext1); signMsgVal = appendParam(signMsgVal, "ext2", ext2); signMsgVal = appendParam(signMsgVal, "payResult", payResult); signMsgVal = appendParam(signMsgVal, "errCode", errCode); ///UTF-8编码 GB2312编码 用户可以根据自己网站的编码格式来选择加密的编码方式 ///byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(signMsgVal); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(signMsgVal); byte[] SignatureByte = Convert.FromBase64String(signMsg); X509Certificate2 cert = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "Content\\KQBill\\99bill.cert.rsa.20140728.cer", ""); RSACryptoServiceProvider rsapri = (RSACryptoServiceProvider)cert.PublicKey.Key; rsapri.ImportCspBlob(rsapri.ExportCspBlob(false)); RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsapri); byte[] result; f.SetHashAlgorithm("SHA1"); SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider(); result = sha.ComputeHash(bytes); if (f.VerifySignature(result, SignatureByte)) { //支付成功 //在这里商户可以写上自己的业务逻辑 //逻辑处理 写入数据库 if (payResult == "10") { BaseResponse br = DBOrderBLL.OrderPaySuccess(orderId, decimal.Parse(orderAmount), payerName); if (br.IsSuccess) { return(Content("<result>1</result><redirecturl>http://inpinke.com/order/success?ordercode=" + orderId + "</redirecturl>")); } else { ViewBag.Msg = "对不起未能成功处理您的订单[" + orderId + "],原因是:" + br.Message; return(View("error")); } } else { ViewBag.Msg = string.Format("订单{0},支付失败,失败编号:{1},支付结果:{2}", orderId, errCode, payResult); log.Info(ViewBag.Msg); //以下是我们快钱设置的show页面,商户需要自己定义该页面。 return(View("error")); } } ViewBag.Msg = string.Format("订单{0},支付失败,失败编号:{1},支付结果:{2}", orderId, errCode, payResult); log.Info(ViewBag.Msg); //以下是我们快钱设置的show页面,商户需要自己定义该页面。 return(View("error")); }