Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string   orderId  = this.Request["OrderId"];
            OrderPay orderPay = bllOrder.GetOrderPay(orderId);

            if (orderPay != null && orderPay.Status == 0)
            {
                PayConfig payConfig = bllPay.GetPayConfig();
                PayString = bllPay.GetBrandWcPayRequest(orderId, orderPay.Total_Fee, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey, bllOrder.GetCurrentUserInfo().WXOpenId, this.Request.UserHostAddress, string.Format("http://{0}/Admin/DoPay/DoPayWxNotify.aspx", this.Request.Url.Host), "易劳积分充值" + orderPay.Total_Fee + "元");
            }
        }
Esempio n. 2
0
        public void BuildOrder(HttpContext context, int payType, UserInfo user)
        {
            decimal amount = Convert.ToDecimal(context.Request["amount"]);

            if (amount <= 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "金额必须大于0";
                bll.ContextResponse(context, apiResp);
                return;
            }
            string    websiteOwner = bll.WebsiteOwner;
            PayConfig payConfig    = bllPay.GetPayConfig();

            if (payType == 1 && !bllPay.IsAliPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户支付宝支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            else if (payType == 2 && !bllPay.IsJDPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户京东支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付充值";
            orderPay.Total_Fee    = amount;
            orderPay.Type         = "4";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = user.UserID;
            orderPay.PayType      = payType;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_order_id = orderPay.OrderId
            };
            bllUser.ContextResponse(context, apiResp);
        }
Esempio n. 3
0
        /// <summary>
        /// 查询付款状态
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetWeixinTransferInfo(HttpContext context)
        {
            string orderDetailId = context.Request["order_detail_id"];

            if (string.IsNullOrEmpty(orderDetailId))
            {
                resp.errcode = 1;
                resp.errmsg  = "order_detail_id 参数不能为空";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            WXMallRefund model = bllMall.GetRefundInfoByOrderDetailId(int.Parse(orderDetailId));

            ZentCloud.BLLJIMP.Model.PayConfig payConfig = bllPay.GetPayConfig();
            bool isSuccess = bllPay.GetWeixinTransferInfo(model.OrderId, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey);

            return(ZentCloud.Common.JSONHelper.ObjectToJson(new
            {
                errcode = 0,
                is_pay_success = isSuccess,
            }));
        }
Esempio n. 4
0
        public void ProcessRequest(HttpContext context)
        {
            PayConfig payConfig = bllPay.GetPayConfig();

            apiResp.result = new
            {
                is_wx_pay  = bllPay.IsWeixinPay(payConfig),
                is_ali_pay = bllPay.IsAliPay(payConfig),
                is_jd_pay  = bllPay.IsJDPay(payConfig)
            };
            apiResp.status = true;
            bllPay.ContextResponse(context, apiResp);
        }
Esempio n. 5
0
        public void ProcessRequest(HttpContext context)
        {
            string orderId = context.Request["order_id"];

            if (string.IsNullOrEmpty(orderId))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "order_id必传";
                bll.ContextResponse(context, apiResp);
                return;
            }
            OrderPay  orderPay  = bllOrder.GetOrderPay(orderId);
            PayConfig payConfig = bllPay.GetPayConfig();

            if (payConfig == null || string.IsNullOrEmpty(payConfig.WXAppId) || string.IsNullOrEmpty(payConfig.WXMCH_ID) || string.IsNullOrEmpty(payConfig.WXPartnerKey))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户微信支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }

            string appId     = payConfig.WXAppId;                                                                             //微信AppId
            string mchId     = payConfig.WXMCH_ID;                                                                            //商户号
            string key       = payConfig.WXPartnerKey;                                                                        //api密钥
            string openId    = CurrentUserInfo.WXOpenId;                                                                      //openid
            string ip        = context.Request.UserHostAddress;                                                               //ip
            string notifyUrl = string.Format("http://{0}/WxPayNotify/SmsRechargeNotify.aspx", context.Request.Url.Authority); //支付充值通知地址
            string body      = "";                                                                                            //订单内容

            string payReqStr = bllPay.GetBrandWcPayRequest(orderPay.OrderId, orderPay.Total_Fee, appId, mchId, key, openId, ip, notifyUrl, body);

            BllPay.WXPayReq payReqModel = ZentCloud.Common.JSONHelper.JsonToModel <BllPay.WXPayReq>(payReqStr);
            if (string.IsNullOrEmpty(payReqModel.paySign))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "构造支付信息失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_req = payReqModel
            };
            bll.ContextResponse(context, apiResp);
        }
Esempio n. 6
0
        private string PayConfig(HttpContext context)
        {
            PayConfig payConfig = bllPay.GetPayConfig();

            payConfig = bllPay.ConvertRequestToModel <PayConfig>(payConfig);
            if (bllPay.Update(payConfig))
            {
                resp.Status = 1;
                resp.Msg    = "提交成功";
            }
            else
            {
                resp.Status = -1;
                resp.Msg    = "提交失败";
            }
            return(Common.JSONHelper.ObjectToJson(resp));
        }
Esempio n. 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string cur_order_id = this.Request["order_id"];

            if (!bllPay.IsMobile)
            {
                errorMsg = "请用手机浏览器访问";
                return;
            }
            if (string.IsNullOrWhiteSpace(cur_order_id))
            {
                errorMsg = "订单号未找到";
                return;
            }
            orderPay = bllOrder.GetOrderPay(cur_order_id, websiteOwner: bllOrder.WebsiteOwner, payType: 1);
            if (orderPay == null)
            {
                errorMsg = "订单未找到";
                return;
            }
            if (orderPay.Status == 1)
            {
                errorMsg = "订单已经付款";
                //formString = "<div style=\"height:100%;color:red;font-size:24px;text-algin:center;\">订单已经付款</div>";
                return;
            }
            if (bllPay.IsWeiXinBrowser)
            {
                return;
            }

            try
            {
                PayConfig payConfig  = bllPay.GetPayConfig();
                string    baseUrl    = string.Format("http://{0}", this.Request.Url.Authority);
                string    notifyUrl  = baseUrl + "/Alipay/ShMemberNotifyUrl.aspx";
                string    formString = bllPay.GetAliPayRequestMobile(orderPay.OrderId, (double)orderPay.Total_Fee,
                                                                     payConfig.Seller_Account_Name, payConfig.Partner, payConfig.PartnerKey, notifyUrl);
                Response.Write(formString);
            }
            catch (Exception ex)
            {
                errorMsg = "支付页生成失败";
            }
        }
Esempio n. 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Tolog("进入支付回调");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Request.InputStream);
                xmlDoc.Save(string.Format("C:\\WXPay\\NotifyActivity{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));//写入日志

                //全部参数
                Dictionary <string, string> parametersAll = new Dictionary <string, string>();
                foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes)
                {
                    string key   = item.Name;
                    string value = item.InnerText;
                    if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value)))
                    {
                        parametersAll.Add(key, value);
                    }
                }
                parametersAll = (from entry in parametersAll
                                 orderby entry.Key ascending
                                 select entry).ToDictionary(pair => pair.Key, pair => pair.Value); //全部参数排序
                PayConfig payConfig = bllPay.GetPayConfig();
                if (!bllPay.VerifySignatureWx(parametersAll, payConfig.WXPartnerKey))              //验证签名
                {
                    Tolog("验证签名出错");
                    Response.Write(failXml);
                    return;
                }
                var orderInfo = bllMeifan.GetActivityDataByOrderId(parametersAll["out_trade_no"]);
                if (orderInfo == null)
                {
                    // Tolog("订单未找到");
                    Response.Write(failXml);
                    return;
                }
                if (orderInfo.PaymentStatus == 1)
                {
                    // Tolog("已支付");
                    Response.Write(successXml);
                    return;
                }
                //更新订单状态
                if (parametersAll["return_code"].Equals("SUCCESS") && parametersAll["result_code"].Equals("SUCCESS"))//交易成功
                {
                    //orderInfo.PaymentStatus = 1;
                    if (bllOrder.Update(orderInfo, string.Format(" PaymentStatus=1"), string.Format(" OrderId='{0}'", orderInfo.OrderId)) > 0)
                    {
                        Response.Write(successXml);
                        return;
                    }
                    else
                    {
                        Response.Write(failXml);
                        return;
                    }
                }

                Response.Write(failXml);
            }
            catch (Exception ex)
            {
                Tolog("出错了:" + ex.ToString());
                Response.Write(failXml);
            }
        }
Esempio n. 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Request.InputStream);
                try
                {
                    xmlDoc.Save(string.Format("C:\\WXPay\\Notify{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));
                }
                catch (Exception)
                {
                }
                //全部参数
                Dictionary <string, string> parametersAll = new Dictionary <string, string>();
                foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes)
                {
                    string key   = item.Name;
                    string value = item.InnerText;
                    if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value)))
                    {
                        parametersAll.Add(key, value);
                    }
                }

                parametersAll = (from entry in parametersAll
                                 orderby entry.Key ascending
                                 select entry).ToDictionary(pair => pair.Key, pair => pair.Value);//全部参数排序

                BllOrder bllOrder = new BllOrder();
                BLLJIMP.Model.OrderPay orderPay = bllOrder.GetOrderPay(parametersAll["out_trade_no"], "", bllOrder.WebsiteOwner);

                BllPay    bllPay    = new BllPay();
                PayConfig payConfig = bllPay.GetPayConfig();
                if (bllPay.VerifySignatureWx(parametersAll, payConfig.WXPartnerKey))//验证签名
                {
                    if (orderPay == null)
                    {
                        Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
                        return;
                    }

                    if (orderPay.Status == 1)
                    {
                        Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>");
                        return;
                    }
                    orderPay.Status = 1;
                    if (bllOrder.Update(orderPay))
                    {
                        BLLUser bllUser = new BLLUser();
                        if (orderPay.Type == "1")
                        {
                            int score = 0;
                            int.TryParse(orderPay.Ex1, out score);
                            BLLKeyValueData bllKeyValueData  = new BLLKeyValueData();
                            string          ScoreDispalyName = bllKeyValueData.GetDataVaule("ScoreDispalyName", "1", bllKeyValueData.WebsiteOwner);

                            string msg = "消费" + orderPay.Total_Fee + "元,充值" + score + ScoreDispalyName;
                            if (bllUser.AddUserScoreDetail(orderPay.UserId, EnumStringHelper.ToString(ScoreDefineType.Recharge), bllUser.WebsiteOwner, score, msg))
                            {
                                Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>");
                            }
                            else
                            {
                                Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
                            }
                            //BLLSystemNotice bllSystemNotice = new BLLSystemNotice();
                            //bllSystemNotice.SendNotice(BLLSystemNotice.NoticeType.SystemMessage, null, null, orderPay.UserId, msg);
                        }
                        else if (orderPay.Type == "2")
                        {
                            string invoiceMsg;
                            if (orderPay.Ex1 == "1")
                            {
                                invoiceMsg = "带发票,";
                            }
                            else
                            {
                                invoiceMsg = "无发票,";
                            }

                            string msg = "充值VIP," + invoiceMsg + "消费" + orderPay.Total_Fee.ToString() + "元";


                            BLLKeyValueData bllKeyValueData = new BLLKeyValueData();
                            string          VIPDatelong     = bllKeyValueData.GetDataVaule("VIPDatelong", "1", bllKeyValueData.WebsiteOwner);
                            if (string.IsNullOrWhiteSpace(VIPDatelong))
                            {
                                VIPDatelong = "12";
                            }
                            int datelong = Convert.ToInt32(VIPDatelong);

                            BLLUserExpand bllUserExpand = new BLLUserExpand();
                            UserExpand    userVip       = bllUserExpand.GetUserExpand(BLLJIMP.Enums.UserExpandType.UserIsVip, orderPay.UserId);
                            string        userVipEndDate;
                            if (userVip == null || DateTime.Parse(userVip.DataValue) < DateTime.Now)
                            {
                                userVipEndDate = DateTime.Now.AddMonths(datelong).ToString("yyyy-MM-dd");
                            }
                            else
                            {
                                userVipEndDate = DateTime.Parse(userVip.DataValue).AddMonths(datelong).ToString("yyyy-MM-dd");
                            }
                            bllUserExpand.UpdateUserExpand(BLLJIMP.Enums.UserExpandType.UserIsVip, orderPay.UserId, userVipEndDate);

                            //更新用户字段
                            UserScoreDetailsInfo scoreModel = new UserScoreDetailsInfo();
                            scoreModel.AddNote   = msg;
                            scoreModel.AddTime   = DateTime.Now;
                            scoreModel.Score     = 0;
                            scoreModel.UserID    = orderPay.UserId;
                            scoreModel.ScoreType = "RechargeVIP";
                            UserInfo currUser = bllUser.GetUserInfo(orderPay.UserId);
                            scoreModel.TotalScore   = currUser.TotalScore;
                            scoreModel.WebSiteOwner = currUser.WebsiteOwner;
                            if (bllUser.Add(scoreModel))
                            {
                                BLLSystemNotice bllSystemNotice = new BLLSystemNotice();
                                bllSystemNotice.SendNotice(BLLSystemNotice.NoticeType.SystemMessage, null, null, orderPay.UserId, msg);

                                Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>");
                            }
                            else
                            {
                                Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
                            }
                        }

                        return;
                    }
                    else
                    {
                        Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
                        return;
                    }
                }
                Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
            }
            catch (Exception)
            {
                Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
            }
        }
