예제 #1
0
        public void Notified(Func <NotifyResult, NotifyReturnMessage> onNotified)
        {
            var request = HttpContext.Current.Request;
            var respose = HttpContext.Current.Response;

            respose.ContentType = "text/plain";
            Dictionary <string, string> dictToReturn = new Dictionary <string, string>();

            dictToReturn.Add("return_code", "SUCCESS");
            dictToReturn.Add("return_msg", "");
            NotifyResult result = null;
            string       xml;

            xml = GetResultXml(request);
            ResultBuilder resultBuilder = new ResultBuilder(xml);

            resultBuilder.BasicValidate();
            result = new NotifyResult(resultBuilder);

            NotifyReturnMessage returnMessage = onNotified(result);

            if (!returnMessage.Success)
            {
                dictToReturn["return_code"] = "FAIL";
                dictToReturn["return_msg"]  = returnMessage.Message;
            }
            respose.Write(CommonHelper.CreateXmlForReturn(dictToReturn));
        }
예제 #2
0
 /// <summary>
 /// 微信的回调
 /// </summary>
 /// <param name="callBack">成功的回调,参数为交易ID,由服务端发到支付宝,再由支付宝返回</param>
 /// <param name="errBack">失败的回调,参数为失败的消息</param>
 public void RecieveWxPayNotify(Action <NotifyResult> callBack, Action <NotifyResult> errBack)
 {
     try
     {
         WxPayClient client = GetWxPayClient();
         client.Notified((result) =>
         {
             NotifyReturnMessage message = new NotifyReturnMessage()
             {
                 Success = true,
                 Message = "收到",
             };
             try
             {
                 if (result.Success)
                 {
                     string rechargeID = result.Out_Trade_No;
                     string sPath      = System.Web.HttpContext.Current.Request.MapPath("/");
                     //----以下是处理微信付款后回调服务处理微信订单入本地库
                     Lind.DDD.Logger.LoggerFactory.Instance.Logger_Info("微信回调成功,订单号:" + rechargeID + ",交易号:" + result.Transaction_Id);
                     callBack(result);
                 }
                 else
                 {
                     string msg = string.Format("收到微信通知的错误消息:{0}({1})", result.ErrorMessage, result.ErrorCode);
                     errBack(result);
                     Logger.LoggerFactory.Instance.Logger_Info(msg);
                 }
             }
             catch (Exception ex)
             {
                 message.Success = false;
                 message.Message = ex.Message;
                 Logger.LoggerFactory.Instance.Logger_Error(ex);
             }
             return(message);
         });
     }
     catch (Exception ex)
     {
         Logger.LoggerFactory.Instance.Logger_Error(ex);
     }
 }