【微信支付踩坑记02】v3版支付简单示例
v3版生成订单代码
有好多想说了,后续补充
/// <summary> /// Js下单API /// </summary> /// <returns></returns> [HttpPost("pay/v3")] public dynamic GetJS([FromBody]ReceiveSelect obj) { string transactionsResponse = ""; try { string dataDir = "URL" + "/apiclient_cert.p12"; X509Certificate2 Certificate = new X509Certificate2(dataDir , mchid, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); string serialNo = Certificate.SerialNumber; TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0); string TheNum = obj.partner_trade_no; V3JsPayObj v3Obj = new V3JsPayObj(); v3Obj.mchid = mchid; v3Obj.out_trade_no = TheNum; v3Obj.appid = mch_appid; v3Obj.description = obj.desc; v3Obj.notify_url = WechatUrl + @"/userPay/PayReMessage";// V3JsDetail theAmount = new V3JsDetail(); theAmount.currency = "CNY"; theAmount.total = Convert.ToInt32(Convert.ToDecimal(obj.amount) * 100); v3Obj.amount = theAmount; Payer ThePayer = new Payer(); ThePayer.openid = obj.openId; v3Obj.payer = ThePayer; v3Obj.time_expire = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"+"+08:00"); v3Obj.attach = ""; string theJson = JsonConvert.SerializeObject(v3Obj); transactionsResponse = postJson("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi", theJson, privateKey, mchid, serialNo); ThePay myObj = JsonConvert.DeserializeObject<ThePay>(transactionsResponse); string prepay_id = myObj.prepay_id; RaySelect rPay = new RaySelect(); rPay.prepay_id = prepay_id; rPay.appid = mch_appid; rPay.mchid = mchid; rPay.description = obj.desc; rPay.time_expire = v3Obj.time_expire; rPay.attach = ""; rPay.notify_url = v3Obj.notify_url; rPay.amount_total = theAmount.total.ToString(); rPay.amount_currency = "CNY"; rPay.payer_openid = obj.openId; return new MyMessage<dynamic> { data = rPay, resultCode = 200, message = "操作成功" }; } catch (Exception e) { return new MyMessage<dynamic> { resultCode = 999, message = "操作失败" }; } }