Esempio n. 10
0
        public void ProcessRequest(HttpContext context)
        {
            BLLJIMP.Model.API.User.PayUpgrade payUpgrade = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayUpgrade>(new BLLJIMP.Model.API.User.PayUpgrade());
            payUpgrade.level = CurrentUserInfo.MemberLevel;
            string websiteOwner = bll.WebsiteOwner;

            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", payUpgrade.level.ToString());

            if (levelConfig == null)
            {
                payUpgrade.userTotalAmount = 0;
            }
            else
            {
                payUpgrade.userTotalAmount = Convert.ToDecimal(levelConfig.FromHistoryScore);
            }
            UserLevelConfig toLevelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", payUpgrade.toLevel.ToString());

            if (toLevelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员等级未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (toLevelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止升级";
                bll.ContextResponse(context, apiResp);
                return;
            }
            payUpgrade.needAmount = Convert.ToDecimal(toLevelConfig.FromHistoryScore);
            payUpgrade.amount     = payUpgrade.needAmount - payUpgrade.userTotalAmount;
            if (payUpgrade.amount < 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "暂时不支持降级";
                bll.ContextResponse(context, apiResp);
                return;
            }

            if (string.IsNullOrWhiteSpace(CurrentUserInfo.WXOpenId))
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "请先绑定微信";
                bll.ContextResponse(context, apiResp);
                return;
            }
            PayConfig payConfig = bllPay.GetPayConfig();

            if (payConfig == null || string.IsNullOrEmpty(payConfig.WXAppId) || string.IsNullOrEmpty(payConfig.WXMCH_ID) || string.IsNullOrEmpty(payConfig.WXPartnerKey))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户微信支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付升级";
            orderPay.Total_Fee    = payUpgrade.amount;
            orderPay.Type         = "6";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = CurrentUserInfo.UserID;
            orderPay.Ex1          = JsonConvert.SerializeObject(payUpgrade);
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            string appId     = payConfig.WXAppId;                                                                            //微信AppId
            string mchId     = payConfig.WXMCH_ID;                                                                           //商户号
            string key       = payConfig.WXPartnerKey;                                                                       //api密钥
            string openId    = CurrentUserInfo.WXOpenId;                                                                     //openid
            string ip        = context.Request.UserHostAddress;                                                              //ip
            string notifyUrl = string.Format("http://{0}/WxPayNotify/PayUpgradeNotify.aspx", context.Request.Url.Authority); //支付升级通知地址
            string body      = "";                                                                                           //订单内容

            string payReqStr = bllPay.GetBrandWcPayRequest(orderPay.OrderId, orderPay.Total_Fee, appId, mchId, key, openId, ip, notifyUrl, body);

            BllPay.WXPayReq payReqModel = ZentCloud.Common.JSONHelper.JsonToModel <BllPay.WXPayReq>(payReqStr);
            if (string.IsNullOrEmpty(payReqModel.paySign))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "构造支付信息失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_req = payReqModel
            };
            bllUser.ContextResponse(context, apiResp);
        }
