public ActionResult NativePayment(int orderId, string codeUrl) { var model = new PrepayInfoModel() { OrderId = orderId, WeixinNativePaymentUrl = codeUrl, }; return(View("Plugin.Payments.Weixin.NativePayment", model)); }
public ActionResult AuthNotify(int orderId, string ip, string code, string state) { _logger.Information( $"收到微信验证通知:orderId=[{orderId}], ip=[{ip}], code=[{code}], state=[{state}]"); var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Weixin") as WeixinPaymentProcessor; if (processor == null || !processor.PluginDescriptor.Installed) { throw new NopException("Weixin module can not be loaded"); } if (!string.IsNullOrEmpty(code)) { var authResult = this.RequestWeixinOauth2(code); var values = new Dictionary <string, string>(); var notifyUrl = _webHelper.GetStoreLocation(false) + $"Plugins/PaymentWeixin/PrepayNotify"; var order = _orderService.GetOrderById(orderId); values["notify_url"] = notifyUrl; values["spbill_create_ip"] = ip; values["trade_type"] = "JSAPI"; values["openid"] = authResult["openid"]; var returnWeixinData = this._weixinPaymentService.UnifiedOrder(order, values); var resultCode = returnWeixinData.GetValue("result_code"); var err_code = returnWeixinData.GetValue("err_code"); if (resultCode != null && resultCode == "SUCCESS") { PrepayInfoModel model = PreparePrepayInfo(returnWeixinData.GetValue("prepay_id"), orderId); _logger.Information($"进入微信支付界面..."); return(View("~/Plugins/Payments.Weixin/Views/PaymentWeixin/JsapiPrepay.cshtml", model)); } else if (err_code == "ORDERPAID") { _weixinPaymentService.ProcessOrderPaid(order); return(Redirect($"~/OrderDetails/{orderId}")); } else { return(Redirect($"~/OrderDetails/{orderId}")); } } else { _logger.Error("微信支付失败:微信没有返回合适的 code"); throw new NopException("支付失败"); } }
private PrepayInfoModel PreparePrepayInfo(string prepayId, int orderId) { var payData = new WxPayData(_WeixinPaymentSetting.MchKey); payData.SetValue("appId", _WeixinPaymentSetting.AppId); payData.SetValue("timeStamp", WxPayData.GenerateTimeStamp()); payData.SetValue("nonceStr", WxPayData.GenerateNonceStr()); payData.SetValue("package", $"prepay_id={prepayId}"); payData.SetValue("signType", "MD5"); payData.SetValue("paySign", payData.MakeSign()); var model = new PrepayInfoModel() { AppId = payData.GetValue("appId"), TimeStamp = payData.GetValue("timeStamp"), NonceStr = payData.GetValue("nonceStr"), Package = payData.GetValue("package"), SignType = payData.GetValue("signType"), PaySign = payData.GetValue("paySign"), PrepayId = prepayId, OrderId = orderId, }; return(model); }