Ejemplo n.º 1
0
        public string UnionpayPayNotify()
        {
            // 使用Dictionary保存参数
            Dictionary <string, string> resData = new Dictionary <string, string>();

            resData = GetRequestPost();
            LogHelper.SaveFileLog("UnionpayPayNotify支付回调", "回调参数:" + JsonConvert.SerializeObject(resData));
            // 返回报文中不包含UPOG,表示Server端正确接收交易请求,则需要验证Server端返回报文的签名
            if (SDKUtil.Validate(resData, Encoding.UTF8))
            {
                //Response.Write("商户端验证返回报文签名成功\n");

                string out_trade_no = resData["orderId"];
                string trade_no     = resData["queryId"];
                //商户端根据返回报文内容处理自己的业务逻辑 ,DEMO此处只输出报文结果
                try
                {
                    //OrderService.PayOrderNotify(out_trade_no, trade_no);
                    LogHelper.SaveFileLog("UnionpayPayNotify支付回调", "支付成功->TRADE_SUCCESS");
                    return("success");
                }
                catch (Exception ex)
                {
                    LogHelper.SaveFileLog("UnionpayPayNotify支付回调", "Exception:" + ex.Message);
                    return("fail");
                }
            }
            else
            {
                LogHelper.SaveFileLog("UnionpayPayNotify支付回调", "验签失败");
                return("fail");
            }
        }
