Example #1
0
 /// <summary>
 /// 微信支付下单
 /// JsAPI下单部分
 /// </summary>
 /// <param name="reqmodel"></param>
 /// <returns></returns>
 public UnifiedOrderModelForJSAPI WxPayUnifiedOrderForJSAPI(RequestUnifiedOrder reqmodel)
 {
     try
     {
         var wxPayAcc  = JsonHelper.Deserialize <WxPayAccVM>(AccStr);
         var nonceStr  = TenPayV3Util.GetNoncestr();
         var timeStamp = TenPayV3Util.GetTimestamp();
         //此处填入此支付附加信息
         var attach      = string.Empty;
         var xmlDataInfo = new TenPayV3UnifiedorderRequestData(wxPayAcc.AppId, wxPayAcc.MchId, reqmodel.Body,
                                                               reqmodel.OutTradeNo, reqmodel.TotalFee, reqmodel.SpbillCreateIp, wxPayAcc.NotifyUrl, Senparc.Weixin.TenPay.TenPayV3Type.JSAPI,
                                                               reqmodel.OpenId, wxPayAcc.MchIdKey, nonceStr, null, null, null, null, attach);
         var result  = TenPayV3.Html5Order(xmlDataInfo);               //调用统一订单接口
         var package = string.Format("prepay_id={0}", result.prepay_id);
         var paySign = TenPayV3.GetJsPaySign(wxPayAcc.AppId, timeStamp, nonceStr, package, wxPayAcc.MchIdKey);
         var model   = new UnifiedOrderModelForJSAPI
         {
             AppId     = result.appid,
             NonceStr  = nonceStr,
             TimeStamp = timeStamp,
             Package   = package,
             SignType  = "MD5",
             PaySign   = paySign
         };
         return(model);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
        public object Do_Payment(object param)
        {
            PaymentParam paymentParam = JsonConvert.DeserializeObject <PaymentParam>(param.ToString());

            if (paymentParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            try
            {
                SessionBag sessionBag = SessionContainer.GetSession(paymentParam.token);
                var        openId     = sessionBag.OpenId;
                var        billId     = this.createBill(openId, paymentParam);
                var        totalPrice = this.getBillPrice(paymentParam);
                if (totalPrice == 0)
                {
                    throw new ApiException(CodeMessage.PaymentTotalPriceZero, "PaymentTotalPriceZero");
                }
                var timeStamp   = TenPayV3Util.GetTimestamp();
                var nonceStr    = TenPayV3Util.GetNoncestr();
                var product     = paymentParam.product;
                var xmlDataInfo =
                    new TenPayV3UnifiedorderRequestData(
                        tenPayV3Info.AppId,
                        tenPayV3Info.MchId,
                        product,
                        billId,
                        totalPrice,
                        "127.0.0.1",
                        tenPayV3Info.TenPayV3Notify,
                        TenPayV3Type.JSAPI,
                        openId,
                        tenPayV3Info.Key,
                        nonceStr);

                var result = TenPayV3.Html5Order(xmlDataInfo);
                pDao.writePrePayId(billId, result.prepay_id);
                var package = string.Format("prepay_id={0}", result.prepay_id);
                var paySign = TenPayV3.GetJsPaySign(tenPayV3Info.AppId, timeStamp, nonceStr, package, tenPayV3Info.Key);

                PaymentResults paymentResults = new PaymentResults();
                paymentResults.appId     = tenPayV3Info.AppId;
                paymentResults.nonceStr  = nonceStr;
                paymentResults.package   = package;
                paymentResults.paySign   = paySign;
                paymentResults.timeStamp = timeStamp;
                paymentResults.product   = product;
                paymentResults.billId    = billId;

                return(paymentResults);
            }
            catch (Exception ex)
            {
                throw new ApiException(CodeMessage.PaymentError, "PaymentError");
            }
        }
Example #3
0
        /// <summary>
        /// H5支付
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="hc"></param>
        /// <returns></returns>
        public ActionResult H5Pay(int productId, int hc)
        {
            {
                try
                {
                    //获取产品信息
                    var products = ProductModel.GetFakeProductList();
                    var product  = products.FirstOrDefault(z => z.Id == productId);
                    if (product == null || product.GetHashCode() != hc)
                    {
                        return(Content("商品信息不存在,或非法进入!1002"));
                    }

                    string openId = null;//此时在外部浏览器,无法或得到OpenId

                    string sp_billno = Request.Query["order_no"];
                    if (string.IsNullOrEmpty(sp_billno))
                    {
                        //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                        sp_billno = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"),
                                                  TenPayV3Util.BuildRandomStr(6));
                    }
                    else
                    {
                        sp_billno = Request.Query["order_no"];
                    }

                    var timeStamp = TenPayV3Util.GetTimestamp();
                    var nonceStr  = TenPayV3Util.GetNoncestr();

                    var body  = product == null ? "test" : product.Name;
                    var price = product == null ? 100 : (int)product.Price * 100;
                    //var ip = Request.Params["REMOTE_ADDR"];
                    var xmlDataInfo = new TenPayV3UnifiedorderRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, body, sp_billno, price, HttpContext.UserHostAddress()?.ToString(), TenPayV3Info.TenPayV3Notify, TenPay.TenPayV3Type.MWEB /*此处无论传什么,方法内部都会强制变为MWEB*/, openId, TenPayV3Info.Key, nonceStr);

                    var result = TenPayV3.Html5Order(xmlDataInfo); //调用统一订单接口
                                                                   //JsSdkUiPackage jsPackage = new JsSdkUiPackage(TenPayV3Info.AppId, timeStamp, nonceStr,);

                    /*
                     * result:{"device_info":"","trade_type":"MWEB","prepay_id":"wx20170810143223420ae5b0dd0537136306","code_url":"","mweb_url":"https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx20170810143223420ae5b0dd0537136306\u0026package=1505175207","appid":"wx669ef95216eef885","mch_id":"1241385402","sub_appid":"","sub_mch_id":"","nonce_str":"juTchIZyhXvZ2Rfy","sign":"5A37D55A897C854F64CCCC4C94CDAFE3","result_code":"SUCCESS","err_code":"","err_code_des":"","return_code":"SUCCESS","return_msg":null}
                     */
                    //return Json(result, JsonRequestBehavior.AllowGet);

                    var package = string.Format("prepay_id={0}", result.prepay_id);

                    ViewData["product"] = product;

                    ViewData["appId"]     = TenPayV3Info.AppId;
                    ViewData["timeStamp"] = timeStamp;
                    ViewData["nonceStr"]  = nonceStr;
                    ViewData["package"]   = package;
                    ViewData["paySign"]   = TenPayV3.GetJsPaySign(TenPayV3Info.AppId, timeStamp, nonceStr, package, TenPayV3Info.Key);

                    //设置成功页面(也可以不设置,支付成功后默认返回来源地址)
                    var returnUrl =
                        string.Format("https://sdk.weixin.senparc.com/TenpayV3/H5PaySuccess?productId={0}&hc={1}",
                                      productId, hc);

                    var mwebUrl = result.mweb_url;
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        mwebUrl += string.Format("&redirect_url={0}", returnUrl.AsUrlData());
                    }

                    ViewData["MWebUrl"] = mwebUrl;

                    //临时记录订单信息,留给退款申请接口测试使用
                    HttpContext.Session.SetString("BillNo", sp_billno);
                    HttpContext.Session.SetString("BillFee", price.ToString());

                    return(View());
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                    msg += "<br>" + ex.StackTrace;
                    msg += "<br>==Source==<br>" + ex.Source;

                    if (ex.InnerException != null)
                    {
                        msg += "<br>===InnerException===<br>" + ex.InnerException.Message;
                    }
                    return(Content(msg));
                }
            }
        }
