Exemple #1
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);
     }
 }
Exemple #2
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);
        }