Ejemplo n.º 2
0
        public void BackReceive()
        {
            lock (_obj)
            {
                if (Request.HttpMethod == "POST")
                {
                    #region 使用Dictionary保存参数
                    Dictionary <string, string> resData = new Dictionary <string, string>();

                    NameValueCollection coll = Request.Form;

                    string[] requestItem = coll.AllKeys;

                    for (int i = 0; i < requestItem.Length; i++)
                    {
                        resData.Add(requestItem[i], Request.Form[requestItem[i]]);
                    }

                    string respcode = resData["respCode"];
                    #endregion 使用Dictionary保存参数
                    // 返回报文中不包含UPOG,表示Server端正确接收交易请求,则需要验证Server端返回报文的签名
                    if (SDKUtil.Validate(resData, Encoding.UTF8))
                    {
                        #region
                        //我先将所有的返回值答应出来
                        //商户端根据返回报文内容处理自己的业务逻辑 ,DEMO此处只输出报文结果
                        StringBuilder builder = new StringBuilder();

                        builder.Append("ChinaUnion BackReceiver:<table><tr><td align=\"center\" colspan=\"2\"><b>商户端接收银联返回报文并按照表格形式输出结果</b></td></tr>");

                        for (int i = 0; i < requestItem.Length; i++)
                        {
                            builder.Append("<tr><td width=\"30%\" align=\"right\">" + requestItem[i] + "</td><td style='word-break:break-all'>" + Request.Form[requestItem[i]] + "</td></tr>");
                        }
                        builder.Append("<tr><td width=\"30%\" align=\"right\">商户端验证银联返回报文结果</td><td>验证签名成功.</td></tr><table>");
                        LogHelper.CreateLog(builder.ToString(), resData["orderId"]);
                        #endregion

                        if (resData["respMsg"] == "Success!")
                        {
                            var orderId  = resData["orderId"];
                            var totalFee = resData["settleAmt"];
                            if (!UpdatePayStatus.CheckIsUpdate(orderId))
                            {
                                UpdatePayStatus.ChinaUnionUpdate(orderId, totalFee);
                            }
                        }
                        else
                        {//支付失败
                            RedirectToAction("FrontConsume");
                        }
                    }
                    else
                    {
                        LogHelper.WriteLog(">商户端验证银联返回报文结果</td><td>验证签名失败.", "~/log/银联BackReceive验证失败");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成App支付订单参数信息
        /// </summary>
        /// <param name="outTradeNo">业务单号</param>
        /// <param name="subject">支付标题</param>
        /// <param name="body">支付内容</param>
        /// <param name="totalFee">支付金额</param>
        /// <returns></returns>
        public static UniionpayResult GetPayString(string outTradeNo, string orderDesc, decimal totalAmount, bool isPrePay, out string payParam)
        {
            UniionpayResult result = new UniionpayResult();
            //构造待签名数据
            Dictionary <string, string> param = new Dictionary <string, string>();

            try
            {
                //填写参数
                param["version"]      = "5.0.0";                                     //版本号
                param["encoding"]     = "UTF-8";                                     //编码方式
                param["certId"]       = CertUtil.GetSignCertId();                    //证书ID
                param["txnType"]      = isPrePay ? TxnType.PrePay : TxnType.Consume; //交易类型
                param["txnSubType"]   = "01";                                        //交易子类
                param["bizType"]      = "000000";                                    //业务类型
                param["backUrl"]      = SDKConfig.BackTransUrl;                      //后台异步通知地址
                param["signMethod"]   = "01";                                        //签名方法,01:表示采用RSA
                param["channelType"]  = "08";                                        //渠道类型,07-PC,08-手机
                param["accessType"]   = "0";                                         //接入类型,0:商户直连接入 1:收单机构接入 2:平台商户接入
                param["merId"]        = SDKConfig.MerId;                             //商户号,请改成自己的商户号
                param["orderId"]      = outTradeNo;                                  //商户订单号
                param["txnTime"]      = DateTime.Now.ToString("yyyyMMddHHmmss");     //订单发送时间
                param["txnAmt"]       = (totalAmount * 100).ToString("0");           //交易金额,单位分
                param["currencyCode"] = "156";                                       //交易币种
                param["orderDesc"]    = orderDesc;                                   //订单描述,可不上送,上送时控件中会显示该信息
                SDKUtil.Sign(param, Encoding.UTF8);                                  // 签名
                payParam = JsonConvert.SerializeObject(param);
                // 初始化通信处理类
                HttpClient hc = new HttpClient(SDKConfig.AppRequestUrl);
                // 发送请求获取通信应答
                int status = hc.Send(param, Encoding.UTF8);
                // 返回结果
                string results = hc.Result;
                Dictionary <string, string> resData = SDKUtil.CoverstringToDictionary(results);
                result.respcode = resData["respCode"];
                if (result.respcode != "00")
                {
                    result.respMsg = resData["respMsg"];
                    return(result);
                }
                if (!SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    LogHelper.SaveFileLog("获取银联支付信息失败!", "商户端验证返回报文签名失败:" + JsonConvert.SerializeObject(resData));
                    result.respMsg = resData["respMsg"];
                    return(result);
                }
                result.tn = resData["tn"];
            }
            catch (Exception ex)
            {
                payParam = JsonConvert.SerializeObject(param);
                LogHelper.SaveFileLog("获取银联支付信息失败!", ex.Message);
                result.respcode = "";
                result.respMsg  = "";
            }
            return(result);
        }
Ejemplo n.º 4
0
        public ActionResult FrontUrl()
        {
            var payResult = new PayResultViewModel();

            if (Request.HttpMethod == "POST")
            {
                #region 使用Dictionary保存参数
                Dictionary <string, string> resData = new Dictionary <string, string>();

                NameValueCollection coll = Request.Form;

                string[] requestItem = coll.AllKeys;

                for (int i = 0; i < requestItem.Length; i++)
                {
                    resData.Add(requestItem[i], Request.Form[requestItem[i]]);
                }

                string respcode = resData["respCode"];
                #endregion 使用Dictionary保存参数
                // 返回报文中不包含UPOG,表示Server端正确接收交易请求,则需要验证Server端返回报文的签名
                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    #region 报文结果写入文件
                    //商户端根据返回报文内容处理自己的业务逻辑 ,DEMO此处只输出报文结果
                    StringBuilder builder = new StringBuilder();

                    builder.Append("ChinaUnion FrontUrl: <table><tr><td align=\"center\" colspan=\"2\"><b>商户端接收银联返回报文并按照表格形式输出结果</b></td></tr>");

                    for (int i = 0; i < requestItem.Length; i++)
                    {
                        builder.Append("<tr><td width=\"30%\" align=\"right\">" + requestItem[i] + "</td><td style='word-break:break-all'>" + Request.Form[requestItem[i]] + "</td></tr>");
                    }

                    builder.Append("<tr><td width=\"30%\" align=\"right\">商户端验证银联返回报文结果</td><td>验证签名成功.</td></tr></table>");
                    LogHelper.CreateLog(builder.ToString(), resData["orderId"]);
                    #endregion 报文结果写入文件
                    if (resData["respMsg"] == "success")
                    {
                        payResult.Status = true;
                    }
                    else
                    {//支付失败
                        payResult.Status = false;
                    }
                }
                else
                {
                    payResult.Status = false;
                    LogHelper.WriteLog(">商户端验证银联返回报文结果</td><td>验证签名失败.", "~/log/银联Front验证失败", "error_____" + DateTime.Now.Ticks);
                }
            }
            return(View(payResult));
        }
Ejemplo n.º 5
0
        public override void VerifyNotify(int timeout, string configXml)
        {
            Dictionary <string, string> data = new Dictionary <string, string>();

            string[] allKeys = this.parameters.AllKeys;
            for (int i = 0; i < allKeys.Length; i++)
            {
                data.Add(allKeys[i], this.parameters[allKeys[i]]);
            }
            if (SDKUtil.Validate(data, Encoding.UTF8))
            {
                this.OnFinished(false);
            }
            else
            {
                this.OnNotifyVerifyFaild();
            }
        }
Ejemplo n.º 6
0
        public ActionResult AppConsume(string txnAmt, string orderDesc)
        {
            LogerHelper.DefaultInfo(Request.ToString());
            Dictionary <string, string> param = new Dictionary <string, string>();
            // 随机构造一个订单号(演示用)
            Random rnd     = new Random();
            string orderID = DateTime.Now.ToString("yyyyMMddHHmmss") + (rnd.Next(900) + 100).ToString().Trim();

            //填写参数

            param["version"]      = "5.0.0";                                                 //版本号
            param["encoding"]     = "UTF-8";                                                 //编码方式
            param["certId"]       = CertUtil.GetSignCertId();                                //证书ID
            param["txnType"]      = "01";                                                    //交易类型
            param["txnSubType"]   = "01";                                                    //交易子类
            param["bizType"]      = "000201";                                                //业务类型
            param["frontUrl"]     = "http://localhost:8080/demo/utf8/FrontRcvResponse.aspx"; //前台通知地址 ,控件接入方式无作用
            param["backUrl"]      = "http://weixin.mandelaauto.com/Pay/CupComplete";         //后台通知地址
            param["signMethod"]   = "01";                                                    //签名方法
            param["channelType"]  = "08";                                                    //渠道类型,07-PC,08-手机
            param["accessType"]   = "0";                                                     //接入类型
            param["merId"]        = Properties.getHost();                                    //商户号,请改成自己的商户号
            param["orderId"]      = orderID;                                                 //商户订单号
            param["txnTime"]      = DateTime.Now.ToString("yyyyMMddHHmmss");                 //订单发送时间
            param["txnAmt"]       = txnAmt;                                                  //交易金额,单位分
            param["currencyCode"] = "156";                                                   //交易币种
            param["orderDesc"]    = orderDesc;                                               //订单描述,可不上送,上送时控件中会显示该信息
            param["reqReserved"]  = "透传信息";                                                  //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现
            SDKUtil.Sign(param, Encoding.UTF8);                                              // 签名
            Response.Write("\n" + "请求报文=[" + SDKUtil.PrintDictionaryToString(param) + "]\n");

            // 初始化通信处理类
            HttpClient hc = new HttpClient(SDKConfig.AppRequestUrl);
            //// 发送请求获取通信应答
            int status = hc.Send(param, Encoding.UTF8);
            // 返回结果
            string result = hc.Result;

            if (status == 200)
            {
                Response.Write("返回报文=[" + result + "]\n");
                LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + result);
                Dictionary <string, string> resData = SDKUtil.CoverstringToDictionary(result);
                foreach (var x in resData.Keys)
                {
                    LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + x);
                }
                string respcode = resData["respCode"];
                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    Response.Write("商户端验证返回报文签名成功\n");
                }
                else
                {
                    Response.Write("商户端验证返回报文签名失败\n");
                }
            }
            else
            {
                Response.Write("请求失败\n");
                Response.Write("返回报文=[" + result + "]\n");
            }
            return(Content("success"));
        }