Example #4
0
        /// <summary>
        /// H5支付
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="hc"></param>
        /// <returns></returns>
        public ActionResult H5Pay(int orderId = 0)
        {
            {
                try
                {
                    string openId = null;//此时在外部浏览器,无法或得到OpenId

                    string sp_billno = Request["order_no"];
                    if (string.IsNullOrEmpty(sp_billno))
                    {
                        //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                        sp_billno = string.Format("{0}{1}{2}", "1234567890", DateTime.Now.ToString("yyyyMMddHHmmss"),
                                                  TenPayV3Util.BuildRandomStr(6));
                    }
                    else
                    {
                        sp_billno = Request["order_no"];
                    }

                    var timeStamp = TenPayV3Util.GetTimestamp();
                    var nonceStr  = TenPayV3Util.GetNoncestr();

                    var body  = "SenparcProduct"; //产品名称
                    var price = 100;              //单位:分

                    //var ip = Request.Params["REMOTE_ADDR"];
                    var xmlDataInfo = new TenPayV3UnifiedorderRequestData(Service.Config.AppId, Service.Config.MchId,
                                                                          body, sp_billno, price, Request.UserHostAddress, Service.Config.TenPayV3Notify,
                                                                          TenPayV3Type.MWEB /*此处无论传什么,方法内部都会强制变为MWEB*/, openId,
                                                                          Service.Config.TenPayV3_Key, nonceStr);

                    var result = TenPayV3.Html5Order(xmlDataInfo); //调用统一订单接口
                                                                   //JsSdkUiPackage jsPackage = new JsSdkUiPackage(TenPayV3Info.AppId, timeStamp, nonceStr,);

                    /*
                     * result:{"device_info":"","trade_type":"MWEB","prepay_id":"wx20170810143223420ae5b0dd0537136306","code_url":"","mweb_url":"https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx20170810143223420ae5b0dd0537136306\u0026package=1505175207","appid":"wx669ef95216eef885","mch_id":"1241385402","sub_appid":"","sub_mch_id":"","nonce_str":"juTchIZyhXvZ2Rfy","sign":"5A37D55A897C854F64CCCC4C94CDAFE3","result_code":"SUCCESS","err_code":"","err_code_des":"","return_code":"SUCCESS","return_msg":null}
                     */
                    //return Json(result, JsonRequestBehavior.AllowGet);

                    var package = string.Format("prepay_id={0}", result.prepay_id);

                    //ViewData["product"] = product;

                    ViewData["appId"]     = Service.Config.AppId;
                    ViewData["timeStamp"] = timeStamp;
                    ViewData["nonceStr"]  = nonceStr;
                    ViewData["package"]   = package;
                    ViewData["paySign"]   = TenPayV3.GetJsPaySign(Service.Config.AppId, timeStamp, nonceStr, package, Service.Config.TenPayV3_Key);

                    //设置成功页面(也可以不设置,支付成功后默认返回来源地址)
                    var returnUrl =
                        string.Format("https://sdk.weixin.senparc.com/TenpayV3/H5PaySuccess?orderId={0}",
                                      orderId);

                    var mwebUrl = result.mweb_url;
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        mwebUrl += string.Format("&redirect_url={0}", returnUrl.AsUrlData());
                    }

                    ViewData["MWebUrl"] = mwebUrl;

                    //临时记录订单信息,留给退款申请接口测试使用
                    Session["BillNo"]  = sp_billno;
                    Session["BillFee"] = price;

                    return(View());
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                    msg += "<br>" + ex.StackTrace;
                    msg += "<br>==Source==<br>" + ex.Source;

                    if (ex.InnerException != null)
                    {
                        msg += "<br>===InnerException===<br>" + ex.InnerException.Message;
                    }
                    return(Content(msg));
                }
            }
        }
