Beispiel #1
0
        public TaskStatus Handle(IHttpProxy httpProxy)
        {
            using (Log log = new Log("CailutongGateway.Notify_RequestHandler"))
            {
                try
                {
                    string json = httpProxy.ReadRequestBody();
                    log.Log(json);

                    SortedDictionary <string, object> dict = Newtonsoft.Json.JsonConvert.DeserializeObject <SortedDictionary <string, object> >(json);
                    string outTradeNo = (string)dict["outTradeNo"];
                    var    config     = new Config(PayFactory.GetInterfaceXmlConfig(PayInterfaceType.CailutongBTC, outTradeNo));

                    if (Cailutong_Helper.Sign(dict, config.Secret) != (string)dict["sign"])
                    {
                        throw new Exception("校验失败");
                    }

                    var status = Convert.ToInt32(dict["status"]);

                    if (status == 2)
                    {
                        PayFactory.OnPaySuccessed(outTradeNo, Convert.ToDouble(dict["payedAmount"]), null, json);
                    }

                    httpProxy.ResponseWrite("{\"status\":\"success\"}");
                }
                catch (Exception ex)
                {
                    log.Log(ex.ToString());
                }
            }
            return(TaskStatus.Completed);
        }
        public TaskStatus Handle(IHttpProxy httpHandler)
        {
            try
            {
                var xml = httpHandler.ReadRequestBody();
                using (CLog log = new CLog("WeiXinNotify Notify", false))
                {
                    log.Log("xml:{0}", xml);

                    XDocument xmldoc = XDocument.Parse(xml);
                    SortedDictionary <string, string> xmlDict = new SortedDictionary <string, string>();
                    var nodes = xmldoc.Root.Elements();
                    foreach (var element in nodes)
                    {
                        if (element.Name.LocalName != "sign")
                        {
                            xmlDict[element.Name.LocalName] = element.Value;
                        }
                    }

                    var return_code  = xmlDict["return_code"];
                    var result_code  = xmlDict["result_code"];
                    var out_trade_no = xmlDict["out_trade_no"];

                    PayFactory.OnLog(out_trade_no, LogEventType.ReceiveNotify, xml);

                    var config = new Config(PayFactory.GetInterfaceXmlConfig(PayInterfaceType.WeiXinScanQRCode, out_trade_no));

                    log.Log("签名校验");
                    var sign = xmldoc.Root.XPathSelectElement("sign").Value;

                    var computeSign = Helper.GetMd5Hash(xmlDict, config.Key);

                    if (sign != computeSign)
                    {
                        log.Log("正确签名:{0}", computeSign);
                        log.Log("签名校验不通过");
                        throw new Exception("签名校验不通过");
                    }

                    if (result_code == "SUCCESS" && return_code == "SUCCESS")
                    {
                        log.Log("excute OnPaySuccessed");
                        PayFactory.OnPaySuccessed(out_trade_no, null, null, xml);

                        WxPayData data = new WxPayData();
                        data.SetValue("return_code", "SUCCESS");
                        data.SetValue("return_msg", "OK");
                        data.SetValue("appid", config.AppID);
                        data.SetValue("mch_id", config.MchID);
                        data.SetValue("result_code", "SUCCESS");
                        data.SetValue("err_code_des", "OK");
                        data.SetValue("sign", data.MakeSign(config));

                        var writebackXml = data.ToXml();
                        log.Log("write to weixin:{0}", writebackXml);

                        httpHandler.ResponseWrite(writebackXml);
                    }
                }
            }
            catch (Exception ex)
            {
                using (CLog log = new CLog("WeiXin Notify error "))
                {
                    log.Log(ex.ToString());

                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "FAIL");
                    res.SetValue("return_msg", ex.Message);

                    var writebackXml = res.ToXml();
                    log.Log("write to weixin:{0}", writebackXml);

                    httpHandler.ResponseWrite(writebackXml);
                }
            }
            return(TaskStatus.Completed);
        }
