第一步:后台构造统一下单参数(SDK:https://download.csdn.net/download/qq_36894527/12875709)
////// 支付宝统一下单接口 /// /// /// 应用私钥 /// 支付宝公钥 /// user_id /// /// ///public static string TradePay(string appid, string merchant_private_key ,string alipay_public_key,string notifyurl,string user_id, string total_fee, string bill) { decimal fee = decimal.Round(decimal.Parse(total_fee), 2); string result = ""; try { IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", appid, merchant_private_key, "json", "1.0", "RSA2", alipay_public_key, "GBK", false); AlipayTradeCreateRequest request = new AlipayTradeCreateRequest(); request.SetNotifyUrl(notifyUrl); request.BizContent = "{" + ""out_trade_no":"" + bill + ""," + //""seller_id":""," + ""total_amount":"" + fee + ""," + //""discountable_amount":0," + ""subject":"会员充值"," + //""body":"支付宝会员充值"," + ""buyer_id":"" + user_id+ """ + //" "goods_detail":[{" + //" "goods_id":"apple-01"," + //""goods_name":"ipad"," + //""quantity":1," + //""price":2000," + //""goods_category":"34543238"," + //""categories_tree":"124868003|126232002|126252004"," + //""body":"特价手机"," + //""show_url":"http://www.alipay.com/xxx.jpg"" + //" }]," + //""product_code":"FACE_TO_FACE_PAYMENT"," + //""operator_id":"Yx_001"," + //""store_id":"NJ_001"," + //""terminal_id":"NJ_T_001"," + //""extend_params":{" + //""sys_service_provider_id":"2088511833207846"," + //""card_type":"S0JP0000"" + //" }," + //""timeout_express":"90m"," + //""settle_info":{" + //" "settle_detail_infos":[{" + //" "trans_in_type":"cardAliasNo"," + //""trans_in":"A0001"," + //""summary_dimension":"A0001"," + //""settle_entity_id":"2088xxxxx;ST_0001"," + //""settle_entity_type":"SecondMerchant、Store"," + //""amount":0.1" + //" }]," + //""settle_period_time":"7d"" + //" }," + //""logistics_detail":{" + //""logistics_type":"EXPRESS"" + //" }," + //""business_params":{" + //""campus_card":"0000306634"," + //""card_type":"T0HK0000"," + //""actual_order_time":"2019-05-14 09:18:55"" + //" }," + //""receiver_address_info":{" + //""name":"张三"," + //""address":"上海市浦东新区陆家嘴银城中路501号"," + //""mobile":"13120180615"," + //""zip":"200120"," + //""division_code":"310115"" + //" }" + " }"; AlipayTradeCreateResponse response = client.Execute(request); Console.WriteLine(response.Body); JObject jobj = (JObject)JsonConvert.DeserializeObject(response.Body); if (jobj["alipay_trade_create_response"]["code"].ToString() == "10000") { string trade_no = jobj["alipay_trade_create_response"]["trade_no"].ToString(); result = ReturnInfo.CodeReturn("S",trade_no); } else { string msg = jobj["alipay_trade_create_response"]["msg"].ToString(); result = ReturnInfo.CodeReturn("E", msg); } } catch (Exception ex) { result = ReturnInfo.CodeReturn("E", ex.Message); } return result; }
第二步:小程序发起支付
my.tradePay({
tradeNO: res,//后台返回的支付宝交易单号
success: function (res) {}
});



