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);

            if (response.ReturnCode == "SUCCESS" && response.ResultCode == "SUCCESS")
            {
                var req = new WeChatPayH5CallPaymentRequest()
                {
                    Package = "prepay_id=" + response.PrepayId,
                };
                var parameter = await _client.ExecuteAsync(req);

                // 将参数(parameter)给 公众号前端 让他在微信内H5调起支付(https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6)
                ViewData["parameter"] = JsonConvert.SerializeObject(parameter);
                ViewData["response"]  = response.Body;
                return(View());
            }
            ViewData["response"] = response.Body;
            return(View());
        }
Пример #2
0
        public async Task <IActionResult> PubPay(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 WeChatPayH5CallPaymentRequest
                {
                    Package = "prepay_id=" + response.PrepayId
                };
                var parameter = await _client.ExecuteAsync(req);

                // 将参数(parameter)给 公众号前端 让他在微信内H5调起支付(https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6)
                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));
        }
Пример #3
0
        public async Task <IActionResult> PubPay(WeChatPayPubPayViewModel viewModel)
        {
            var request = new WeChatPayUnifiedOrderRequest
            {
                Body           = "测试商品",                                  //商品名称
                OutTradeNo     = DateTime.Now.ToString("yyyyMMhhddmmss"), //单号
                TotalFee       = 120,                                     //金额*100
                SpbillCreateIp = "111.231.71.111",                        //获取终端Ip,
                NotifyUrl      = "http://www.shhjy.cn/access/unifiedorder",
                // viewModel.NotifyUrl


                TradeType = "JSAPI",                       //viewModel.TradeType,
                OpenId    = "or1ZywUA0RJl6glVkPZC1a7h-Us8" //viewModel.OpenId//

                                                           //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 WeChatPayH5CallPaymentRequest
                {
                    Package = "prepay_id=" + response.PrepayId
                };
                var parameter = await _client.ExecuteAsync(req);

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