Esempio n. 11
0
        public void ProcessRequest(HttpContext context)
        {
            string  scoreStr = context.Request["score"];
            decimal score    = Convert.ToDecimal(scoreStr);

            if (score == 0)
            {
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "积分不能为0";
                bllKeyValueData.ContextResponse(context, apiResp);
                return;
            }
            if (CurrentUserInfo == null)
            {
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.UserIsNotLogin;
                apiResp.msg  = "您还没有登录";
                bllKeyValueData.ContextResponse(context, apiResp);
                return;
            }
            BllOrder  bllOrder  = new BllOrder();
            BllPay    bllPay    = new BllPay();
            PayConfig payConfig = bllPay.GetPayConfig();

            string  rechargeValue = bllKeyValueData.GetDataVaule("Recharge", "100", bllKeyValueData.WebsiteOwner);
            decimal rechargeFee   = Convert.ToDecimal(rechargeValue);
            decimal totalFee      = rechargeFee / 100 * score;

            string websiteOwner = bllKeyValueData.WebsiteOwner;

            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bllOrder.GetGUID(TransacType.CommAdd);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Status       = 0;
            orderPay.Type         = "1";
            orderPay.Subject      = "积分充值";
            orderPay.Total_Fee    = totalFee;
            orderPay.UserId       = CurrentUserInfo.UserID;
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.Ex1          = scoreStr;

            var non_str = Payment.WeiXin.CommonUtil.CreateNoncestr();//随机串
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("appid", payConfig.WXAppId);
            dic.Add("body", "订单" + orderPay.OrderId);
            dic.Add("mch_id", payConfig.WXMCH_ID);//商户号
            dic.Add("nonce_str", non_str);
            dic.Add("out_trade_no", orderPay.OrderId);
            dic.Add("spbill_create_ip", context.Request.UserHostAddress);
            dic.Add("total_fee", (totalFee * 100).ToString("F0"));
            dic.Add("notify_url", string.Format("http://{0}/WxPayNotify/DoPayWxNotify.aspx", context.Request.Url.Authority));
            dic.Add("trade_type", "NATIVE");
            dic.Add("product_id", orderPay.OrderId);
            string strtemp = Payment.WeiXin.CommonUtil.FormatBizQueryParaMap(dic, false);
            string sign    = Payment.WeiXin.MD5SignUtil.Sign(strtemp, payConfig.WXPartnerKey);

            dic = (from entry in dic
                   orderby entry.Key ascending
                   select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
            dic.Add("sign", sign);

            string postData = Payment.WeiXin.CommonUtil.ArrayToXml(dic);
            string url      = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
            byte[] requestBytes           = System.Text.Encoding.UTF8.GetBytes(postData);
            req.Method        = "POST";
            req.ContentType   = "application/x-www-form-urlencoded";
            req.ContentLength = requestBytes.Length;
            Stream requestStream = req.GetRequestStream();

            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();

            System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
            StreamReader sr      = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
            string       backStr = sr.ReadToEnd();

            sr.Close();
            res.Close();
            var result      = System.Xml.Linq.XDocument.Parse(backStr);
            var return_code = result.Element("xml").Element("return_code").Value;

            if (!return_code.ToUpper().Equals("SUCCESS"))
            {
                apiResp.code   = (int)BLLJIMP.Enums.APIErrCode.OperateFail;
                apiResp.msg    = "预支付失败";
                apiResp.result = new
                {
                    return_msg = result.Element("xml").Element("return_msg").Value,
                    post_data  = postData
                };
                bllKeyValueData.ContextResponse(context, apiResp);
                return;
            }

            var rusult_code = result.Element("xml").Element("result_code").Value;

            if (return_code.ToUpper().Equals("SUCCESS") && (rusult_code.ToUpper().Equals("SUCCESS")))
            {
                var prepay_id = result.Element("xml").Element("prepay_id").Value;
                var code_url  = result.Element("xml").Element("code_url").Value;
                orderPay.Trade_No = prepay_id;
                bllOrder.Add(orderPay);

                apiResp.code   = (int)BLLJIMP.Enums.APIErrCode.IsSuccess;
                apiResp.msg    = "预支付完成";
                apiResp.status = true;
                apiResp.result = new
                {
                    orderId   = orderPay.OrderId,
                    prepay_id = prepay_id,
                    code_url  = code_url
                };
            }
            else
            {
                apiResp.code   = (int)BLLJIMP.Enums.APIErrCode.OperateFail;
                apiResp.result = result.Element("xml").Element("err_code_des").Value;
                apiResp.msg    = "预支付失败";
            }
            bllKeyValueData.ContextResponse(context, apiResp);
        }
Esempio n. 12
0
        public void BuildOrder(HttpContext context, int payType)
        {
            BLLJIMP.Model.API.User.PayRegisterUser requestUser = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayRegisterUser>(new BLLJIMP.Model.API.User.PayRegisterUser());
            string websiteOwner = bll.WebsiteOwner;

            if (string.IsNullOrWhiteSpace(requestUser.level.ToString()))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请选择会员级别";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.spreadid))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入推荐人编号";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入手机号码";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.PhoneNumLogicJudge(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "手机号码格式不正确";
                bll.ContextResponse(context, apiResp);
                return;
            }

            if (!ZentCloud.Common.MyRegex.IsIDCard(requestUser.idcard))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "身份证号码必须如实填写";
                bll.ContextResponse(context, apiResp);
                return;
            }
            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUser.level.ToString());

            if (levelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (levelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止注册";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.levelname = levelConfig.LevelString;
            UserInfo spreadUser = bllUser.GetSpreadUser(requestUser.spreadid, websiteOwner);

            if (spreadUser == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "推荐人未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.spreadid = spreadUser.UserID; //推荐人
            UserInfo oldUserInfo = bllUser.GetUserInfoByPhone(requestUser.phone, websiteOwner);

            if (oldUserInfo != null && oldUserInfo.MemberLevel > 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该手机已注册会员";
                bll.ContextResponse(context, apiResp);
                return;
            }

            PayConfig payConfig = bllPay.GetPayConfig();

            if (payType == 1 && !bllPay.IsAliPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户支付宝支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            else if (payType == 2 && !bllPay.IsJDPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户京东支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (oldUserInfo != null)
            {
                requestUser.userid = oldUserInfo.UserID;
            }
            else
            {
                requestUser.userid = string.Format("ZYUser{0}{1}", DateTime.Now.ToString("yyyyMMdd"), Guid.NewGuid().ToString("N").ToUpper());
            }
            requestUser.regIP    = context.Request.UserHostAddress;//ip
            requestUser.password = ZentCloud.Common.Rand.Number(6);

            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付注册会员";
            orderPay.Total_Fee    = Convert.ToDecimal(levelConfig.FromHistoryScore);
            orderPay.Type         = "5";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = requestUser.userid;
            orderPay.Ex1          = JsonConvert.SerializeObject(requestUser);
            orderPay.Ex2          = requestUser.phone;
            orderPay.PayType      = payType;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_order_id = orderPay.OrderId
            };
            bllUser.ContextResponse(context, apiResp);
        }
Esempio n. 13
0
        public void BuildOrder(HttpContext context, int payType, UserInfo user)
        {
            BLLJIMP.Model.API.User.PayUpgrade payUpgrade = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayUpgrade>(new BLLJIMP.Model.API.User.PayUpgrade());
            payUpgrade.level = user.MemberLevel;
            string websiteOwner = bll.WebsiteOwner;

            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", payUpgrade.level.ToString());

            if (levelConfig == null)
            {
                payUpgrade.userTotalAmount = 0;
            }
            else
            {
                payUpgrade.userTotalAmount = Convert.ToDecimal(levelConfig.FromHistoryScore);
            }
            UserLevelConfig toLevelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", payUpgrade.toLevel.ToString());

            if (toLevelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员等级未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (toLevelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止升级";
                bll.ContextResponse(context, apiResp);
                return;
            }
            payUpgrade.needAmount = Convert.ToDecimal(toLevelConfig.FromHistoryScore);
            payUpgrade.amount     = payUpgrade.needAmount - payUpgrade.userTotalAmount;
            if (payUpgrade.amount < 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "暂时不支持降级";
                bll.ContextResponse(context, apiResp);
                return;
            }
            PayConfig payConfig = bllPay.GetPayConfig();

            if (payType == 1 && !bllPay.IsAliPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户支付宝支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            else if (payType == 2 && !bllPay.IsJDPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户京东支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付升级";
            orderPay.Total_Fee    = payUpgrade.amount;
            orderPay.Type         = "6";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = user.UserID;
            orderPay.Ex1          = JsonConvert.SerializeObject(payUpgrade);
            orderPay.PayType      = payType;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                user_id      = user.AutoID,
                pay_order_id = orderPay.OrderId
            };
            bllUser.ContextResponse(context, apiResp);
        }
Esempio n. 14
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                Tolog("京东支付通知start");
                PayConfig payConfig = bllPay.GetPayConfig();
                byte[]    byts      = new byte[context.Request.InputStream.Length];
                context.Request.InputStream.Read(byts, 0, byts.Length);
                string req = Encoding.UTF8.GetString(byts);
                Tolog("通知参数" + req);
                //string req = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><jdpay><version>V2.0</version><merchant>110226843002</merchant><result><code>000000</code><desc>success</desc></result><encrypt>NDdmNmZkNjQwNzBiYzEzMmE5N2ExMTg3YjkxNmQ4NzkxYzQyMmFjZjM4YTM1MjZjY2JjNzM1ZDkxY2Q5ZDNmMTMzMGFjYTBkNTI0MzYzNjc3MTVhODI3OWUzZTAxMmY5ODEyOTVmNDNiNWY5MDZhZGJiYTcwYTYyOTFlYzVmYTU2Y2EyN2U1YzhkNzllMGE3ZTUyNDE4NWU4OWMxNjIwNDFkODcyYzJiZDA4ZWY4YWEyMmY5ZWUxNDk3YTg3MTI3YmU1NTMxNjc5NWJiOTlmN2ZmNGU1MTc1YWJhNjNkYjUzYWUwZDQzOTk4ZjIzMjBiYmVkNGJkMDcxOWUzOThjZjU1ODUwNz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DIzNTBlODlmNDNlZGE5NTUyYjJmMmRjNjU0MTNlZjYxZTNlODc4MDk3MmNiYjg3NTVjNmU1NWNlZDljNWU0ZDE5ZTRmZjJjZTAxNmJiMGIzYWFlOTdlYTQzYmM5NWVmMGU0ZjUyNzY4NDNlZGE5NTUyYjJmMmRjNmMyOWRiYWZkYTNjYzQ1M2E3ZGJhZWNjZWJmNGIxZmQ5MTMxMmRiMzliOTU2YzBmNmNiODMxMDQ1ZDBiYjM1ZTNmMzlmMGE0ODNiN2M3ODYyZjNjMTFiN2ZiODljNDNkMjE4NGFlNzU5M2JhMmQ2YTJkOWMwMmYxYTBlNTg2MzhkYzU0NzE0NjExNzkyNGU4ZjQ4NDgzMTAyNDY5OGRlNGZiMDVmNGQzNzE3NGMwOGI2NGU2NjkxMmU2NGY5M2I0YjNiMThmMzZiZmY0NTgwN2FjMDAxOWRlY2ZkYTcyOGFmNzIyZTQwNjhlMTViM2UwMmQzMmRiYjJkOTE2MmQzNWMzZWM2OGRkZjJjMjdmOTRhZGNmYzEzOTdlOWY0NjQwODFiYWU0Y2E3Y2NjZDY0NjQzNGFmZWU4ODExYWRiZTBlY2MwY2JlOThmNDliMDZkYjE2YjNjNTZhOTRiOGZkMDU=</encrypt></jdpay>";

                //req = Regex.Replace(req, @"[\t\n\r]", "", RegexOptions.IgnoreCase);

                req = req.Replace("\r", "").Replace("\n", "").Replace("\t", "");

                AsynNotifyResponse anyResponse = Payment.JDPay.XMLUtil.decryptResXml <AsynNotifyResponse>(Payment.JDPay.Config.JDPubKey, payConfig.JDPayDESKey, req);
                // System.Diagnostics.Debug.WriteLine("异步通知订单号:" + anyResponse.tradeNum + ",状态:" + anyResponse.status);
                Tolog("异步通知订单号:" + anyResponse.tradeNum + ",状态:" + anyResponse.status);
                string   orderId   = anyResponse.tradeNum;
                OrderPay orderInfo = bllOrder.GetOrderPay(orderId, payType: 2);
                if (orderInfo == null)
                {
                    //context.Response.Write("订单未找到");
                    context.Response.StatusCode = 500;
                    context.Response.Write(failStr);
                    return;
                }
                if (orderInfo.Status.Equals(1))
                {
                    //Tolog("已支付");
                    // context.Response.Write("订单已支付");
                    context.Response.StatusCode = 200;
                    context.Response.Write(successStr);
                    return;
                }

                if (anyResponse.status == "2")
                {
                    //京东支付未返回流水号
                    bool result = false;
                    Alipay.ShMemberNotifyUrl shNotify = new Alipay.ShMemberNotifyUrl();
                    if (orderInfo.Type == "4")
                    {
                        result = shNotify.PayRecharge(orderInfo, "");
                    }
                    else if (orderInfo.Type == "5")
                    {
                        result = shNotify.PayRegister(orderInfo, "");
                    }
                    else if (orderInfo.Type == "6")
                    {
                        result = shNotify.PayUpgrade(orderInfo, "");
                    }
                    if (result)
                    {
                        context.Response.StatusCode = 200;
                        context.Response.Write(successStr);
                        Tolog("支付成功" + orderInfo.OrderId);
                        return;
                    }
                    else
                    {
                        context.Response.StatusCode = 500;
                        context.Response.Write(failStr);
                        Tolog("支付失败");
                        return;
                    }
                }
                else
                {
                    context.Response.StatusCode = 500;
                    context.Response.Write(failStr);
                    return;
                }
            }
            catch (Exception ex)
            {
                //error = "fail";
                Tolog("京东支付异常:" + ex.ToString());
            }

            context.Response.ContentType = "text/plain";
            context.Response.StatusCode  = 500;
            context.Response.Write(failStr);
        }
Esempio n. 15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Tolog("进入支付回调");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Request.InputStream);
                //xmlDoc.Load(@"D:\PayRegisterNotify20170613203329981.xml");
                xmlDoc.Save(string.Format("C:\\WXPay\\PayRegisterNotify{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));//写入日志

                //全部参数
                Dictionary <string, string> parametersAll = new Dictionary <string, string>();
                foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes)
                {
                    string key   = item.Name;
                    string value = item.InnerText;
                    if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value)))
                    {
                        parametersAll.Add(key, value);
                    }
                }
                parametersAll = (from entry in parametersAll
                                 orderby entry.Key ascending
                                 select entry).ToDictionary(pair => pair.Key, pair => pair.Value); //全部参数排序
                PayConfig payConfig = bllPay.GetPayConfig();
                if (!bllPay.VerifySignatureWx(parametersAll, payConfig.WXPartnerKey))              //验证签名
                {
                    Tolog("验证签名出错");
                    Response.Write(failXml);
                    return;
                }
                OrderPay orderPay = bllOrder.GetOrderPay(parametersAll["out_trade_no"]);
                if (orderPay == null)
                {
                    Tolog("订单未找到");
                    Response.Write(failXml);
                    return;
                }
                if (orderPay.Status.Equals(1))
                {
                    Tolog("已支付");
                    Response.Write(successXml);
                    return;
                }
                BLLJIMP.Model.API.User.PayRegisterUser requestUser = JsonConvert.DeserializeObject <BLLJIMP.Model.API.User.PayRegisterUser>(orderPay.Ex1);
                UserLevelConfig levelConfig = bll.QueryUserLevel(orderPay.WebsiteOwner, "DistributionOnLine", requestUser.level.ToString());
                if (levelConfig == null)
                {
                    Tolog("会员等级未找到");
                    Response.Write(failXml);
                    return;
                }
                //更新订单状态
                if (parametersAll["return_code"].Equals("SUCCESS") && parametersAll["result_code"].Equals("SUCCESS"))//交易成功
                {
                    UserInfo regUser = bllUser.GetUserInfoByPhone(requestUser.phone, orderPay.WebsiteOwner);
                    if (regUser != null && regUser.MemberLevel >= 10)
                    {
                        Tolog("该手机已注册会员");
                        Response.Write(failXml);
                        return;
                    }
                    if (regUser != null && regUser.MemberLevel > requestUser.level)
                    {
                        Tolog("该会员有更高级别");
                        Response.Write(failXml);
                        return;
                    }
                    if (regUser != null)
                    {
                        regUser.UserType          = 2;
                        regUser.TrueName          = requestUser.truename;
                        regUser.DistributionOwner = requestUser.spreadid;
                        regUser.MemberLevel       = requestUser.level;
                        regUser.MemberStartTime   = DateTime.Now;
                        regUser.MemberApplyTime   = orderPay.InsertDate;
                        regUser.RegIP             = requestUser.regIP;
                        regUser.Password          = requestUser.password;
                        regUser.MemberApplyStatus = 9;
                        regUser.IdentityCard      = requestUser.idcard;
                        regUser.Province          = requestUser.province;
                        regUser.City         = requestUser.city;
                        regUser.District     = requestUser.district;
                        regUser.Town         = requestUser.town;
                        regUser.ProvinceCode = requestUser.provinceCode;
                        regUser.CityCode     = requestUser.cityCode;
                        regUser.DistrictCode = requestUser.districtCode;
                        regUser.TownCode     = requestUser.townCode;
                        regUser.RegUserID    = null;
                        regUser.RegisterWay  = "线上";
                        regUser.IsDisable    = 0;
                        regUser.RegUserID    = null;
                    }
                    else
                    {
                        regUser                   = new UserInfo();
                        regUser.UserID            = requestUser.userid;
                        regUser.UserType          = 2;
                        regUser.TrueName          = requestUser.truename;
                        regUser.WebsiteOwner      = orderPay.WebsiteOwner;
                        regUser.DistributionOwner = requestUser.spreadid;
                        regUser.Phone             = requestUser.phone;
                        regUser.MemberLevel       = requestUser.level;
                        regUser.MemberStartTime   = DateTime.Now;
                        regUser.MemberApplyTime   = orderPay.InsertDate;
                        regUser.Regtime           = DateTime.Now;
                        regUser.LastLoginDate     = DateTime.Parse("1970-01-01");
                        regUser.RegIP             = requestUser.regIP;
                        regUser.Password          = requestUser.password;
                        regUser.MemberApplyStatus = 9;
                        regUser.IdentityCard      = requestUser.idcard;
                        regUser.Province          = requestUser.province;
                        regUser.City              = requestUser.city;
                        regUser.District          = requestUser.district;
                        regUser.Town              = requestUser.town;
                        regUser.ProvinceCode      = requestUser.provinceCode;
                        regUser.CityCode          = requestUser.cityCode;
                        regUser.DistrictCode      = requestUser.districtCode;
                        regUser.TownCode          = requestUser.townCode;
                        regUser.RegisterWay       = "线上";
                        regUser.IsDisable         = 0;
                        regUser.RegUserID         = null;
                    }
                    string msg = "";
                    orderPay.Trade_No = parametersAll["transaction_id"];
                    //线上注册分佣
                    if (!bll.PayRegisterTransfers(regUser, orderPay, parametersAll["openid"], parametersAll["transaction_id"], levelConfig, out msg))
                    {
                        Tolog(msg);
                        Response.Write(failXml);
                        return;
                    }
                    //发送优惠券
                    if (!string.IsNullOrEmpty(levelConfig.CouponId))
                    {
                        BLLCardCoupon bllCardCoupon = new BLLCardCoupon();
                        bllCardCoupon.SendCardCouponsByCurrUserInfo(regUser, levelConfig.CouponId);
                    }

                    Response.Write(successXml);
                    return;
                }
                Tolog("返回信息有误");
                Response.Write(failXml);
            }
            catch (Exception ex)
            {
                Tolog("出错了:" + ex.ToString());
                Response.Write(failXml);
            }
        }
