Example #1
0
 public void Push(string user, WeixinRequest request)
 {
     if (!mCache.ContainsKey(user))
     {
         mCache[user] = new FixedSizedQueue <RequestPing>(4);
     }
 }
Example #2
0
        /// <summary>
        /// 获取微信支付回调请求对象
        /// </summary>
        /// <param name="resHandler">获取页面提交参数对象</param>
        /// <returns>微信支付回调请求对象</returns>
        /// <remarks>2015-09-24 苟治国 创建</remarks>
        private WeixinRequest GetParaWeixin(ResponseHandler resHandler)
        {
            if (resHandler == null)
            {
                resHandler = new ResponseHandler(null);
            }
            var paraWeixin = new WeixinRequest()
            {
                //返回状态码 SUCCESS/FAIL 此字段是通信标识,非交易标识,交易是否成功需要查看 result_code来判断
                return_code = resHandler.GetParameter("return_code"),
                //返回信息,如非空为错误原因 1:签名失败 2:参数格式校验错误
                return_msg = resHandler.GetParameter("return_msg"),

                #region 以下字段在return_code为SUCCESS的时候有返回
                //微信公众账号id
                appid = resHandler.GetParameter("appid"),
                //商户号
                mch_id = resHandler.GetParameter("mch_id"),
                //终端设备号
                device_info = resHandler.GetParameter("device_info"),
                //随机字符串
                nonce_str = resHandler.GetParameter("nonce_str"),
                //签名
                sign = resHandler.GetParameter("sign"),
                //业务结果
                result_code = resHandler.GetParameter("result_code"),
                //错误代码
                err_code = resHandler.GetParameter("err_code"),
                //错误代码描述
                err_code_des = resHandler.GetParameter("err_code_des"),
                #endregion

                #region 以下字段在return_code和result_code都为SUCCESS的时候有返回
                //用户标识
                openid = resHandler.GetParameter("openid"),
                //是否关注公众账号
                is_subscribe = resHandler.GetParameter("is_subscribe"),
                //交易类型
                trade_type = resHandler.GetParameter("trade_type"),
                //付款银行
                bank_type = resHandler.GetParameter("bank_type"),
                //总金额
                total_fee = resHandler.GetParameter("total_fee"),
                //现金券金额
                coupon_fee = resHandler.GetParameter("coupon_fee"),
                //货币种类
                fee_type = resHandler.GetParameter("fee_type"),
                //微信支付订单号
                transaction_id = resHandler.GetParameter("transaction_id"),
                //商户订单号
                out_trade_no = resHandler.GetParameter("out_trade_no"),
                //商家数据包
                attach = resHandler.GetParameter("attach"),
                //支付完成时间
                time_end = resHandler.GetParameter("time_end")
                           #endregion
            };

            return(paraWeixin);
        }
Example #3
0
        /// <summary>
        /// 微信回调异常日志
        /// </summary>
        /// <param name="ex">异常对象</param>
        /// <param name="param">微信支付回调请求对象</param>
        /// <returns>void</returns>
        private void WriteWeixinErrorLog(Exception ex, WeixinRequest param)
        {
            if (param == null)
            {
                param = new WeixinRequest();
            }
            var sb = new StringBuilder("--------------------------------------------------------\r\n");

            sb.AppendLine("order:" + param.out_trade_no);
            sb.AppendLine("logtime:" + DateTime.Now);
            sb.AppendLine("message:" + ex.Message);
            Log4Helper.WriteInfoLog(sb.ToString(), "PayNotify");
        }
Example #4
0
        /// <summary>
        /// 微信回调普通日志
        /// </summary>
        /// <param name="content">日志内容</param>
        /// <param name="param">微信支付回调请求对象</param>
        /// <returns>void</returns>
        private void WriteWeixinLog(string content, WeixinRequest param)
        {
            if (param == null)
            {
                param = new WeixinRequest();
            }
            var sb = new StringBuilder("--------------------------------------------------------\r\n");

            sb.AppendLine("order:" + param.out_trade_no);
            sb.AppendLine("logtime:" + DateTime.Now);
            try
            {
                sb.AppendLine("content:" + content);
                Log4Helper.WriteInfoLog(sb.ToString(), "PayNotify");
            }
            catch { }

            LogApp.Instance.Info(new LogRequest()
            {
                Source    = LogEnum.Source.前台,
                Message   = sb.ToString(),
                Exception = null
            });
        }
Example #5
0
        private ContentResult onWeixinRequestReceived(WeixinRequest reqMsg)
        {
            var user = reqMsg.FromUserName;

            if (reqMsg is TextRequest)
            {
                var req     = reqMsg as TextRequest;
                var keyword = req.Content;

                //ping测试
                if (keyword == "@p")
                {
                    return(Content(new TextResponse(user, reqMsg.HowMuchSecondsPassedAfterCreated.ToString()).ToString()));
                }
                //web界面登录
                else if (keyword == "?")
                {
                    var rsp = getWebAppRsp(user, Request).ToString();
                    Console.WriteLine(rsp);
                    return(Content(rsp));
                }
                //表情的过滤
                else if (keyword.StartsWith("/:"))
                {
                    return(Content(new TextResponse(user, keyword).ToString()));
                }
                //留言建议
                else if (keyword.StartsWith("@"))
                {
                    return(Content(new TextResponse(user, " /::)")
                    {
                        FuncFlag = 1
                    }.ToString()));
                }
                //关注
                else if (keyword == "Hello2BizUser")
                {
                    return(onSubscribed(reqMsg));
                }

                LibrarySearchOption option;
                string errMsg;

                ContentResult result    = null;
                var           stopWatch = Stopwatch.StartNew();
                if (UserCommand.GetInstance().OnMessage(user, keyword, out option, out errMsg))
                {
                    result = Content(Library.GetInstance().GetRspForSearch(Session, Request, option).ToString());
                }
                else
                {
                    result = Content(new TextResponse(user, errMsg).ToString());
                }
                stopWatch.Stop();
                ApplicationLogger.GetLogger().Info("(" + Session.SessionID + ")" +
                                                   user + " search for " + keyword + " consume " + stopWatch.ElapsedMilliseconds);
                return(result);
            }
            else if (reqMsg is EventRequest)
            {
                var req = reqMsg as EventRequest;
                if (req.Event == "subscribe")
                {
                    return(onSubscribed(req));
                }
                else if (req.Event == "unsubscribe")
                {
                    return(onUnsubscribed(req));
                }
                else
                {
                    return(Content(new TextResponse(user, "暂未支持,敬请期待").ToString()));
                }
            }
            else
            {
                return(Content(new TextResponse(user, "暂未支持,敬请期待").ToString()));
            }
        }
Example #6
0
 private ContentResult onSubscribed(WeixinRequest reqMsg)
 {
     return(Content(new TextResponse(reqMsg.FromUserName, Consts.WELCOME).ToString()));
 }