public async Task <IActionResult> PayReturn([FromQuery] PayReturnModel model)
        {
            var verfyResult = await _paymentService.VerifyRequest(model);

            ViewBag.OK = model.Status;
            return(View(verfyResult));
        }
示例#2
0
        private PayReturnModel CreatePayReturnModel(TradeType tradeType, string nonceStr, string xmlResult)
        {
            string            timeStamp  = WechatCommonUtlis.GetTimestamp();
            PackageParamModel packageDic = new PackageParamModel();//坑2 参数区分大小写  APP是小写
            string            prepay_id  = GetPrepayId(xmlResult);
            string            package;

            if (tradeType == TradeType.JSAPI)
            {
                packageDic.AddValue("appId", this.AppId);// 注意这里的大小写 应用AppID 坑4
                packageDic.AddValue("timeStamp", timeStamp);
                packageDic.AddValue("nonceStr", nonceStr);
                package = string.Format("prepay_id={0}", prepay_id);
                packageDic.AddValue("package", package);//坑3
                packageDic.AddValue("signType", this._signType);
            }
            else if (tradeType == TradeType.APP)
            {
                packageDic.AddValue("appid", this.AppId);
                packageDic.AddValue("partnerid", _mchId);
                packageDic.AddValue("prepayid", prepay_id);
                package = "Sign=WXPay";
                packageDic.AddValue("package", package);//APP支付固定设置参数
                packageDic.AddValue("timestamp", timeStamp);
                packageDic.AddValue("noncestr", nonceStr);
            }
            else
            {
                throw new WxPayException("暂未实现的支付类型");
            }

            var            paySign = WechatCommonUtlis.GetMD5Sign(packageDic, this._appKey);//坑1 APPKey可能也有错
            PayReturnModel model   = new PayReturnModel
            {
                timeStamp = timeStamp,
                nonceStr  = nonceStr,
                package   = package,
                paySign   = paySign,
                signType  = this._signType,
                appId     = AppId,
                prepayId  = prepay_id,//JSAPI支付忽略此字段
                partnerId = _mchId
            };

            return(model);//最终返回前端的参数
        }
示例#3
0
        private void SendToPay(string orderid, string getuserid, string GoodsType, string bank_Type, string bank_payMoney)
        {
            //string orderid = Request.QueryString["orderid"].ToString();
            //string getuserid = Request.QueryString["userid"].ToString();
            //string GoodsType = Request.QueryString["GoodsType"].ToString();
            string hrefBackurl = hrefBack;  // 下行异步通知地址
            //银行提交获取信息
            // string bank_Type = Request.QueryString["rtype"].ToString();//银行类型
            // string bank_payMoney = Request.QueryString["PayMoney"].ToString();//充值金额
            string goodsname = "会员充值";

            goodsname = HttpUtility.UrlEncode(goodsname, System.Text.Encoding.GetEncoding("utf-8"));
            var    forgemd5 = shop_id + bank_payMoney + appkey;
            var    md5str   = md5.MD5(forgemd5);
            String param    = String.Format("shop_id={0}&amount={1}&pay_source={2}&body={3}&notify_url={4}", shop_id, bank_payMoney, bank_Type, goodsname, hrefBackurl);
            String PostUrl  = String.Format("{0}?{1}&sign={2}", gateway, param, md5str);



            var uri  = PostUrl;
            var json = "";

            byte[]         b   = Encoding.ASCII.GetBytes(json);
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Method        = "POST";
            req.ContentType   = "text/html";
            req.ContentLength = b.Length;
            req.Headers.Set("Pragma", "no-cache");
            req.Timeout = 60000;
            Stream reqstream = req.GetRequestStream();

            reqstream.Write(b, 0, b.Length);
            WebResponse  res    = req.GetResponse();
            Stream       stream = res.GetResponseStream();
            StreamReader sr     = new StreamReader(stream, Encoding.UTF8);
            string       result = sr.ReadToEnd();

            reqstream.Close();
            reqstream.Dispose();
            sr.Close();
            sr.Dispose();
            stream.Close();
            stream.Close();

            JavaScriptSerializer jss = new JavaScriptSerializer();
            PayReturnModel       abc = jss.Deserialize <PayReturnModel>(result) as PayReturnModel;
            var order_no             = abc.order_no;
            var issucc  = abc.success;
            var pay_url = abc.pay_url;


            if (issucc == true)
            {
                Dictionary <string, object> conditions2 = new Dictionary <string, object>();


                conditions2.Add("OrderID", orderid);
                conditions2.Add("ChannelOrderID", order_no);

                PayOrderController ent = new PayOrderController();

                conditions2.Add("UserID", int.Parse(getuserid));
                conditions2.Add("GoodsType", int.Parse(GoodsType));
                conditions2.Add("PayType", 6);
                conditions2.Add("PayAmount", "500");
                conditions2.Add("BuyCount", 0);
                conditions2.Add("BackCount", 0);
                conditions2.Add("PayState", 1);
                ent.PayOrderAdd(conditions2);
                //if (bank_Type == "1")
                //{
                //    Response.Redirect(pay_url);
                //}
                //else
                //{
                //Panel1.Visible = true;
                var    foredcode = pay_url;
                var    path      = Server.MapPath("/qrcode_data");
                Bitmap getimage  = Create_ImgCode(path, foredcode, 10);

                string imgname  = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
                string savepath = "/CodeEncoder/" + imgname;
                getimage.Save(Server.MapPath(savepath));
                // this.Image1.ImageUrl = savepath;
                Response.Redirect("dopay.aspx?btype=" + bank_Type + "&url=" + savepath);
                //}
            }
            else
            {
                Response.Write("返回数据错误" + result);
            }
        }
示例#4
0
        public async Task <VerifyRequestModel> VerifyRequest(PayReturnModel model)
        {
            var result = await _requestManagerService.Post <ServiceResponse <VerifyRequestModel> >("/update_payment_request", model);

            return(result.DataModel);
        }