Example #5
0
        public ActionResult ajaxorder(string orderno)
        {
            try
            {
                ReturnJson root         = null;
                var        ordersEntity = ordersbll.GetEntityByOrderSn(orderno);
                if (ordersEntity != null)
                {
                    var sp_billno = ordersEntity.OrderSn;
                    var nonceStr  = TenPayV3Util.GetNoncestr();

                    //商品Id,用户自行定义
                    string  productId = ordersEntity.TelphoneID.ToString();
                    decimal?Amount    = ordersEntity.Price;//0.01M 测试
                    if (Amount < 0)
                    {
                        root = new ReturnJson {
                            code = 200, msg = "付款金额小于0"
                        };
                    }
                    else
                    {
                        if (ordersEntity.PayType == "支付宝")
                        {
                            try
                            {
                                DefaultAopClient client = new DefaultAopClient(WeixinConfig.serviceUrl, WeixinConfig.aliAppId, WeixinConfig.privateKey, "json", "1.0",
                                                                               WeixinConfig.signType, WeixinConfig.payKey, WeixinConfig.charset, false);

                                // 组装业务参数model
                                AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
                                model.Body           = "支付宝购买靓号";                                       // 商品描述
                                model.Subject        = productId;                                       // 订单名称
                                model.TotalAmount    = Amount.ToString();                               // 付款金额"0.01"ordersEntity.Price.ToString()
                                model.OutTradeNo     = sp_billno;                                       // 外部订单号,商户网站订单系统中唯一的订单号
                                model.ProductCode    = "QUICK_WAP_WAY";
                                model.QuitUrl        = "http://www.1650539.com/webapp/agentshop/index"; // 支付中途退出返回商户网站地址
                                model.TimeoutExpress = "90m";
                                AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
                                //设置支付完成同步回调地址
                                request.SetReturnUrl(WeixinConfig.return_url);
                                //设置支付完成异步通知接收地址
                                request.SetNotifyUrl(WeixinConfig.notify_url);
                                // 将业务model载入到request
                                request.SetBizModel(model);

                                AlipayTradeWapPayResponse response = null;
                                try
                                {
                                    response = client.pageExecute(request, null, "post");
                                    //Response.Write(response.Body);
                                    H5PayData h5PayData = new H5PayData();
                                    h5PayData.form = response.Body;
                                    root           = new ReturnJson {
                                        code = 200, msg = "\u652f\u4ed8\u5b9d\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData
                                    };
                                }
                                catch (Exception exp)
                                {
                                    throw exp;
                                }
                            }
                            catch (Exception ex)
                            {
                                //return Json(new { Result = false, msg = "缺少参数" });
                            }
                        }
                        else
                        {
                            //0 手机(H5支付)  1 电脑(扫码Native支付),2微信浏览器(JSAPI)
                            //pc端返回二维码,否则H5
                            if (ordersEntity.PayType == "微信扫码")
                            {
                                //创建请求统一订单接口参数
                                var xmlDataInfo = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID,
                                                                                      tenPayV3Info.MchId,
                                                                                      "扫码支付靓号",
                                                                                      sp_billno,
                                                                                      Convert.ToInt32(Amount * 100),
                                                                                      //1,
                                                                                      Request.UserHostAddress,
                                                                                      tenPayV3Info.TenPayV3Notify,
                                                                                      TenPayV3Type.NATIVE,
                                                                                      null,
                                                                                      tenPayV3Info.Key,
                                                                                      nonceStr,
                                                                                      productId: productId);
                                //调用统一订单接口
                                var result = TenPayV3.Unifiedorder(xmlDataInfo);
                                if (result.return_code == "SUCCESS")
                                {
                                    H5PayData h5PayData = new H5PayData()
                                    {
                                        appid         = WeixinConfig.AppID,
                                        code_url      = result.code_url,//weixin://wxpay/bizpayurl?pr=lixpXgt-----------扫码支付
                                        mch_id        = WeixinConfig.MchId,
                                        nonce_str     = result.nonce_str,
                                        prepay_id     = result.prepay_id,
                                        result_code   = result.result_code,
                                        return_code   = result.return_code,
                                        return_msg    = result.return_msg,
                                        sign          = result.sign,
                                        trade_type    = "NATIVE",
                                        trade_no      = sp_billno,
                                        payid         = ordersEntity.Id.ToString(),
                                        wx_query_href = "http://www.1650539.com/webapp/agentshop/queryWx/" + ordersEntity.Id,
                                        wx_query_over = "http://www.1650539.com/webapp/agentshop/paymentFinish/" + ordersEntity.Id
                                    };

                                    root = new ReturnJson {
                                        code = 200, msg = "\u5fae\u4fe1\u626b\u7801\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData
                                    };
                                }
                                else
                                {
                                    root = new ReturnJson {
                                        code = 400, msg = result.return_msg
                                    };
                                }
                            }
                            else
                            {
                                var xmlDataInfoH5 = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID, tenPayV3Info.MchId, "H5购买靓号", sp_billno,
                                                                                        // 1,
                                                                                        Convert.ToInt32(Amount * 100),
                                                                                        Request.UserHostAddress, tenPayV3Info.TenPayV3Notify, TenPayV3Type.MWEB /*此处无论传什么,方法内部都会强制变为MWEB*/, null, tenPayV3Info.Key, nonceStr);

                                var resultH5 = TenPayV3.Html5Order(xmlDataInfoH5); //调用统一订单接口
                                LogHelper.AddLog(resultH5.ResultXml);              //记录日志
                                if (resultH5.return_code == "SUCCESS")
                                {
                                    H5PayData h5PayData = new H5PayData()
                                    {
                                        appid         = WeixinConfig.AppID,
                                        mweb_url      = resultH5.mweb_url,//H5访问链接
                                        mch_id        = WeixinConfig.MchId,
                                        nonce_str     = resultH5.nonce_str,
                                        prepay_id     = resultH5.prepay_id,
                                        result_code   = resultH5.result_code,
                                        return_code   = resultH5.return_code,
                                        return_msg    = resultH5.return_msg,
                                        sign          = resultH5.sign,
                                        trade_type    = "H5",
                                        trade_no      = sp_billno,
                                        payid         = ordersEntity.Id.ToString(),
                                        wx_query_href = "http://www.1650539.com/webapp/agentshop/queryWx/" + ordersEntity.Id,
                                        wx_query_over = "http://www.1650539.com/webapp/agentshop/paymentFinish/" + ordersEntity.Id
                                    };

                                    root = new ReturnJson {
                                        code = 200, msg = "\u5fae\u4fe1\u0048\u0035\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData
                                    };
                                }
                                else
                                {
                                    root = new ReturnJson {
                                        code = 400, msg = resultH5.return_msg
                                    };
                                }
                            }
                        }
                    }
                }
                else
                {
                    root = new ReturnJson {
                        code = 400, msg = "订单号不存在!"
                    };
                }

                LogHelper.AddLog(JsonConvert.SerializeObject(root));//记录日志
                return(Json(root));
            }
            catch (Exception ex)
            {
                LogHelper.AddLog(ex.Message);//记录日志
                throw;
            }
        }
