public async Task <PaymentOrderBaseResponse> GeneratePaymentOrder(PaymentOrderRequest request) { var apiHost = await _appSettingService.Get(ShopKeys.ApiHost); var wxRequest = new WeChatPayUnifiedOrderRequest { Body = request.Subject, OutTradeNo = request.OrderNo, TotalFee = Convert.ToInt32(request.TotalAmount * 100), OpenId = request.OpenId, TradeType = "JSAPI", SpbillCreateIp = "127.0.0.1", NotifyUrl = $"{apiHost.Trim('/')}/api/mp/pay/notify/{request.OrderNo}", }; var response = await _client.ExecuteAsync(wxRequest); if (response?.ReturnCode == "SUCCESS" && response?.ResultCode == "SUCCESS") { var req = new WeChatPayLiteAppCallPaymentRequest { Package = "prepay_id=" + response.PrepayId }; // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5 // 将参数(parameter)给 小程序前端 让他调起支付API var parameter = await _client.ExecuteAsync(req); var json = JsonConvert.SerializeObject(parameter); return(JsonConvert.DeserializeObject <PaymentOrderResponse>(json)); } throw new Exception(response?.ReturnMsg); }
public async Task <IActionResult> LiteAppPay(WeChatPayLiteAppPayViewModel viewModel) { var request = new WeChatPayUnifiedOrderRequest() { Body = viewModel.Body, OutTradeNo = viewModel.OutTradeNo, TotalFee = viewModel.TotalFee, SpbillCreateIp = viewModel.SpbillCreateIp, NotifyUrl = viewModel.NotifyUrl, TradeType = viewModel.TradeType, OpenId = viewModel.OpenId, }; var response = await _client.ExecuteAsync(request); if (response.ReturnCode == "SUCCESS" && response.ResultCode == "SUCCESS") { var req = new WeChatPayLiteAppCallPaymentRequest() { Package = "prepay_id=" + response.PrepayId, }; var parameter = await _client.ExecuteAsync(req); // 将参数(parameter)给 小程序前端 让他调起支付API(https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5) ViewData["parameter"] = JsonConvert.SerializeObject(parameter); ViewData["response"] = response.Body; return(View()); } ViewData["response"] = response.Body; return(View()); }
public async Task <IActionResult> LiteAppPay(string body, string out_trade_no, int total_fee, string spbill_create_ip, string notify_url, string trade_type, string openid) { var request = new WeChatPayUnifiedOrderRequest { Body = body, OutTradeNo = out_trade_no, TotalFee = total_fee, SpbillCreateIp = spbill_create_ip, NotifyUrl = notify_url, TradeType = trade_type, OpenId = openid }; var response = await _client.ExecuteAsync(request); ResponseModel responseModel = new ResponseModel() { code = HTTPResponseCode.PartialContent, data = response.Body }; Dictionary <string, string> result = new Dictionary <string, string>(); result.Add("return_code", response.ReturnCode); result.Add("return_msg", response.ReturnMsg); if (response.ReturnCode == "SUCCESS" && response.ResultCode == "SUCCESS") { var req = new WeChatPayLiteAppCallPaymentRequest { Package = "prepay_id=" + response.PrepayId }; var parameter = await _client.ExecuteAsync(req); // 将参数(parameter)给 小程序前端 让他调起支付API(https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5) result.Add("parameter", JsonConvert.SerializeObject(parameter)); responseModel.code = HTTPResponseCode.Successful; } else { responseModel.code = HTTPResponseCode.BadRequest; result.Add("err_code", response.ErrCode); result.Add("err_code_des", response.ErrCodeDes); } responseModel.message = JsonConvert.SerializeObject(result); return(Json(responseModel)); }