Beispiel #3
0
        public TaskStatus Handle(IHttpProxy httpHandler)
        {
            using (Log logPush = new Log("饿了么.Push", false))
            {
                httpHandler.ResponseContentType = "application/json";
                string postContent = httpHandler.ReadRequestBody();
                logPush.Log(postContent);

                Newtonsoft.Json.Linq.JObject jsonObj = postContent.JsonToObject <Newtonsoft.Json.Linq.JObject>();

                Config config = null;
                try
                {
                    //签名验证
                    config = new Config(ResturantFactory.ResturantListener.OnGetPlatformConfigXml(ResturantPlatformType.Ele));
                    if (EleHelper.CheckSign(jsonObj, config) == false)
                    {
                        throw new Exception("签名错误");
                    }

                    int type = jsonObj.Value <int>("type");
                    System.Diagnostics.Debug.WriteLine($"饿了么 callback type:{type}");
                    if (type == 10)
                    {
                        //新订单
                        new Thread(() =>
                        {
                            try
                            {
                                handleNewOrder(jsonObj);
                            }
                            catch (Exception ex)
                            {
                                using (Log log = new Log("handleNewOrder error"))
                                {
                                    log.Log(ex.ToString());
                                    log.Log("post content:{0}", postContent);
                                }
                            }
                        }).Start();
                    }
                    else if (type == 14)
                    {
                        //订单取消
                        new Thread(() =>
                        {
                            try
                            {
                                handleCancelOrder(jsonObj);
                            }
                            catch (Exception ex)
                            {
                                using (Log log = new Log("handleCancelOrder error"))
                                {
                                    log.Log(ex.ToString());
                                    log.Log("post content:{0}", postContent);
                                }
                            }
                        }).Start();
                    }
                    else if (type == 18)
                    {
                        //订单完结
                        new Thread(() =>
                        {
                            try
                            {
                                handleOrderFinish(jsonObj);
                            }
                            catch (Exception ex)
                            {
                                using (Log log = new Log("handleOrderFinish error"))
                                {
                                    log.Log(ex.ToString());
                                    log.Log("post content:{0}", postContent);
                                }
                            }
                        }).Start();
                    }
                    else if (type == 20)
                    {
                        //用户申请取消订单
                        new Thread(() =>
                        {
                            try
                            {
                                handleOrderToCancel(jsonObj);
                            }
                            catch (Exception ex)
                            {
                                using (Log log = new Log("handleOrderToCancel error"))
                                {
                                    log.Log(ex.ToString());
                                    log.Log("post content:{0}", postContent);
                                }
                            }
                        }).Start();
                    }
                    else if (type == 21 || type == 31)
                    {
                        //用户取消退单
                        new Thread(() =>
                        {
                            try
                            {
                                handleCancelOrderRefund(jsonObj);
                            }
                            catch (Exception ex)
                            {
                                using (Log log = new Log("handleCancelOrderRefund error"))
                                {
                                    log.Log(ex.ToString());
                                    log.Log("post content:{0}", postContent);
                                }
                            }
                        }).Start();
                    }
                    else if (type == 30)
                    {
                        //用户申请退单
                        new Thread(() =>
                        {
                            try
                            {
                                handleOrderRefund(jsonObj);
                            }
                            catch (Exception ex)
                            {
                                using (Log log = new Log("handleOrderRefund error"))
                                {
                                    log.Log(ex.ToString());
                                    log.Log("post content:{0}", postContent);
                                }
                            }
                        }).Start();
                    }
                    else if (type == 33)
                    {
                        //用户同意退单
                        new Thread(() =>
                        {
                            try
                            {
                                handleOrderAgreeRefund(jsonObj);
                            }
                            catch (Exception ex)
                            {
                                using (Log log = new Log("handleOrderAgreeRefund error"))
                                {
                                    log.Log(ex.ToString());
                                    log.Log("post content:{0}", postContent);
                                }
                            }
                        }).Start();
                    }
                }
                catch (Exception ex)
                {
                    using (Log log = new Log("饿了么回调解析错误"))
                    {
                        log.Log(ex.ToString());
                        log.Log("post content:{0}", postContent);
                        if (jsonObj != null)
                        {
                            log.LogJson(jsonObj);
                        }
                        if (config != null)
                        {
                            log.LogJson(config);
                        }
                    }
                    throw ex;
                }
                httpHandler.ResponseWrite("{\"message\": \"ok\"}");

                return(TaskStatus.Completed);
            }
        }