Example #6
0
        /// <summary>
        /// H5支付
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="hc"></param>
        /// <returns></returns>
        public ActionResult H5Pay(int productId, int hc)
        {
            {
                try
                {
                    //获取产品信息
                    var products = ProductModel.GetFakeProductList();
                    var product  = products.FirstOrDefault(z => z.Id == productId);
                    if (product == null || product.GetHashCode() != hc)
                    {
                        return(Content("商品信息不存在,或非法进入!1002"));
                    }

                    string openId = null;//此时在外部浏览器,无法或得到OpenId

                    string sp_billno = Request["order_no"];
                    if (string.IsNullOrEmpty(sp_billno))
                    {
                        //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                        sp_billno = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, DateTime.Now.ToString("yyyyMMddHHmmss"),
                                                  TenPayV3Util.BuildRandomStr(6));
                    }
                    else
                    {
                        sp_billno = Request["order_no"];
                    }

                    var timeStamp = TenPayV3Util.GetTimestamp();
                    var nonceStr  = TenPayV3Util.GetNoncestr();

                    var body  = product == null ? "test" : product.Name;
                    var price = product == null ? 100 : (int)product.Price * 100;
                    //var ip = Request.Params["REMOTE_ADDR"];
                    var xmlDataInfo = new TenPayV3UnifiedorderRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, body, sp_billno, price, Request.UserHostAddress, TenPayV3Info.TenPayV3Notify, TenPayV3Type.MWEB /*此处无论传什么,方法内部都会强制变为MWEB*/, openId, TenPayV3Info.Key, nonceStr);

                    var result = TenPayV3.Html5Order(xmlDataInfo); //调用统一订单接口
                                                                   //JsSdkUiPackage jsPackage = new JsSdkUiPackage(TenPayV3Info.AppId, timeStamp, nonceStr,);
                    var package = string.Format("prepay_id={0}", result.prepay_id);

                    ViewData["product"] = product;

                    ViewData["appId"]        = TenPayV3Info.AppId;
                    ViewData["timeStamp"]    = timeStamp;
                    ViewData["nonceStr"]     = nonceStr;
                    ViewData["package"]      = package;
                    ViewData["paySign"]      = TenPayV3.GetJsPaySign(TenPayV3Info.AppId, timeStamp, nonceStr, package, TenPayV3Info.Key);
                    ViewData["MidWechatUrl"] = result.code_url;


                    //临时记录订单信息,留给退款申请接口测试使用
                    Session["BillNo"]  = sp_billno;
                    Session["BillFee"] = price;


                    return(View());
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                    msg += "<br>" + ex.StackTrace;
                    msg += "<br>==Source==<br>" + ex.Source;

                    if (ex.InnerException != null)
                    {
                        msg += "<br>===InnerException===<br>" + ex.InnerException.Message;
                    }
                    return(Content(msg));
                }
            }
            return(View());
        }
