Example #1
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验证失败");
                    }
                }
            }
        }
Example #2
0
        public void WxNotify()
        {
            lock (_obj)
            {
                LogHelper.CreateLog("进入回调方法\r\n\r\n", "wxdebug");
                Notify    notify     = new Notify(this);
                WxPayData notifyData = notify.GetNotifyData();
                LogHelper.CreateLog(string.Format("notifyData:{0}", notifyData.ToJson()), "wxdebug");

                //检查支付结果中transaction_id是否存在
                if (!notifyData.IsSet("transaction_id"))
                {
                    //若transaction_id不存在,则立即返回结果给微信支付后台
                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "FAIL");
                    res.SetValue("return_msg", "支付结果中微信订单号不存在");
                    LogHelper.CreateLog(res.ToXml(), "wxdebug");
                }

                string transactionId = notifyData.GetValue("transaction_id").ToString();
                var    orderId       = notifyData.GetValue("out_trade_no").ToString();

                //由于微信会多次发出返回提示,所以需要判断下数据是否已经处理
                if (!UpdatePayStatus.CheckIsUpdate(orderId))
                {
                    //查询订单,判断订单真实性
                    if (!notify.QueryOrder(transactionId))
                    {
                        //若订单查询失败,则立即返回结果给微信支付后台
                        WxPayData res = new WxPayData();
                        res.SetValue("return_code", "FAIL");
                        res.SetValue("return_msg", "订单查询失败");
                        LogHelper.CreateLog(transactionId + Environment.NewLine + res.ToXml(), "wxdebug");
                    }
                    //查询订单成功
                    else
                    {
                        notifyData.SetValue("is_subscribe", "Y");
                        UpdatePayStatus.WxUpdate(orderId, _totalFee);
                        WxPayData res = new WxPayData();
                        res.SetValue("return_code", "SUCCESS");
                        res.SetValue("return_msg", "OK");
                        LogHelper.CreateLog(
                            "微信支付订单Success" + Environment.NewLine + transactionId + Environment.NewLine + res.ToXml(),
                            "wxdebug");
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// 该方式的朱勇主要防止订单丢失,即页面条状同步通知没有处理订单更新,它则去处理
        /// </summary>
        /// <returns></returns>
        public void Notify()
        {
            var sPara = GetRequestPost();

            if (sPara.Count > 0) //判断是否有带返回参数
            {
                var aliNotify    = new Notify();
                var verifyResult = aliNotify.VerifyNotify(sPara, Request.Form["sign"]);

                if (verifyResult) //验证成功
                {
                    //XML解析notify_data数据
                    try
                    {
                        var xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(sPara["notify_data"]);

                        //商户订单号
                        var out_trade_no = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText;
                        //支付宝交易号
                        var trade_no = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText;
                        //交易状态
                        var trade_status = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText;

                        var orderId = out_trade_no;
                        //这里需要注意
                        var totalFee = xmlDoc.SelectSingleNode("/notify/total_fee").InnerText;
                        var setting  = new JsonSerializerSettings()
                        {
                            Formatting = Newtonsoft.Json.Formatting.Indented
                        };
                        LogHelper.CreateLog(JsonConvert.SerializeObject(sPara["notify_data"], setting), orderId);
                        LogHelper.CreateLog(JsonConvert.SerializeObject(Request.Form), orderId);
                        if (trade_status == "TRADE_FINISHED")
                        {
                            #region
                            if (!UpdatePayStatus.CheckIsUpdate(orderId))
                            {
                                UpdatePayStatus.AlipayUpdate(orderId, totalFee);
                            }

                            #endregion Notify

                            //程序执行完成后必须打印输出"success"这7个字符,否则支付包会不断重发通知
                            Response.Write("success");
                        }
                        else if (trade_status == "TRADE_SUCCESS")
                        {
                            #region
                            if (!UpdatePayStatus.CheckIsUpdate(orderId))
                            {
                                UpdatePayStatus.AlipayUpdate(orderId, totalFee);
                            }

                            #endregion 支付宝回调地址

                            Response.Write("success");
                        }
                        else
                        {
                            Response.Write(trade_status);
                        }
                    }
                    catch (Exception exc)
                    {
                        Response.Write(exc.ToString());
                    }
                }
                else //验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }