示例#1
0
        public async Task <IActionResult> PubPay(WeChatPayPubPayViewModel 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, _optionsAccessor.Value);

            if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success)
            {
                var req = new WeChatPayJsApiSdkRequest
                {
                    Package = "prepay_id=" + response.PrepayId
                };

                var parameter = await _client.ExecuteAsync(req, _optionsAccessor.Value);

                // 将参数(parameter)给 公众号前端
                // 让他在微信内H5调起支付(https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6)
                // ViewData["parameter"] = JsonSerializer.Serialize(parameter); ViewData["response"]
                // = response.Body;
                return(Ok(response.Body));
            }

            //ViewData["response"] = response.Body;
            return(Ok(response.Body));
        }
示例#2
0
        // 公众号支付
        public async Task <WeChatPayDictionary> PubPay(PayRequest request)
        {
            var order = orderService.GetByRef(request.Id);
            var req   = new WeChatPayUnifiedOrderRequest
            {
                OutTradeNo     = order.Order_SN,
                Body           = order.Name,
                TotalFee       = (int)(order.Pay_Money * 100),
                SpBillCreateIp = App.Context.GetClientIp(),
                NotifyUrl      = request.NotifyUrl,
                TradeType      = WepayTypes.JSAPI,
                OpenId         = request.OpenId
            };

            var res = await client.ExecuteAsync(req, options.Value);

            if (res.ReturnCode == "SUCCESS" && res.ResultCode == "SUCCESS")
            {
                var jsapiReq = new WeChatPayJsApiSdkRequest
                {
                    Package = "prepay_id=" + res.PrepayId
                };

                // 将参数(parameter)给 公众号前端 让他在微信内H5调起支付
                // https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6
                return(await client.ExecuteAsync(jsapiReq, options.Value));
            }

            throw new AceException($"公众号支付错误:{res.ErrCode}:{res.ErrCodeDes}");
        }
示例#3
0
        // 公众号支付
        public async Task <PayResult> PubPay(PayRequest request)
        {
            var order = OrderService.Get(request.Id);
            var req   = new WeChatPayUnifiedOrderRequest
            {
                OutTradeNo     = order.Order_SN,
                Body           = order.Name,
                TotalFee       = (int)(order.Order_Money * 100),
                SpBillCreateIp = App.Context.GetClientIp(),
                NotifyUrl      = request.NotifyUrl,
                TradeType      = WepayTypes.JSAPI,
                OpenId         = request.OpenId
            };

            logger.LogDebug($"Wepay PubPay begin with: {request.Id}");
            var res = await client.ExecuteAsync(req, options.Value);

            if (res.ReturnCode == "SUCCESS" && res.ResultCode == "SUCCESS")
            {
                var jsapiReq = new WeChatPayJsApiSdkRequest
                {
                    Package = "prepay_id=" + res.PrepayId
                };

                logger.LogDebug($"Wepay PubPay begin with: {request.Id} SUCCESS");

                // 将参数(parameter)给 公众号前端 让他在微信内H5调起支付
                // https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6
                return(new PayResult
                {
                    Success = true,
                    Params = await client.ExecuteAsync(jsapiReq, options.Value)
                });
            }

            logger.LogDebug($"Wepay PubPay end with: {request.Id} Fail: {res.ErrCode}:{res.ErrCodeDes}");
            return(new PayResult
            {
                Success = false,
                Error = $"{res.ErrCode}:{res.ErrCodeDes}"
            });
        }
示例#4
0
        public async Task <IActionResult> PubPay(WeChatPayPubPayV3ViewModel viewModel)
        {
            var model = new WeChatPayTransactionsJsApiBodyModel
            {
                AppId  = _optionsAccessor.Value.AppId,
                MchId  = _optionsAccessor.Value.MchId,
                Amount = new Amount {
                    Total = viewModel.Total, Currency = "CNY"
                },
                Description = viewModel.Description,
                NotifyUrl   = viewModel.NotifyUrl,
                OutTradeNo  = viewModel.OutTradeNo,
                Payer       = new PayerInfo {
                    OpenId = viewModel.OpenId
                }
            };

            var request = new WeChatPayTransactionsJsApiRequest();

            request.SetBodyModel(model);

            var response = await _client.ExecuteAsync(request, _optionsAccessor.Value);

            if (response.StatusCode == 200)
            {
                var req = new WeChatPayJsApiSdkRequest
                {
                    Package = "prepay_id=" + response.PrepayId
                };

                var parameter = await _client.ExecuteAsync(req, _optionsAccessor.Value);

                // 将参数(parameter)给 公众号前端
                // https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_4.shtml
                ViewData["parameter"] = JsonSerializer.Serialize(parameter);
                ViewData["response"]  = response.Body;
                return(View());
            }

            ViewData["response"] = response.Body;
            return(View());
        }