Example #7
0
        public ActionResult ajaxorder(OrdersEntity ordersEntity)
        {
            try
            {
                string city = ordersEntity.City;
                if (city.Contains("-"))
                {
                    string[] area = ordersEntity.City.Split('-');
                    if (area.Length > 0)
                    {
                        ordersEntity.Province = area[0]; //省
                        ordersEntity.City     = area[1]; //市
                        ordersEntity.Country  = area[2]; //市
                    }
                }
                else
                {
                    string[] area = ordersEntity.City.Split(' ');
                    if (area.Length > 0)
                    {
                        ordersEntity.Province = area[0]; //省
                        ordersEntity.City     = area[1]; //市
                    }
                }

                string payType = ordersEntity.PayType;
                if (payType == "alipay")
                {
                    payType = "支付宝";
                }
                else
                {
                    if (ordersEntity.PC == 1)
                    {
                        payType = "微信扫码";
                    }
                    else
                    {
                        payType = "微信H5";
                    }
                }
                ordersEntity.PayType = payType;
                ordersEntity         = ordersbll.SaveForm(ordersEntity);

                var sp_billno = ordersEntity.OrderSn;
                var nonceStr  = TenPayV3Util.GetNoncestr();

                //商品Id,用户自行定义
                string productId = ordersEntity.TelphoneID.ToString();

                H5Response root = null;

                if (payType == "支付宝")
                {
                    try
                    {
                        DefaultAopClient client = new DefaultAopClient(WeixinConfig.serviceUrl, WeixinConfig.aliAppId, WeixinConfig.privateKey, "json", "1.0",
                                                                       WeixinConfig.signType, WeixinConfig.payKey, WeixinConfig.charset, false);

                        // 组装业务参数model
                        AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
                        model.Body           = "支付宝购买靓号";                                           // 商品描述
                        model.Subject        = productId;                                           // 订单名称
                        model.TotalAmount    = ordersEntity.Price.ToString();                       // 付款金额"0.01"
                        model.OutTradeNo     = sp_billno;                                           // 外部订单号,商户网站订单系统中唯一的订单号
                        model.ProductCode    = "QUICK_WAP_WAY";
                        model.QuitUrl        = "https://ghdh.digitdance.cn:8069/webapp/jntt/Index"; // 支付中途退出返回商户网站地址
                        model.TimeoutExpress = "90m";
                        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
                        //设置支付完成同步回调地址
                        request.SetReturnUrl(WeixinConfig.return_url);
                        //设置支付完成异步通知接收地址
                        request.SetNotifyUrl(WeixinConfig.notify_url);
                        // 将业务model载入到request
                        request.SetBizModel(model);

                        AlipayTradeWapPayResponse response = null;
                        try
                        {
                            response = client.pageExecute(request, null, "post");
                            //Response.Write(response.Body);

                            H5PayData h5PayData = new H5PayData();
                            h5PayData.form = response.Body;
                            root           = new H5Response {
                                code = true, status = true, msg = "\u652f\u4ed8\u5b9d\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData
                            };
                        }
                        catch (Exception exp)
                        {
                            throw exp;
                        }
                    }
                    catch (Exception ex)
                    {
                        //return Json(new { Result = false, msg = "缺少参数" });
                    }
                }
                else
                {
                    //pc端返回二维码,否则H5
                    if (payType == "微信扫码")
                    {
                        //创建请求统一订单接口参数
                        var xmlDataInfo = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID2,
                                                                              tenPayV3Info.MchId,
                                                                              "扫码支付靓号",
                                                                              sp_billno,
                                                                              Convert.ToInt32(ordersEntity.Price * 100),
                                                                              //1,
                                                                              Request.UserHostAddress,
                                                                              tenPayV3Info.TenPayV3Notify,
                                                                              TenPayV3Type.NATIVE,
                                                                              null,
                                                                              tenPayV3Info.Key,
                                                                              nonceStr,
                                                                              productId: productId);
                        //调用统一订单接口
                        var result = TenPayV3.Unifiedorder(xmlDataInfo);
                        if (result.return_code == "SUCCESS")
                        {
                            H5PayData h5PayData = new H5PayData()
                            {
                                appid         = WeixinConfig.AppID2,
                                code_url      = result.code_url,//weixin://wxpay/bizpayurl?pr=lixpXgt-----------扫码支付
                                mch_id        = WeixinConfig.MchId,
                                nonce_str     = result.nonce_str,
                                prepay_id     = result.prepay_id,
                                result_code   = result.result_code,
                                return_code   = result.return_code,
                                return_msg    = result.return_msg,
                                sign          = result.sign,
                                trade_type    = "NATIVE",
                                trade_no      = sp_billno,
                                payid         = ordersEntity.Id.ToString(),
                                wx_query_href = "https://shop.jnlxsm.net/webapp/jntt/queryWx/" + ordersEntity.Id,
                                wx_query_over = "https://shop.jnlxsm.net/webapp/jntt/paymentFinish/" + ordersEntity.Id
                            };

                            root = new H5Response {
                                code = true, status = true, msg = "\u5fae\u4fe1\u626b\u7801\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData
                            };
                        }
                        else
                        {
                            root = new H5Response {
                                code = false, status = false, msg = result.return_msg
                            };
                        }
                    }
                    else
                    {
                        var xmlDataInfoH5 = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID2, tenPayV3Info.MchId, "H5购买靓号", sp_billno,
                                                                                // 1,
                                                                                Convert.ToInt32(ordersEntity.Price * 100),
                                                                                Request.UserHostAddress, tenPayV3Info.TenPayV3Notify, TenPayV3Type.MWEB /*此处无论传什么,方法内部都会强制变为MWEB*/, null, tenPayV3Info.Key, nonceStr);

                        var resultH5 = TenPayV3.Html5Order(xmlDataInfoH5); //调用统一订单接口
                        LogHelper.AddLog(resultH5.ResultXml);              //记录日志
                        if (resultH5.return_code == "SUCCESS")
                        {
                            H5PayData h5PayData = new H5PayData()
                            {
                                appid         = WeixinConfig.AppID2,
                                mweb_url      = resultH5.mweb_url,//H5访问链接
                                mch_id        = WeixinConfig.MchId,
                                nonce_str     = resultH5.nonce_str,
                                prepay_id     = resultH5.prepay_id,
                                result_code   = resultH5.result_code,
                                return_code   = resultH5.return_code,
                                return_msg    = resultH5.return_msg,
                                sign          = resultH5.sign,
                                trade_type    = "H5",
                                trade_no      = sp_billno,
                                payid         = ordersEntity.Id.ToString(),
                                wx_query_href = "https://shop.jnlxsm.net/webapp/jntt/queryWx/" + ordersEntity.Id,
                                wx_query_over = "https://shop.jnlxsm.net/webapp/jntt/paymentFinish/" + ordersEntity.Id
                            };

                            root = new H5Response {
                                code = true, status = true, msg = "\u5fae\u4fe1\u0048\u0035\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData
                            };
                        }
                        else
                        {
                            root = new H5Response {
                                code = false, status = false, msg = resultH5.return_msg
                            };
                        }
                    }
                }

                LogHelper.AddLog(JsonConvert.SerializeObject(root));//记录日志

                return(Content(JsonConvert.SerializeObject(root)));
            }
            catch (Exception ex)
            {
                LogHelper.AddLog(ex.Message);//记录日志
                throw;
            }
        }
Example #8
0
        public object Do_Payment(BaseApi baseApi)
        {
            PaymentParam paymentParam = JsonConvert.DeserializeObject <PaymentParam>(baseApi.param.ToString());

            if (paymentParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            if (paymentParam.billId == null || paymentParam.billId == "")
            {
                throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError");
            }

            string  openId  = Utils.GetOpenID(baseApi.token);
            OpenDao openDao = new OpenDao();

            //处理10分取消未支付订单
            openDao.UpdateBookingStatusBy10Minute(openId);
            BILLLIST billList = openDao.getBillListById(paymentParam.billId, openId);

            if (billList == null)
            {
                throw new ApiException(CodeMessage.PaymentBillError, "PaymentBillError");
            }
            if (billList.bookingState != "1")
            {
                throw new ApiException(CodeMessage.PaymentStateError, "PaymentStateError");
            }
            var billId     = paymentParam.billId;
            int totalPrice = Convert.ToInt32(billList.billPrice * 100);

            if (totalPrice <= 0)
            {
                throw new ApiException(CodeMessage.PaymentTotalPriceZero, "PaymentTotalPriceZero");
            }

            //if (billList.prePayId!=null && billList.prePayId!="" && billList.prePayTime != null && billList.prePayTime != "")
            //{
            //    try
            //    {
            //        DateTime preDateTime = Convert.ToDateTime(billList.prePayTime);
            //        if (DateTime.Now.AddHours(-2)< preDateTime)
            //        {
            //            var timeStamp = TenPayV3Util.GetTimestamp();
            //            var nonceStr = TenPayV3Util.GetNoncestr();
            //            var product = "船票";
            //            var package = string.Format("prepay_id={0}", billList.prePayId);
            //            var paySign = TenPayV3.GetJsPaySign(tenPayV3Info.AppId, timeStamp, nonceStr, package, tenPayV3Info.Key);

            //            PaymentResults paymentResults = new PaymentResults();
            //            paymentResults.appId = tenPayV3Info.AppId;
            //            paymentResults.nonceStr = nonceStr;
            //            paymentResults.package = package;
            //            paymentResults.paySign = paySign;
            //            paymentResults.timeStamp = timeStamp;
            //            paymentResults.product = product;
            //            paymentResults.billId = billId;

            //            return paymentResults;
            //        }
            //    }
            //    catch (Exception)
            //    {

            //    }

            //}

            try
            {
                var timeStamp   = TenPayV3Util.GetTimestamp();
                var nonceStr    = TenPayV3Util.GetNoncestr();
                var product     = "船票";
                var xmlDataInfo =
                    new TenPayV3UnifiedorderRequestData(
                        tenPayV3Info.AppId,
                        tenPayV3Info.MchId,
                        product,
                        billId,
                        totalPrice,
                        "127.0.0.1",
                        tenPayV3Info.TenPayV3Notify,
                        TenPayV3Type.JSAPI,
                        openId,
                        tenPayV3Info.Key,
                        nonceStr);

                var result = TenPayV3.Html5Order(xmlDataInfo);
                if (result.return_msg != "")
                {
                    openDao.writeLog(Global.POSCODE, "", "pay", result.return_msg);
                }

                pDao.writePrePayId(billId, result.prepay_id);
                var package = string.Format("prepay_id={0}", result.prepay_id);
                var paySign = TenPayV3.GetJsPaySign(tenPayV3Info.AppId, timeStamp, nonceStr, package, tenPayV3Info.Key);

                PaymentResults paymentResults = new PaymentResults();
                paymentResults.appId     = tenPayV3Info.AppId;
                paymentResults.nonceStr  = nonceStr;
                paymentResults.package   = package;
                paymentResults.paySign   = paySign;
                paymentResults.timeStamp = timeStamp;
                paymentResults.product   = product;
                paymentResults.billId    = billId;

                return(paymentResults);
            }
            catch (Exception ex)
            {
                throw new ApiException(CodeMessage.PaymentError, "PaymentError");
            }
        }