Ejemplo n.º 7
0
        //银联支付结果回调接口
        public ActionResult CupComplete(Cup cup)
        {
            LogerHelper.DefaultInfo(Request.ToString());
            if (Request.HttpMethod == "POST")
            {
                // 使用Dictionary保存参数
                Dictionary <string, string> resData = new Dictionary <string, string>();

                NameValueCollection coll = Request.Form;

                string[] requestItem = coll.AllKeys;

                for (int i = 0; i < requestItem.Length; i++)
                {
                    resData.Add(requestItem[i], Request.Form[requestItem[i]]);
                }
                // 返回报文中不包含UPOG,表示Server端正确接收交易请求,则需要验证Server端返回报文的签名
                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    cup.accNo            = resData["accNo"];
                    cup.bindId           = resData["bindId"];
                    cup.bizType          = resData["bizType"];
                    cup.cupParams        = coll.ToString();
                    cup.id               = resData["id"];
                    cup.merId            = resData["merId"];
                    cup.orderId          = resData["orderId"];
                    cup.payCardIssueName = resData["payCardIssueName"];
                    cup.payCardNo        = resData["payCardNo"];
                    cup.payCardType      = resData["payCardType"];
                    cup.payType          = resData["payType"];
                    cup.queryId          = resData["queryId"];
                    cup.respCode         = resData["respCode"];
                    cup.respMsg          = resData["respMsg"];
                    cup.settleAmt        = Convert.ToInt32(resData["settleAmt"]);
                    cup.settleDate       = resData["settleDate"];
                    cup.txnAmt           = Convert.ToInt32(resData["txnAmt"]);
                    cup.txnTime          = resData["txnTime"];
                    cup.txnType          = resData["txnType"];
                    string respcode = resData["respCode"];
                    //Response.Write("商户端验证返回报文签名成功\n");

                    //商户端根据返回报文内容处理自己的业务逻辑 ,DEMO此处只输出报文结果
                    //StringBuilder builder = new StringBuilder();

                    //builder.Append("<tr><td align=\"center\" colspan=\"2\"><b>商户端接收银联返回报文并按照表格形式输出结果</b></td></tr>");

                    //for (int i = 0; i < requestItem.Length; i++)
                    //{
                    //    builder.Append("<tr><td width=\"30%\" align=\"right\">" + requestItem[i] + "</td><td style='word-break:break-all'>" + Request.Form[requestItem[i]] + "</td></tr>");
                    //}

                    //builder.Append("<tr><td width=\"30%\" align=\"right\">商户端验证银联返回报文结果</td><td>验证签名成功.</td></tr>");
                    //Response.Write(builder.ToString());
                    cup.cupParams = coll.ToString();
                    cup.id        = Guid.NewGuid().ToString().Replace("-", "");
                    if (paymentbll.cupPayment(cup))
                    {
                        LogerHelper.debug("银联支付成功");
                        return(Content("success"));
                    }
                }
                else
                {
                    LogerHelper.debug("银联支付失败");
                    // Response.Write("<tr><td width=\"30%\" align=\"right\">商户端验证银联返回报文结果</td><td>验证签名失败.</td></tr>");
                }
            }
            return(Content("fail"));
        }
Ejemplo n.º 8
0
        public ActionResult Result()
        {
            // 使用Dictionary保存参数
            Dictionary <string, string> resData = new Dictionary <string, string>();
            NameValueCollection         coll    = Request.Form;

            string[] requestItem = coll.AllKeys;
            for (int i = 0; i < requestItem.Length; i++)
            {
                resData.Add(requestItem[i], Request.Form[requestItem[i]]);
            }
            string merId   = resData["merId"];   //商户号
            string orderId = resData["orderId"]; //商户订单号
            string queryId = resData["queryId"]; //交易查询流水号
            string txnAmt  = resData["txnAmt"];  //交易金额
            Orders Orders  = Entity.Orders.FirstOrDefault(n => n.TNum == orderId);

            if (Orders == null)
            {
                ViewBag.ErrorMsg = "订单信息有误!";
                return(View("Error"));
            }
            PayConfig PayConfig = Entity.PayConfig.FirstOrDefault(n => n.Id == Orders.PayWay && n.State == 1);

            if (PayConfig == null)
            {
                ViewBag.ErrorMsg = "支付通道已关闭!";
                return(View("Error"));
            }
            //================================================
            PayLog PayLog = new PayLog();

            PayLog.PId     = PayConfig.Id;
            PayLog.OId     = orderId;
            PayLog.TId     = queryId;
            PayLog.Amount  = decimal.Parse(txnAmt) / 100;
            PayLog.Way     = "GET";
            PayLog.AddTime = DateTime.Now;
            PayLog.Data    = Request.Form.ToString();
            PayLog.State   = 1;
            Entity.PayLog.AddObject(PayLog);
            Entity.SaveChanges();
            //================================================
            // 返回报文中不包含UPOG,表示Server端正确接收交易请求,则需要验证Server端返回报文的签名
            if (!SDKUtil.Validate(resData, Encoding.UTF8))
            {
                ViewBag.ErrorMsg = "签名错误!";
                return(View("Error"));
            }
            //================================================
            string[] strArray = PayConfig.QueryArray.Split(new char[] { ',' }); //接口信息 商户号,终端号,密钥
            string   MemberID = strArray[0];                                    //商户号

            if (merId != MemberID)
            {
                ViewBag.ErrorMsg = "支付信息有误!";
                return(View("Error"));
            }
            string respCode = resData["respCode"];//响应码

            if (respCode != "00")
            {
                ViewBag.ErrorMsg = "支付失败![" + respCode + "]";
                return(View("Error"));
            }
            //string respMsg = resData["respMsg"];//应答信息
            //if (respMsg != "success")
            //{
            //    ViewBag.ErrorMsg = "支付失败![" + respMsg + "]";
            //    return View("Error");
            //}

            int factmoney = int.Parse(txnAmt);

            if (((int)(Orders.Amoney * 100)) > factmoney)
            {
                ViewBag.ErrorMsg = "支付金额与交易金额不符!";
                return(View("Error"));
            }
            Orders         = Orders.PaySuccess(Entity);
            ViewBag.Orders = Orders;
            return(View("Success"));
        }
