Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            var result = false;

            try
            {
                var xdocument   = XDocument.Load(context.Request.InputStream);
                var return_code = xdocument.Descendants("return_code").FirstOrDefault();
                if (return_code != null && return_code.Value == "SUCCESS")
                {
                    var result_code    = xdocument.Descendants("result_code").First().Value;
                    var out_trade_no   = xdocument.Descendants("out_trade_no").First().Value;
                    var transaction_id = xdocument.Descendants("transaction_id").First().Value;
                    var status         = (result_code == "SUCCESS" ? TradeStatus.NOTIFYSUCCESS : TradeStatus.NOTIFYISSUE);
                    WebApiConfig.log.Info("微信通知 " + out_trade_no + "-" + transaction_id + ":" + result_code);
                    JObject localResult;
                    if (!TradeBusiness.UpdateTradeStatusSeveralTimes(out_trade_no, transaction_id, PaymentType.WechatPay, result_code, status, out localResult))
                    {
                        WebApiConfig.log.Error(out_trade_no + "-" + transaction_id + "微信通知支付成功,本地数据库状态维护失败");
                    }
                    else
                    {
                        result = true;
                    }

                    // 通知患者端
                    PatientCustomerBusiness.NotifyPatient(localResult);
                }
            } catch
            {
            }

            if (result)
            {
                context.Response.ContentType = "text/xml";
                context.Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>");
            }
            else
            {
                context.Response.ContentType = "text/xml";
                context.Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
            }
        }
Пример #2
0
        /// <summary>
        /// 检查未提交订单
        /// </summary>
        public static void CheckOrder()
        {
            while (true)
            {
                var now     = DateTime.Now;
                var start   = now.AddHours(-24);
                var list    = TradeBusiness.GetTradeList(start.ToString(), now.ToString());
                var outMess = string.Empty;
                foreach (var item in list)
                {
                    var jObject = item as JObject;
                    var tradeNo = jObject.GetValue("TradeNo").ToString();
                    var status  = jObject.GetValue("Status").ToString();
                    if (status == "4" || status == "7")
                    {
                        break;
                    }

                    try
                    {
                        var mess = CheckOrder(tradeNo, tradeNo.Substring(0, 8), ConfigurationManager.AppSettings["icbc.merID"], ConfigurationManager.AppSettings["icbc.merAcct"], out outMess);
                        if (mess.Length > 5)//缴费成功,未返回错误编码,返回xml数据
                        {
                            DataSet      myds      = new DataSet();
                            StringReader strReader = new StringReader(mess);
                            myds.ReadXml(strReader);
                            string stat = myds.Tables["out"].Rows[0]["tranStat"].ToString();
                            if (stat == "1" || stat == "0")
                            {
                                var     actualTradeNo = myds.Tables["out"].Rows[0]["tranSerialNum"].ToString();
                                JObject localResult;
                                if (!TradeBusiness.UpdateTradeStatusSeveralTimes(tradeNo, actualTradeNo, PaymentType.ICBC, stat, TradeStatus.NOTIFYSUCCESS, out localResult))
                                {
                                    WebApiConfig.log.Info(tradeNo + ":工行查询支付成功,本地数据库状态维护失败");
                                }

                                // 通知患者端
                                PatientCustomerBusiness.NotifyPatient(localResult);
                            }
                            else//支付失败
                            {
                                WebApiConfig.log.Error(tradeNo + ":工行查询支付失败");
                            }
                        }
                        else
                        {
                            string pays = "";
                            switch (mess)
                            {
                            case "40972": pays = "API查询的订单不存在"; break;

                            case "40973": pays = "API查询过程中系统异常"; break;

                            case "40976": pays = "API查询系统异常"; break;

                            case "40977": pays = "商户证书信息错"; break;

                            case "40978": pays = "解包商户请求数据报错"; break;

                            case "40979": pays = "查询的订单不存在"; break;

                            case "40980": pays = "API查询过程中系统异常"; break;

                            case "40981": pays = "给商户打包返回数据错"; break;

                            case "40982": pays = "系统错误"; break;

                            case "40983": pays = "查询的订单不唯一"; break;

                            case "40987": pays = "商户代码或者商城账号有误"; break;

                            case "40947": pays = "给商户打包返回数据错"; break;

                            case "40948": pays = "商城状态非法"; break;

                            case "40949": pays = "商城类别非法"; break;

                            case "40950": pays = "商城应用类别非法"; break;

                            case "40951": pays = "商户证书id状态非法"; break;

                            case "40952": pays = "商户证书id未绑定"; break;

                            case "40953": pays = "商户id权限非法"; break;

                            case "40954": pays = "检查商户状态时数据库异常"; break;
                            }

                            WebApiConfig.log.Error(tradeNo + ":工行查询支付发生错误, 错误编码:" + mess + "-" + pays);
                        }
                    }
                    catch (Exception e)
                    {
                        WebApiConfig.log.Error(tradeNo + ":工行查询支付发生错误:" + e.ToString());
                    }
                }

                System.Threading.Thread.Sleep(1000 * 60 * 60);
            }
        }