Esempio n. 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Tolog("进入支付回调");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Request.InputStream);
                xmlDoc.Save(string.Format("C:\\WXPay\\PayUpgradeNotify{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));//写入日志

                //全部参数
                Dictionary <string, string> parametersAll = new Dictionary <string, string>();
                foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes)
                {
                    string key   = item.Name;
                    string value = item.InnerText;
                    if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value)))
                    {
                        parametersAll.Add(key, value);
                    }
                }
                parametersAll = (from entry in parametersAll
                                 orderby entry.Key ascending
                                 select entry).ToDictionary(pair => pair.Key, pair => pair.Value); //全部参数排序
                PayConfig payConfig = bllPay.GetPayConfig();
                if (!bllPay.VerifySignatureWx(parametersAll, payConfig.WXPartnerKey))              //验证签名
                {
                    Tolog("验证签名出错");
                    Response.Write(failXml);
                    return;
                }
                OrderPay orderPay = bllOrder.GetOrderPay(parametersAll["out_trade_no"]);
                if (orderPay == null)
                {
                    Tolog("订单未找到");
                    Response.Write(failXml);
                    return;
                }
                if (orderPay.Status.Equals(1))
                {
                    Tolog("已支付");
                    Response.Write(successXml);
                    return;
                }
                BLLJIMP.Model.API.User.PayUpgrade payUpgrade = JsonConvert.DeserializeObject <BLLJIMP.Model.API.User.PayUpgrade>(orderPay.Ex1);
                //更新订单状态
                if (parametersAll["return_code"].Equals("SUCCESS") && parametersAll["result_code"].Equals("SUCCESS"))//交易成功
                {
                    string msg = "";
                    orderPay.Trade_No = parametersAll["transaction_id"];
                    UserLevelConfig levelConfig = bll.QueryUserLevel(orderPay.WebsiteOwner, "DistributionOnLine", payUpgrade.toLevel.ToString());
                    UserInfo        payUser     = bllUser.GetUserInfo(orderPay.UserId, orderPay.WebsiteOwner);
                    if (!string.IsNullOrEmpty(levelConfig.CouponId))
                    {
                        BLLCardCoupon bllCardCoupon = new BLLCardCoupon();
                        bllCardCoupon.SendCardCouponsByCurrUserInfo(payUser, levelConfig.CouponId);
                    }
                    //支付升级分佣
                    if (!bll.PayUpgradeTransfers(orderPay, payUpgrade, parametersAll["openid"], parametersAll["transaction_id"], out msg))
                    {
                        Tolog(msg);
                        Response.Write(failXml);
                        return;
                    }

                    Response.Write(successXml);
                    return;
                }
                Tolog("返回信息有误");
                Response.Write(failXml);
            }
            catch (Exception ex)
            {
                Tolog("出错了:" + ex.Message);
                Response.Write(failXml);
            }
        }
