/// <summary>
        /// 获取微信预支付信息包
        /// </summary>
        /// <returns></returns>
        private static string GetWxPayPackage(OnLinePayOrder orderReturn, string paytype, string openid,
                                              string authority)
        {
            string    domain = string.IsNullOrEmpty(AppConfig.FrontSiteDomain) ? authority : AppConfig.FrontSiteDomain;
            WxPayInfo wx     = new WxPayInfo
            {
                AppID     = ApplicationSettings.Get(paytype == "wx" ? "WXAPPID" : "WXNATIVEAPPID"),
                AppSecret = ApplicationSettings.Get(paytype == "wx" ? "WXAPPSECRET" : "WXNATIVESECRET"),
                // ReSharper disable once SpecifyACultureInStringConversionExplicitly
                Body       = orderReturn.Amount.ToString(),
                Key        = ApplicationSettings.Get(paytype == "wx" ? "WXAPPKEY" : "WXNATIVEKEY"),
                Mchid      = ApplicationSettings.Get(paytype == "wx" ? "WXAPPMCHID" : "WXNATIVEMCHID"),
                NotifyUrl  = "http://" + domain + "/Notify/" + (paytype == "wx" ? "WxApp.aspx" : "WxWeb.aspx"),
                OpenId     = openid,
                OutTradeNo = orderReturn.OrderID,
                TotalFee   = (orderReturn.Amount * 100).ToString("F0"),
                TradeType  = paytype == "wx" ? "APP" : "JSAPI"
            };
            WxPayHelper helper = new WxPayHelper(wx);

            return(helper.GetPrepayIDSign());
        }
Пример #2
0
        public IHttpActionResult GetPayInfo(string accessToken, int channel, int platform, string ver, int type)
        {
            Logger.WriterLogger("Common.GetPayInfo, Params: " + string.Format("accessToken={0}&channel={1}&platform={2}&ver={3}", accessToken, channel, platform, ver), LoggerType.Info);

            // 保存访问信息
            base.SaveVisitInfo("", channel, platform, ver);

            // 验证令牌
            int accessTookenCode = VerifyAccessToken(accessToken);

            if (accessTookenCode > 0)
            {
                return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), "Common.GetPayInfo"));
            }

            if (type == 1)
            {
                PaymentModeInfo paymentMode = SalesHelper.GetPaymentMode("Ecdev.plugins.payment.ws_wappay.wswappayrequest");
                if (paymentMode != null)
                {
                    string xml = HiCryptographer.Decrypt(paymentMode.Settings);
                    System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
                    xmlDocument.LoadXml(xml);

                    AliPayInfo info = new AliPayInfo();
                    info.Partner = xmlDocument.GetElementsByTagName("Partner")[0].InnerText;
                    info.Key     = xmlDocument.GetElementsByTagName("Key")[0].InnerText;
                    info.Account = xmlDocument.GetElementsByTagName("Seller_account_name")[0].InnerText;


                    StandardResult <AliPayInfo> result = new StandardResult <AliPayInfo>()
                    {
                        code = 0,
                        msg  = "",
                        data = info
                    };

                    return(base.JsonActionResult(result));
                }

                else
                {
                    StandardResult <string> result = new StandardResult <string>()
                    {
                        code = 1,
                        msg  = "未找到配置",
                        data = ""
                    };

                    return(base.JsonActionResult(result));
                }
            }

            else
            {
                PaymentModeInfo paymentMode = SalesHelper.GetPaymentMode("Ecdev.plugins.payment.wx_apppay.wxwappayrequest");
                if (paymentMode != null)
                {
                    string xml = HiCryptographer.Decrypt(paymentMode.Settings);
                    System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
                    xmlDocument.LoadXml(xml);
                    WxPayInfo info = new WxPayInfo();
                    info.AppId     = xmlDocument.GetElementsByTagName("AppId")[0].InnerText;
                    info.Key       = xmlDocument.GetElementsByTagName("Key")[0].InnerText;;
                    info.AppSecret = xmlDocument.GetElementsByTagName("AppSecret")[0].InnerText;
                    info.Mch_id    = xmlDocument.GetElementsByTagName("Mch_id")[0].InnerText;

                    StandardResult <WxPayInfo> result = new StandardResult <WxPayInfo>()
                    {
                        code = 0,
                        msg  = "",
                        data = info
                    };

                    return(base.JsonActionResult(result));
                }

                else
                {
                    StandardResult <string> result = new StandardResult <string>()
                    {
                        code = 1,
                        msg  = "未找到配置",
                        data = ""
                    };

                    return(base.JsonActionResult(result));
                }
            }
        }
Пример #3
0
        public WxPayOrder Pay(WxPayInfo wxPayInfo)
        {
            //  var us = GetUserSession(false);


            WxPayOrder wxOrder  = null;
            JsApiPay   jsApiPay = new JsApiPay();

            try
            {
                var us = GetUserSession(false);
                if (us != null)
                {
                    string notifyUrl = "http://edu.iqiban.cn/api/wxPay/Notify";

                    var eCoursePrice = _CourseSrv.GetCoursePrice(wxPayInfo.PriceCode);
                    if (eCoursePrice.CourseScheduleType == EduCenterModel.BaseEnum.CourseScheduleType.VIP)
                    {
                        eCoursePrice.Qty   = wxPayInfo.VIPQty;
                        eCoursePrice.Price = us.UserAccount.VIPPrice1 * eCoursePrice.Qty;
                    }


                    jsApiPay.openid    = us.OpenId;
                    jsApiPay.total_fee = (int)eCoursePrice.Price * 100;



                    string OrderNo = WxPayApi.GenerateOutTradeNo();
                    var    order   = _BusinessSrv.PayCourseOrder(us.OpenId, eCoursePrice);

                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(wxPayInfo.ItemDes, notifyUrl, OrderNo);
                    WxPayData wxJsApiParam       = jsApiPay.GetJsApiParameters();

                    wxOrder = new WxPayOrder()
                    {
                        appId      = wxJsApiParam.GetValue("appId").ToString(),
                        nonceStr   = wxJsApiParam.GetValue("nonceStr").ToString(),
                        package    = wxJsApiParam.GetValue("package").ToString(),
                        paySign    = wxJsApiParam.GetValue("paySign").ToString(),
                        signType   = "MD5",
                        timeStamp  = wxJsApiParam.GetValue("timeStamp").ToString(),
                        OrderNo    = OrderNo,
                        EduOrderNo = order.OrderId
                    };
                }
                else
                {
                    wxOrder = new WxPayOrder()
                    {
                        IntMsg    = -1,
                        IsSuccess = false,
                        ErrorMsg  = "请重新登陆",
                    };
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"WXPayController Pay:{ex.Message}");
                wxOrder = new WxPayOrder()
                {
                    IsSuccess = false,
                    ErrorMsg  = "支付失败,请联系客服",
                };
            }

            return(wxOrder);
        }
Пример #4
0
 public WxPayHelper(WxPayInfo wxInfo)
 {
     _wxInfo = wxInfo;
 }