Пример #3
0
        public void ProcessRequest(HttpContext context)
        {
            var result = false;

            try
            {
                var str = "工行通知:";
                foreach (var item in context.Request.Form.AllKeys)
                {
                    str += string.Format("{0}:{1},", item, context.Request.Form[item]);
                }

                WebApiConfig.log.Info(str);
                var notifyData = Encoding.GetEncoding("gbk").GetString(Convert.FromBase64String(context.Request.Form["notifyData"]));
                WebApiConfig.log.Info("notifyData:" + notifyData);
                var xdocument        = XDocument.Parse(notifyData);
                var return_code      = xdocument.Descendants("tranStat").First().Value;
                var out_trade_no     = xdocument.Descendants("orderid").First().Value;
                var orderDate        = xdocument.Descendants("orderDate").First().Value;
                var amount           = xdocument.Descendants("amount").First().Value;
                var installmentTimes = xdocument.Descendants("installmentTimes").First().Value;
                var tranSerialNoNode = xdocument.Descendants("TranSerialNo").FirstOrDefault();
                if (tranSerialNoNode == null)
                {
                    tranSerialNoNode = xdocument.Descendants("tranSerialNo").FirstOrDefault();
                }

                var tranSerialNo = tranSerialNoNode.Value; // 银行端指令流水号
                var comment      = xdocument.Descendants("comment").First().Value;

                WebApiConfig.log.Info("工行通知(" + out_trade_no + "-" + orderDate + "-" + amount + "-" + installmentTimes + "):" + return_code);

                TradeStatus status;
                if (return_code == "1")
                {
                    status = TradeStatus.NOTIFYSUCCESS;
                }
                else if (return_code == "2")
                {
                    status = TradeStatus.NOTIFYISSUE;
                }
                else if (return_code == "3")
                {
                    status = TradeStatus.NOTIFYSUSPECT;
                }
                else
                {
                    status = TradeStatus.NOTIFYUNKNOWN;
                }

                JObject localResult;
                if (!TradeBusiness.UpdateTradeStatusSeveralTimes(out_trade_no, tranSerialNo, PaymentType.ICBC, return_code, status, out localResult))
                {
                    WebApiConfig.log.Error(out_trade_no + "-" + tranSerialNo + ":接受到工行通知,本地数据库状态维护失败");
                }
                else
                {
                    result = true;
                }

                if (return_code == "1")
                {
                    // 通知患者端
                    PatientCustomerBusiness.NotifyPatient(localResult);
                }
            }
            catch (Exception e)
            {
                WebApiConfig.log.Error(e.ToString());
            }

            // todo
            if (result)
            {
                context.Response.ContentType = "text/html";
                context.Response.Write("success");
            }
            else
            {
                context.Response.ContentType = "text/html";
                context.Response.Write("failure");
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                var str = string.Empty;
                foreach (var item in sPara)
                {
                    str += string.Format("{0}:{1},", item.Key, item.Value);
                }

                WebApiConfig.log.Info(str);

                Notify aliNotify = new Notify();
                //bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
                string sign = sPara["sign"];
                sPara.Remove("sign");
                sPara.Remove("sign_type");
                string signContent  = AlipaySignature.GetSignContent(sPara);
                var    verifyResult = AlipaySignature.RSACheckContent(signContent, sign, ConfigurationManager.AppSettings["alipay.publicKey"], Request.QueryString["charset"], "RSA", false);
                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


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

                    //商户订单号

                    string out_trade_no = Request.Form["out_trade_no"];

                    //支付宝交易号

                    string trade_no = Request.Form["trade_no"];

                    //交易状态
                    string  trade_status = Request.Form["trade_status"];
                    JObject localResult;
                    int     resultCode;
                    if (Request.Form["trade_status"] == "TRADE_FINISHED")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                        //如果有做过处理,不执行商户的业务程序

                        //注意:
                        //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                        WebApiConfig.log.Info(out_trade_no + "-" + trade_no + "支付宝通知订单完成");
                        if (!TradeBusiness.UpdateTradeStatusSeveralTimes(out_trade_no, trade_no, PaymentType.Alipay, trade_status, TradeStatus.NOTIFYFINISHED, out localResult))
                        {
                            WebApiConfig.log.Error(out_trade_no + "-" + trade_no + "支付宝通知订单完成,本地数据库状态维护失败");
                        }

                        resultCode = (int)TradeStatus.NOTIFYFINISHED;
                    }
                    else if (Request.Form["trade_status"] == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                        //如果有做过处理,不执行商户的业务程序

                        //注意:
                        //付款完成后,支付宝系统发送该交易状态通知
                        WebApiConfig.log.Info(out_trade_no + "-" + trade_no + "支付宝通知订单支付成功");
                        if (!TradeBusiness.UpdateTradeStatusSeveralTimes(out_trade_no, trade_no, PaymentType.Alipay, trade_status, TradeStatus.NOTIFYSUCCESS, out localResult))
                        {
                            WebApiConfig.log.Error(out_trade_no + "-" + trade_no + "支付宝通知订单支付成功,本地数据库状态维护失败");
                        }

                        resultCode = (int)TradeStatus.NOTIFYSUCCESS;
                    }
                    else
                    {
                        TradeBusiness.UpdateTradeStatusSeveralTimes(out_trade_no, trade_no, PaymentType.Alipay, trade_status, TradeStatus.NOTIFYISSUE, out localResult);
                        WebApiConfig.log.Error(out_trade_no + "-" + trade_no + "支付宝通知失败");
                        resultCode = (int)TradeStatus.NOTIFYISSUE;
                    }

                    // 通知患者端
                    PatientCustomerBusiness.NotifyPatient(localResult);
                    Response.Clear();
                    Response.Write("success");
                    Response.End();
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    WebApiConfig.log.Error("支付宝通知验证失败");
                    Response.Write("支付宝通知验证失败");
                }
            }
            else
            {
                WebApiConfig.log.Error("支付宝无通知参数");
                Response.Write("支付宝无通知参数");
            }
        }