Esempio n. 17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BllPay bllPay = new BllPay();

            payConfig = bllPay.GetPayConfig();
        }
Esempio n. 18
0
        /// <summary>
        /// 微信支付
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string BrandWcPayRequest(HttpContext context)
        {
            if (!bllPay.IsWeiXinBrowser)
            {
                resp.errcode = 1;
                resp.errmsg  = "请在微信中打开";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            string  orderId     = context.Request["order_id"];
            decimal totalAmount = 0;                                      //订单金额
            string  appId       = "";                                     //微信AppId
            string  mchId       = "";                                     //商户号
            string  key         = "";                                     //api密钥
            string  openId      = "";                                     //openid
            string  ip          = "";                                     //ip
            string  notifyUrl   = baseUrl + "/WxPayNotify/NotifyV2.aspx"; //支付通知地址
            string  body        = "";                                     //订单内容

            if (string.IsNullOrEmpty(orderId))
            {
                resp.errcode = 1;
                resp.errmsg  = "order_id 必传";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            var orderInfo = bllMall.GetOrderInfo(orderId);

            if (orderInfo != null)
            {
                totalAmount = orderInfo.TotalAmount;
                //if (orderInfo.OrderUserID != CurrentUserInfo.UserID)
                //{
                //    resp.errcode = 1;
                //    resp.errmsg = "订单号无效";
                //    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
                //}
                if (orderInfo.PaymentStatus == 1)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "该订单已经支付,不需重复支付";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }

                //更改支付方式
                bllMall.Update(orderInfo, " PaymentType=2 ", string.Format(" (OrderID = '{0}' Or ParentOrderId='{0}') ", orderInfo.OrderID));

                //resp.errcode = 1;
                //resp.errmsg = "订单号不存在";
                //return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }
            else
            {
                #region 众筹
                var orderInfoCrowd = bllMall.Get <CrowdFundRecord>(string.Format(" RecordID={0}", orderId));
                if (orderInfoCrowd == null)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "订单号不存在";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (orderInfoCrowd.UserID != currentUserInfo.UserID)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "订单号无效";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (orderInfoCrowd.Status == 1)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "订单已经支付,不需重复支付";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                totalAmount = orderInfoCrowd.Amount;
                notifyUrl   = baseUrl + "/WxPayNotify/NotifyCrowdFundV2.aspx";
                #endregion
            }

            PayConfig payConfig = bllPay.GetPayConfig();
            if (payConfig == null)
            {
                resp.errcode = 1;
                resp.errmsg  = "该商户微信支付还没有配置";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            if ((string.IsNullOrEmpty(payConfig.WXAppId)) || (string.IsNullOrEmpty(payConfig.WXMCH_ID)) || (string.IsNullOrEmpty(payConfig.WXPartnerKey)))
            {
                resp.errcode = 1;
                resp.errmsg  = "该商户微信支付还没有配置";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            appId  = payConfig.WXAppId;
            mchId  = payConfig.WXMCH_ID;
            key    = payConfig.WXPartnerKey;
            openId = currentUserInfo.WXOpenId;
            ip     = context.Request.UserHostAddress;
            string   payReqStr   = bllPay.GetBrandWcPayRequest(orderId, totalAmount, appId, mchId, key, openId, ip, notifyUrl, body);
            WXPayReq payReqModel = ZentCloud.Common.JSONHelper.JsonToModel <WXPayReq>(payReqStr);
            if (!string.IsNullOrEmpty(payReqModel.paySign))
            {
                return(ZentCloud.Common.JSONHelper.ObjectToJson(new
                {
                    errcode = 0,
                    pay_req = payReqModel
                }));
            }
            resp.errcode = 1;
            resp.errmsg  = "获取配置失败";
            return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
Esempio n. 19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Dictionary <string, string> parametersAll = bllPay.GetRequestParameter();
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(parametersAll["notify_data"]);
                xmlDoc.Save(string.Format("C:\\Alipay\\mallnotify{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));
                //商户订单号
                string outTradeNo = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText;
                //支付宝交易号
                string tradeNo = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText;
                //交易状态
                string   tradeStatus  = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText;
                string   websiteOwner = bllOrder.WebsiteOwner;
                OrderPay orderPay     = bllOrder.GetOrderPay(outTradeNo, "", websiteOwner);
                if (parametersAll.Count > 0)//判断是否有带返回参数
                {
                    Notify    aliNotify    = new Notify();
                    PayConfig payConfig    = bllPay.GetPayConfig();
                    bool      verifyResult = aliNotify.VerifyNotifyMall(parametersAll, Request.Form["sign"], payConfig.Partner, payConfig.PartnerKey);
                    if (verifyResult)//验证成功
                    {
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        //请在这里加上商户的业务逻辑程序代码

                        //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                        //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                        //解密(如果是RSA签名需要解密,如果是MD5签名则下面一行清注释掉)
                        //sPara = aliNotify.Decrypt(sPara);

                        //XML解析notify_data数据
                        if (tradeStatus == "TRADE_FINISHED")
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序

                            //注意:
                            //该种交易状态只在两种情况下出现
                            //1、开通了普通即时到账,买家付款成功后。
                            //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。

                            if (orderPay.Status.Equals(0))//只有未付款状态
                            {
                                bool result = false;
                                if (orderPay.Type == "4")
                                {
                                    result = PayRecharge(orderPay, tradeNo);
                                }
                                else if (orderPay.Type == "5")
                                {
                                    result = PayRegister(orderPay, tradeNo);
                                }
                                else if (orderPay.Type == "6")
                                {
                                    result = PayUpgrade(orderPay, tradeNo);
                                }
                                if (result)
                                {
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("fail");
                                }
                            }
                            else
                            {
                                Response.Write("success");  //请不要修改或删除
                            }
                        }
                        else if (tradeStatus == "TRADE_SUCCESS")
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序

                            //注意:
                            //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。


                            if (orderPay.Status.Equals(0))//只有未付款状态
                            {
                                bool result = false;
                                if (orderPay.Type == "4")
                                {
                                    result = PayRecharge(orderPay, tradeNo);
                                }
                                else if (orderPay.Type == "5")
                                {
                                    result = PayRegister(orderPay, tradeNo);
                                }
                                else if (orderPay.Type == "6")
                                {
                                    result = PayUpgrade(orderPay, tradeNo);
                                }
                                if (result)
                                {
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("fail");
                                }
                            }
                            else
                            {
                                Response.Write("success");  //请不要修改或删除
                            }
                        }
                        else
                        {
                            Response.Write(tradeStatus);
                        }
                        //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    }
                    else//验证失败
                    {
                        Response.Write("fail");
                    }
                }
                else
                {
                    Response.Write("无通知参数");
                }
            }
            catch (Exception)
            {
                Response.Write("fail");
            }
        }
Esempio n. 20
0
        public void ProcessRequest(HttpContext context)
        {
            decimal amount = Convert.ToDecimal(context.Request["amount"]);

            if (amount <= 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "金额必须大于0";
                bll.ContextResponse(context, apiResp);
                return;
            }
            string websiteOwner = bll.WebsiteOwner;

            if (string.IsNullOrWhiteSpace(CurrentUserInfo.WXOpenId))
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "请先绑定微信";
                bll.ContextResponse(context, apiResp);
                return;
            }
            PayConfig payConfig = bllPay.GetPayConfig();

            if (payConfig == null || string.IsNullOrEmpty(payConfig.WXAppId) || string.IsNullOrEmpty(payConfig.WXMCH_ID) || string.IsNullOrEmpty(payConfig.WXPartnerKey))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户微信支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付充值";
            orderPay.Total_Fee    = amount;
            orderPay.Type         = "4";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = CurrentUserInfo.UserID;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            string appId     = payConfig.WXAppId;                                                                             //微信AppId
            string mchId     = payConfig.WXMCH_ID;                                                                            //商户号
            string key       = payConfig.WXPartnerKey;                                                                        //api密钥
            string openId    = CurrentUserInfo.WXOpenId;                                                                      //openid
            string ip        = context.Request.UserHostAddress;                                                               //ip
            string notifyUrl = string.Format("http://{0}/WxPayNotify/PayRechargeNotify.aspx", context.Request.Url.Authority); //支付充值通知地址
            string body      = "";                                                                                            //订单内容

            string payReqStr = bllPay.GetBrandWcPayRequest(orderPay.OrderId, orderPay.Total_Fee, appId, mchId, key, openId, ip, notifyUrl, body);

            BllPay.WXPayReq payReqModel = ZentCloud.Common.JSONHelper.JsonToModel <BllPay.WXPayReq>(payReqStr);
            if (string.IsNullOrEmpty(payReqModel.paySign))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "构造支付信息失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_req = payReqModel
            };
            bllUser.ContextResponse(context, apiResp);
        }
Esempio n. 21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Tolog("进入支付回调");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Request.InputStream);
                xmlDoc.Save(string.Format("C:\\WXPay\\PayRechargeNotify{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));//写入日志

                //全部参数
                Dictionary <string, string> parametersAll = new Dictionary <string, string>();
                foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes)
                {
                    string key   = item.Name;
                    string value = item.InnerText;
                    if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value)))
                    {
                        parametersAll.Add(key, value);
                    }
                }
                parametersAll = (from entry in parametersAll
                                 orderby entry.Key ascending
                                 select entry).ToDictionary(pair => pair.Key, pair => pair.Value); //全部参数排序
                PayConfig payConfig = bllPay.GetPayConfig();
                if (!bllPay.VerifySignatureWx(parametersAll, payConfig.WXPartnerKey))              //验证签名
                {
                    Tolog("验证签名出错");
                    Response.Write(failXml);
                    return;
                }
                OrderPay orderPay = bllOrder.GetOrderPay(parametersAll["out_trade_no"]);
                if (orderPay == null)
                {
                    Tolog("订单未找到");
                    Response.Write(failXml);
                    return;
                }
                if (orderPay.Status.Equals(1))
                {
                    Tolog("已支付");
                    Response.Write(successXml);
                    return;
                }
                //更新订单状态
                if (parametersAll["return_code"].Equals("SUCCESS") && parametersAll["result_code"].Equals("SUCCESS"))//交易成功
                {
                    string msg = "";
                    orderPay.Trade_No = parametersAll["transaction_id"];
                    if (!bll.PayRechargeTransfers(orderPay, parametersAll["openid"], parametersAll["transaction_id"], out msg))
                    {
                        Tolog(msg);
                        Response.Write(failXml);
                        return;
                    }
                    Response.Write(successXml);
                    return;
                }
                Tolog("返回信息有误");
                Response.Write(failXml);
            }
            catch (Exception ex)
            {
                Tolog("出错了:" + ex.Message);
                Response.Write(failXml);
            }
        }
