Exemplo n.º 1
0
        /// <summary>
        /// 验证支付成功后台服务通知
        /// 创建用户:shiyuankao
        /// 创建时间:2014-08-06
        /// </summary>
        /// <param name="inParams">银联传送过来的参数信息</param>
        /// <returns></returns>
        bool CallbackVerify(UmsPayConfig config, Dictionary <string, string> inParams)
        {
            // 组装验签内容信息
            var signField = new string[] { "OrderTime", "OrderDate", "MerOrderId", "TransType", "TransAmt", "MerId", "MerTermId", "TransId", "TransState", "RefId", "Account", "TransDesc", "Reserve" };
            var sbSign    = new StringBuilder();

            foreach (var s in signField)
            {
                var r = inParams.Keys.Any(n => String.Equals(n, s.ToLower(), StringComparison.CurrentCultureIgnoreCase));
                if (!r)
                {
                    continue;
                }
                var dict = inParams.FirstOrDefault(n => String.Equals(n.Key, s.ToLower(), StringComparison.CurrentCultureIgnoreCase));
                sbSign.Append(dict.Value);
            }
            // 判断验签是否成功
            var result = RSAUtil.Verify(sbSign.ToString(), inParams["signature"], config.PublicKey);

            if (result)
            {
                Lebi_Order order = B_Lebi_Order.GetModel("Code='" + inParams["MerOrderId"] + "'");
                // 验签成功后,向银联服务发送接收通知消息响应请求
                this.NotifyResponse(config, inParams);
            }
            return(result);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 将接收到的通知信息向银联服务器响应
 /// 创建用户:shiyuankao
 /// 创建时间:2014-08-06
 /// </summary>
 /// <param name="inParams">银联传送过来的参数信息</param>
 void NotifyResponse(UmsPayConfig config, Dictionary <string, string> inParams)
 {
     try
     {
         var signField = new string[] { "OrderTime", "OrderDate", "MerOrderId", "TransType", "TransAmt", "MerId", "MerTermId", "TransId", "TransState", "RefId", "Account", "TransDesc", "Reserve" };
         var sbSign    = new StringBuilder();
         foreach (var s in signField)
         {
             sbSign.Append(inParams[s]);
         }
         var merSign        = RSAUtil.RSASign(sbSign.ToString(), config.PrivateKey);
         var responseObject = new
         {
             TransCode     = "201202",
             MerOrderId    = inParams["MerOrderId"],
             TransType     = "NoticePay",
             MerId         = inParams["MerId"],
             MerTermId     = inParams["MerTermId"],
             TransId       = inParams["TransId"],
             MerPlatTime   = DateTime.Now.ToString("yyyyMMddHHmmss"),
             MerOrderState = "00",//00销账成功 11销账失败
             Reserve       = inParams["Reserve"],
             MerSign       = merSign
         };
         var response = HttpContext.Current.Response;
         response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(responseObject));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Shop.Bussiness.Site site = new Shop.Bussiness.Site();
                int        order_id      = RequestTool.RequestInt("order_id", 0);
                Lebi_Order order         = B_Lebi_Order.GetModel(order_id);
                if (order == null)
                {
                    Response.Write("ERROR");
                    Response.End();
                    return;
                }
                Lebi_Language language = B_Lebi_Language.GetModel(order.Language_id);
                if (order.IsPaid == 1)
                {
                    Response.Write(Language.Tag("已付款", language.Code));
                    Response.End();
                    return;
                }
                order.Site_id_pay = CurrentSite.id;
                order.Language_id = CurrentLanguage.id;
                Lebi_OnlinePay pay = Shop.Bussiness.Money.GetOnlinePay(order, "yinlianqmf");
                if (pay == null)
                {
                    Response.Write(Language.Tag("系统错误", language.Code));
                    Response.End();
                    return;
                }
                if (pay.FeeRate > 0)
                {
                    order.Money_OnlinepayFee = order.Money_Pay * pay.FeeRate / 100;
                }
                if (order.OnlinePay_id != pay.id)
                {
                    order.OnlinePay_id   = pay.id;
                    order.OnlinePay_Code = pay.Code;
                    order.OnlinePay      = pay.Name;
                }
                B_Lebi_Order.Update(order);
                config = new UmsPayConfig(pay);
                Lebi_Currency currendy = B_Lebi_Currency.GetModel(pay.Currency_id);
                //string notify_url = "http://" + RequestTool.GetRequestDomain() + site.WebPath + "/onlinepay/pinpay/notify_url.aspx";


                Lebi_Site lebisite = B_Lebi_Site.GetModel(order.Site_id_pay);
                if (site == null)
                {
                    returnurl = Shop.Bussiness.Site.Instance.WebPath;
                }
                else
                {
                    Lebi_Language lang = B_Lebi_Language.GetModel(order.Language_id);
                    string        path = "";
                    if (lang != null)
                    {
                        path = lang.Path.TrimEnd('/');
                    }
                    if (lebisite.Domain == "")
                    {
                        returnurl = Shop.Bussiness.Site.Instance.WebPath.TrimEnd('/') + lebisite.Path.TrimEnd('/') + path;
                    }
                    else
                    {
                        returnurl = Shop.Bussiness.Site.Instance.WebPath.TrimEnd('/') + path;
                    }
                }


                returnurl = "http://" + RequestTool.GetRequestDomain() + returnurl.TrimEnd('/') + "/user/OrderDetails.aspx?id=" + order.id;
                decimal order_amount1 = order.Money_Pay * currendy.ExchangeRate * (1 + (pay.FeeRate / 100));
                msg = Payment(config, order, order_amount1);
            }
            finally
            {
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 付款操作
        /// 创建用户:shiyuankao
        /// 创建时间:2014-08-07
        /// </summary>
        /// <param name="orderId">订单号</param>
        /// <param name="productName">商品名称</param>
        /// <param name="amount">支付金额</param>
        /// <returns></returns>
        PayMessage Payment(UmsPayConfig config, Lebi_Order order, decimal amount)
        {
            var message = new PayMessage()
            {
                IsSuccess = true
            };

            var now = DateTime.Now;
            // 参数组装
            var inParams = new Dictionary <string, string>
            {
                { "TransCode", "201201" },
                { "OrderTime", now.ToString("HHmmss") },
                { "OrderDate", now.ToString("yyyyMMdd") },
                { "MerOrderId", order.Code },
                { "TransType", "NoticePay" },
                { "TransAmt", (amount * 100).ToString("F0") },
                { "MerId", config.MerId },
                { "MerTermId", config.MerTermId },
                { "NotifyUrl", config.NotifyUrl },
                { "Reserve", order.Code },
                { "OrderDesc", order.Code },
                { "EffectiveTime", "0" }
            };
            var signContent = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}", inParams["OrderTime"], inParams["EffectiveTime"], inParams["OrderDate"], inParams["MerOrderId"], inParams["TransType"], inParams["TransAmt"], inParams["MerId"], inParams["MerTermId"], inParams["NotifyUrl"], inParams["Reserve"], inParams["OrderDesc"]);
            var merSign     = RSAUtil.RSASign(signContent, config.PrivateKey);

            inParams.Add("MerSign", merSign);
            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(inParams);

            //client.PostingData.Add("jsonString", jsonString);
            //var result = client.GetString();
            System.Collections.Specialized.NameValueCollection nv = new System.Collections.Specialized.NameValueCollection();
            nv.Add("jsonString", jsonString);
            string result = HtmlEngine.Post(config.OrderUrl, nv);

            if (string.IsNullOrEmpty(result))
            {
                message.IsSuccess = false;
                message.Msg       = "调用支付下单接口无数据返回。";
                return(message);
            }
            var dictionary = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(result);
            // 判断是否下单成功
            var respCode = dictionary["RespCode"];

            if (respCode != "00000")
            {
                message.IsSuccess = false;
                message.Msg       = dictionary["RespMsg"];
                return(message);
            }
            // 组装验签字符串
            var content = string.Format("{0}{1}{2}{3}{4}{5}", dictionary["MerOrderId"], dictionary["ChrCode"],
                                        dictionary["TransId"], dictionary["Reserve"].Trim(), dictionary["RespCode"], dictionary["RespMsg"].Trim());
            var r = RSAUtil.Verify(content, dictionary["Signature"], config.PublicKey);

            if (!r)
            {
                message.IsSuccess = false;
                message.Msg       = "下单成功,返回数据签名验证失败。";
                return(message);
            }
            var chrCode = dictionary["ChrCode"];
            var transId = dictionary["TransId"];

            inParams.Add("ChrCode", chrCode);
            inParams.Add("TransId", transId);
            merSign             = RSAUtil.RSASign(string.Format("{0}{1}", transId, chrCode), config.PrivateKey);
            inParams["MerSign"] = merSign;
            // 处理各个支付渠道对应的订单编码
            // 以下处理是根据自己业务处理,添加业务订单号
            if (!inParams.ContainsKey("OrderId"))
            {
                inParams.Add("OrderId", inParams["MerOrderId"]);
            }
            var data = new Dictionary <string, string>
            {
                { "MerSign", merSign },
                { "ChrCode", chrCode },
                { "TransId", transId },
                { "MerchantId", config.MerId }
            };

            message.Data      = data;
            message.OtherData = inParams;
            return(message);
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //OrderTime 订单时间 N 14 M 格式: hhmmss
            //OrderDate 订单日期 N 8 M 格式:yyyyMMdd
            //MerOrderId 商户订单号 AN 32 M
            //TransType 交易类型 AN 32 M 固定值:NoticePay
            //TransAmt 交易金额 N 12 M 单位分
            //MerId 商户号 N 32 M
            //MerTermId 终端号 N 8 M
            //TransId 银商订单号 AN 32 M
            //TransState 交易状态 N 2 M
            //RefId 系统检索号 N 12 M
            //Account 支付卡号 N 30 M 支付卡号
            //TransDesc 交易描述 ANS 256 O
            //LiqDate 清算日期 N 8 M yyyyMMdd
            //Reserve 备用字段 ANS 256 O 备用字段
            //Signature 签名数据 ANS 256 M HexStr
            string OrderTime  = RequestTool.RequestString("OrderTime");
            string OrderDate  = RequestTool.RequestString("OrderDate");
            string MerOrderId = RequestTool.RequestString("MerOrderId");
            string TransType  = RequestTool.RequestString("TransType");
            string TransAmt   = RequestTool.RequestString("TransAmt");
            string MerId      = RequestTool.RequestString("MerId");
            string MerTermId  = RequestTool.RequestString("MerTermId");
            string TransId    = RequestTool.RequestString("TransId");
            string TransState = RequestTool.RequestString("TransState");
            string RefId      = RequestTool.RequestString("RefId");
            string Account    = RequestTool.RequestString("Account");
            string TransDesc  = RequestTool.RequestString("TransDesc");
            string LiqDate    = RequestTool.RequestString("LiqDate");
            string Reserve    = RequestTool.RequestString("Reserve");
            string Signature  = RequestTool.RequestString("Signature");
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("OrderTime", "OrderTime");
            dic.Add("OrderDate", "OrderDate");
            dic.Add("MerOrderId", "MerOrderId");
            dic.Add("TransType", "TransType");
            dic.Add("TransAmt", "TransAmt");
            dic.Add("MerId", "MerId");
            dic.Add("MerTermId", "MerTermId");
            dic.Add("TransId", "TransId");
            dic.Add("TransState", "TransState");
            dic.Add("RefId", "RefId");
            dic.Add("Account", "Account");
            dic.Add("TransDesc", "TransDesc");
            dic.Add("LiqDate", "LiqDate");
            dic.Add("Reserve", "Reserve");
            dic.Add("Signature", "Signature");

            Shop.Bussiness.Site site  = new Shop.Bussiness.Site();
            Lebi_Order          order = B_Lebi_Order.GetModel("Code='" + MerOrderId + "'");

            if (order == null)
            {
                Response.Write("订单错误");
                return;
            }
            Lebi_OnlinePay pay = Shop.Bussiness.Money.GetOnlinePay(order, "yinlianqmf");

            if (pay == null)
            {
                return;
            }
            UmsPayConfig config = new UmsPayConfig(pay);

            if (CallbackVerify(config, dic))
            {
                Order.OnlinePaySuccess("yinlianqmf", MerOrderId);
            }
        }