H5手机网站接入付出宝的付出接口,引荐运用付出宝供应的SDK来疾速开辟
我运用的是SDK开辟
援用定名空间
using Aop.Api; using Aop.Api.Request; using Aop.Api.Response; using Aop.Api.Util;
首页需要定义一些常量
static string serverUrl = "https://openapi.alipaydev.com/gateway.do"; static string app_id = "**"; //开辟者的运用ID static string format = "JSON"; static string charset = "utf-8"; static string sign_type = "RSA2"; //署名花样 static string version = "1.0"; string UID = "2088102169707816";//卖家付出宝账户号 //商户私钥 static string merchant_private_key = "***"; //付出宝公钥 static string alipay_public_key = "***";
这里的app_id,merchant_private_key,alipay_public_key 我就没有列出来了,猎取的要领需要本身去付出宝平台完成一些操纵举行猎取
在用户点击网站付款时,我们需要叫醒付出宝,来举行付出
public string H5RequestPayWay(OrderPO order) { IAopClient client = new DefaultAopClient(serverUrl, app_id, merchant_private_key, format, version, sign_type, alipay_public_key, charset, false); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); string address= "http://m." + PathLogic1.RootDomain; request.SetReturnUrl(address+ "/WebPay/AlipayPayResult");//同步要求 request.SetNotifyUrl(address + "/WebPay/AsyncPay");//异步要求 var lstDetail = Context.Data.OrderDetail.Where(x => x.OrderNo == order.OrderNo).ToSelectList(x=>new { x.SkuName}); StringBuilder sb = new StringBuilder(); for (int i = 0; i < lstDetail.Count(); i++) { sb.Append(lstDetail[i].SkuName + ","); } request.BizContent = "{" + "\"body\":\""+sb.ToString().Substring(0,sb.Length-1)+"\"," + "\"subject\":\"袋鼠巴巴商品付出\"," + "\"out_trade_no\":\""+order.OrderNo+"\"," + "\"timeout_express\":\"90m\"," + "\"total_amount\":"+(order.TotalAmount.Value+order.TotalFreight.Value)+"," + "\"product_code\":\"QUICK_WAP_PAY\"" + " }"; AlipayTradeWapPayResponse response = client.pageExecute(request); return response.Body; }
详细发送给付出宝的参数,自行去检察
实行要领后,买家输入本身的付出宝账号密码举行付出,付出胜利的效果,付出宝会以post的体式格局异步要求你的SetNotifyUrl的地点
这个SetNotifyUrl的地点必需要外网能够接见,付出宝的要求才进来
买家付出胜利,商家修正定单状况和数据库的操纵,都在异步要求中实行
同步要求
public ActionResult AlipayPayResult() { ViewBag.result = "success"; return View("PayResult"); }
/// <summary> /// 考证关照数据的正确性 /// </summary> /// <param name="out_trade_no"></param> /// <param name="total_amount"></param> /// <param name="seller_id"></param> /// <returns></returns> private SortedDictionary<string, string> GetRequestPost() { int i = 0; SortedDictionary<string, string> sArray = new SortedDictionary<string, string>(); NameValueCollection coll; //Load Form variables into NameValueCollection variable. coll = Request.Form; // Get names of all forms into a string array. String[] requestItem = coll.AllKeys; for (i = 0; i < requestItem.Length; i++) { sArray.Add(requestItem[i], Request.Form[requestItem[i]]); } return sArray; }
/// <summary> /// 验签 /// </summary> /// <param name="inputPara"></param> /// <returns></returns> public Boolean Verify(SortedDictionary<string, string> inputPara) { Dictionary<string, string> sPara = new Dictionary<string, string>(); Boolean verifyResult = AlipaySignature.RSACheckV1(inputPara, alipay_public_key, charset,sign_type,false); return verifyResult; }
异步要求:
[HttpPost] public void AsyncPay() { SortedDictionary<string, string> sPara = GetRequestPost();//将post要求过来的参数传化为SortedDictionary if (sPara.Count > 0) { AlipayTradeWayPayServer pay = new AlipayTradeWayPayServer(); Boolean VerifyResult = pay.Verify(sPara);//验签if (VerifyResult) { try { //商户定单号 string out_trade_no = Request.Form["out_trade_no"]; //付出宝生意营业号 string trade_no = Request.Form["trade_no"]; //付出金额 decimal total_amount = Request.Form["total_amount"].ConvertType(Decimal.Zero); //实收金额 //decimal receipt_amount = Request.Form["receipt_amount"].ConvertType(Decimal.Zero); //生意营业状况 string trade_status = Request.Form["trade_status"]; //卖家付出宝账号 string seller_id = Request.Form["seller_id"]; //商品形貌 string body = Request.Form["body"]; //生意营业建立时刻 DateTime gmt_create = DateTime.Parse(Request.Form["gmt_create"]); //生意营业付款时刻 DateTime gmt_payment = DateTime.Parse(Request.Form["gmt_payment"]); string appid = Request.Form["app_id"]; WriteError("考证参数最先"); Boolean DataValidity = pay.CheckInform(out_trade_no, total_amount, seller_id, appid);//商家推断参数时刻是不是婚配if (DataValidity) { if (Request.Form["trade_status"] == "TRADE_FINISHED") { AlipayWayPayPO model = CreateAlipayWayPay(out_trade_no, trade_no, trade_status, gmt_create, gmt_payment); pay.PaySuccess(out_trade_no, model, Server.MapPath("~/" + DateTime.Today.ToString("yyMMdd") + ".txt"));//修正定单 //注重: //退款日期凌驾可退款限期后(如三个月可退款),付出宝体系发送该生意营业状况关照 } else if (Request.Form["trade_status"] == "TRADE_SUCCESS") { AlipayWayPayPO model = CreateAlipayWayPay(out_trade_no, trade_no, trade_status, gmt_create, gmt_payment); pay.PaySuccess(out_trade_no, model, Server.MapPath("~/" + DateTime.Today.ToString("yyMMdd") + ".txt"));//修正定单 //注重: //付款完成后,付出宝体系发送该生意营业状况关照 } else { } //——请根据您的营业逻辑来编写程序(以上代码仅作参考)—— Response.Write("success"); //请不要修正或删除 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } } catch (Exception ex) { } } else//考证失利 { Response.Write("fail"); } } else { Response.Write("无关照参数"); } }
以上就是付出宝的付出接口在.net中的运用的细致内容,更多请关注ki4网别的相干文章!