Ejemplo n.º 9
0
        public void Notice()
        {
            // 使用Dictionary保存参数
            Dictionary <string, string> resData = new Dictionary <string, string>();
            NameValueCollection         coll    = Request.Form;

            string[] requestItem = coll.AllKeys;
            for (int i = 0; i < requestItem.Length; i++)
            {
                string formvalue = Request.Form[requestItem[i]];
                if (formvalue.IndexOf("%") != -1)
                {
                    formvalue = HttpUtility.UrlDecode(formvalue, Encoding.UTF8);
                }
                resData.Add(requestItem[i], formvalue);
            }
            string merId   = resData["merId"];   //商户号
            string orderId = resData["orderId"]; //商户订单号
            string queryId = resData["queryId"]; //交易查询流水号
            string txnAmt  = resData["txnAmt"];  //交易金额
            Orders Orders  = Entity.Orders.FirstOrDefault(n => n.TNum == orderId);

            if (Orders == null)
            {
                Response.Write("E4");
                return;
            }
            PayConfig PayConfig = Entity.PayConfig.FirstOrDefault(n => n.Id == Orders.PayWay && n.State == 1);

            if (PayConfig == null)
            {
                Response.Write("E0");
                return;
            }
            //================================================
            PayLog PayLog = new PayLog();

            PayLog.PId     = PayConfig.Id;
            PayLog.OId     = orderId;
            PayLog.TId     = queryId;
            PayLog.Amount  = decimal.Parse(txnAmt) / 100;
            PayLog.Way     = "POST";
            PayLog.AddTime = DateTime.Now;
            PayLog.Data    = Request.Form.ToString();
            PayLog.State   = 1;
            Entity.PayLog.AddObject(PayLog);
            Entity.SaveChanges();
            //================================================
            // 返回报文中不包含UPOG,表示Server端正确接收交易请求,则需要验证Server端返回报文的签名
            if (!SDKUtil.Validate(resData, Encoding.UTF8))
            {
                Response.Write("E2");
                return;
            }
            //================================================
            string[] strArray = PayConfig.QueryArray.Split(new char[] { ',' }); //接口信息 商户号,终端号,密钥
            string   MemberID = strArray[0];                                    //商户号

            if (merId != MemberID)
            {
                Response.Write("E1");
                return;
            }
            string respCode = resData["respCode"];//响应码

            if (respCode != "00")
            {
                Response.Write("E3");
                return;
            }
            //string respMsg = resData["respMsg"];//应答信息
            //if (respMsg != "success")
            //{
            //    Response.Write("E4");
            //    return;
            //}
            int factmoney = int.Parse(txnAmt);

            if (((int)(Orders.Amoney * 100)) > factmoney)
            {
                Response.Write("E5");
                return;
            }
            Orders = Orders.PaySuccess(Entity);
            Response.Write("OK");
        }