Esempio n. 22
0
        public void ProcessRequest(HttpContext context)
        {
            BLLJIMP.Model.API.User.PayRegisterUser requestUser = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayRegisterUser>(new BLLJIMP.Model.API.User.PayRegisterUser());
            string websiteOwner = bll.WebsiteOwner;

            if (context.Session["currWXOpenId"] == null)
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "仅支持微信注册";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.spreadid))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入推荐人编号";
                bll.ContextResponse(context, apiResp);
                return;
            }
            string currWXOpenId = context.Session["currWXOpenId"].ToString();

            if (string.IsNullOrWhiteSpace(requestUser.level.ToString()))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请选择会员级别";
                bll.ContextResponse(context, apiResp);
                return;
            }

            if (string.IsNullOrWhiteSpace(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入手机号码";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.PhoneNumLogicJudge(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "手机号码格式不正确";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.IsIDCard(requestUser.idcard))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "身份证号码必须如实填写";
                bll.ContextResponse(context, apiResp);
                return;
            }
            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUser.level.ToString());

            if (levelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (levelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止注册";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.levelname = levelConfig.LevelString;
            UserInfo spreadUser = spreadUser = bllUser.GetSpreadUser(requestUser.spreadid, websiteOwner);

            if (spreadUser == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "推荐人未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.spreadid = spreadUser.UserID; //推荐人
            UserInfo oldUserInfo = bllUser.GetUserInfoByPhone(requestUser.phone, websiteOwner);

            if (oldUserInfo != null && oldUserInfo.MemberLevel >= 10)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该手机已注册会员";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (oldUserInfo != null && oldUserInfo.MemberLevel > requestUser.level)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该会员有更高级别";
                bll.ContextResponse(context, apiResp);
                return;
            }

            PayConfig payConfig = bllPay.GetPayConfig();

            if (payConfig == null || string.IsNullOrEmpty(payConfig.WXAppId) || string.IsNullOrEmpty(payConfig.WXMCH_ID) || string.IsNullOrEmpty(payConfig.WXPartnerKey))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户微信支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (oldUserInfo != null)
            {
                requestUser.userid = oldUserInfo.UserID;
            }
            else
            {
                requestUser.userid = string.Format("ZYUser{0}{1}", DateTime.Now.ToString("yyyyMMdd"), Guid.NewGuid().ToString("N").ToUpper());
            }
            requestUser.regIP    = context.Request.UserHostAddress;//ip
            requestUser.password = ZentCloud.Common.Rand.Number(6);

            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付注册会员";
            orderPay.Total_Fee    = Convert.ToDecimal(levelConfig.FromHistoryScore);
            orderPay.Type         = "5";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = requestUser.userid;
            orderPay.Ex1          = JsonConvert.SerializeObject(requestUser);
            orderPay.Ex2          = requestUser.phone;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            string appId     = payConfig.WXAppId;                                                                             //微信AppId
            string mchId     = payConfig.WXMCH_ID;                                                                            //商户号
            string key       = payConfig.WXPartnerKey;                                                                        //api密钥
            string openId    = currWXOpenId;                                                                                  //openid
            string notifyUrl = string.Format("http://{0}/WxPayNotify/PayRegisterNotify.aspx", context.Request.Url.Authority); //支付注册通知地址
            string body      = "";                                                                                            //订单内容

            string payReqStr = bllPay.GetBrandWcPayRequest(orderPay.OrderId, orderPay.Total_Fee, appId, mchId, key, openId, requestUser.regIP, notifyUrl, body);

            BllPay.WXPayReq payReqModel = ZentCloud.Common.JSONHelper.JsonToModel <BllPay.WXPayReq>(payReqStr);
            if (string.IsNullOrEmpty(payReqModel.paySign))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "构造支付信息失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_req = payReqModel
            };
            bllUser.ContextResponse(context, apiResp);
        }