Example #1
0
        private void textCase(IRequestMessageBase requestBaseMsg)
        {
            var siteSetting = SiteSettingApplication.SiteSettings;
            int nowtime     = ConvertDateTimeInt(DateTime.Now);
            //string msg = "";
            //用户发送过来的消息内容
            string content = (requestBaseMsg as RequestMessageText).Content;

            //msg = getText(content);
            Log.Info("微信用户输入内容:" + content);
            var data = WeixinAutoReplyApplication.GetAutoReplyByKey(CommonModel.ReplyType.Keyword, content, false, true, false);

            if (data == null)
            {
                Log.Info("请设置自动回复内容!");
            }
            else
            {
                string resxml = GetResxml(data, requestBaseMsg);
                if (!string.IsNullOrEmpty(resxml))
                {
                    Response.Write(resxml);
                }
            }
        }
        // GET: Admin/WeiXin

        public ActionResult FocusReplay()
        {
            var item = WeixinAutoReplyApplication.GetAutoReplyByKey(CommonModel.ReplyType.Follow);

            if (item == null)
            {
                item = new AutoReplyInfo();
            }
            return(View(item));
        }
Example #3
0
        public ActionResult NewsReplay()
        {
            var item = WeixinAutoReplyApplication.GetAutoReplyByKey(CommonModel.ReplyType.Msg);

            if (item == null)
            {
                item           = new Entities.AutoReplyInfo();
                item.TextReply = "欢迎关注";
            }
            return(View(item));
        }
 private string getText(string content)
 {
     Log.Info("微信用户输入内容:" + content);
     var item = WeixinAutoReplyApplication.GetAutoReplyByKey(CommonModel.ReplyType.Keyword, content, false, true, false);
     if (item == null)
     {
         Log.Info("请设置自动回复内容!");
         return "";
     }
     //Log.Info("根据关键字取到的数据:" + item.Id);
     return item.TextReply;
 }
        public ActionResult Index(long id = 0)
        {
            Log.Info("进入微信API");

            //string token = "weixin_test";
            string token = "", signature = "", nonce = "", timestamp = "", echostr = "";
            if (id == 0)
            {
                var siteSetting = _iSiteSettingService.GetSiteSettings();
                token = siteSetting.WeixinToken;
            }
            else
            {
                var _tmp = _iVShopService.GetVShopSetting(id);
                if (_tmp == null)
                {
                    throw new HimallException("错误的商铺编号");
                }
                token = _tmp.Token;
            }
            signature = Request["signature"];
            nonce = Request["nonce"];
            timestamp = Request["timestamp"];
            echostr = Request["echostr"];
            ActionResult actionResult = Content("");

            Log.Info(string.Format("传入信息:signature = {0} , nonce = {1} , timestamp = {2} , echostr = {3} , id = {4}", signature, nonce, timestamp, echostr, id));
            if (Request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timestamp, nonce, token))
                {
                    actionResult = Content(echostr);
                }
            }
            else
            {
                //TODO:[lly] 微信消息处理
                if (!CheckSignature.Check(signature, timestamp, nonce, token))
                {
                    Log.Info("验证不通过");
                }

                XDocument requestDoc = XDocument.Load(Request.InputStream);

#if DEBUG
                //调试时记录数据日志
                Core.Log.Debug(requestDoc);
#endif

                var requestBaseMsg = RequestMessageFactory.GetRequestEntity(requestDoc);
                SceneHelper helper = new SceneHelper();

                //卡券服务
                var cardser = _iWXCardService;

                switch (requestBaseMsg.MsgType)
                {
                    #region Event处理
                    case RequestMsgType.Event:
                        var requestMsg = requestBaseMsg as Senparc.Weixin.MP.Entities.RequestMessageEventBase;
                        Log.Info("进入RequestMsgType - Event:" + requestMsg.Event.ToString());
                        switch (requestMsg.Event)
                        {
                            //取消公众号订阅事件
                            case Event.unsubscribe:
                                UnSubscribe(requestMsg.FromUserName);
                                break;

                            //订阅公众号事件
                            case Event.subscribe:

                                //关注红包
                                actionResult = SendAttentionToUser(requestBaseMsg);


                                #region 关注公众号,欢迎语!
                                int nowtime = ConvertDateTimeInt(DateTime.Now);

                                string msg = "";//关注时,需要发送的内容
                                var data = WeixinAutoReplyApplication.GetAutoReplyByKey(CommonModel.ReplyType.Follow, "", false, true, true);
                                if (data != null)
                                {
                                    msg = data.TextReply;
                                }
                                else
                                    Log.Info("请设置关注后自动回复消息内容!");

                                string resxml = "<xml><ToUserName><![CDATA[" + requestBaseMsg.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestBaseMsg.ToUserName + "]]></FromUserName><CreateTime>" + nowtime + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + msg + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                Response.Write(resxml);
                                #endregion

                                var requestSubscribe = requestMsg as Senparc.Weixin.MP.Entities.RequestMessageEvent_Subscribe;
#if DEBUG
                                Log.Debug(requestSubscribe, new Exception("进入订阅事件"));
#endif
                                bool isActivityBonus = false;
                                SceneModel sceneModel = null;
#if DEBUG
                                Log.Info("进入订阅事件requestSubscribe.EventKey =" + requestSubscribe.EventKey);
#endif
                                #region 场景二维码

                                if (requestSubscribe.EventKey != string.Empty)
                                {
                                    var scene = requestSubscribe.EventKey.Replace("qrscene_", string.Empty);
                                    sceneModel = helper.GetModel(scene);
                                    if (sceneModel != null)
                                    {
#if DEBUG
                                        Log.Info("sceneModel.Type = " + sceneModel.SceneType.ToString());
#endif
                                        if (sceneModel.SceneType == Himall.Model.QR_SCENE_Type.WithDraw)
                                        {//提现场景(未关注时)
                                            echostr = ProcessWithDrawScene(requestSubscribe, scene, sceneModel);
                                            actionResult = Content(echostr);
                                        }
                                        else if (sceneModel.SceneType == Himall.Model.QR_SCENE_Type.Bonus)
                                        {
                                            //TODO:ZJT 用户通过场景二维码扫描关注后 推送消息给用户
                                            //isActivityBonus用于判断激发关注事件的是活动红包还是其他
                                            isActivityBonus = true;
                                            actionResult = SendActivityToUser(sceneModel.Object, requestBaseMsg);
                                        }
                                        else if (sceneModel.SceneType == Himall.Model.QR_SCENE_Type.FlashSaleRemind)
                                        {
#if DEBUG
                                            Log.Info("进入限时购场景二维码事件");
#endif
                                            long flashSaleId = (long)sceneModel.Object;
                                            SendFlashSaleRemindMessage(flashSaleId, requestBaseMsg.FromUserName);
                                        }
                                        else if (sceneModel.SceneType == Himall.Model.QR_SCENE_Type.Binding)//绑定微信
                                        {
                                            echostr = Binding(requestSubscribe, scene, sceneModel);
                                            actionResult = Content(echostr);
                                        }
                                    }
                                }
                                #endregion
                                Log.Info("开始isActivityBonus=" + isActivityBonus);

                                //通过场景二维码进来,并且二维码不是活动红包,则进行关注送红包事件
                                //if (!isActivityBonus && sceneModel != null && sceneModel.SceneType == QR_SCENE_Type.Bonus)
                                //{
                                // actionResult = SendAttentionToUser(requestBaseMsg);
                                //}

#if DEBUG
                                Log.Info("开始Subscribe requestBaseMsg.FromUserName="******"进入限时购场景二维码事件");
                                            long flashSaleId = (long)sceneModel.Object;
                                            SendFlashSaleRemindMessage(flashSaleId, requestBaseMsg.FromUserName);
                                        }
                                        else if (sceneModel.SceneType == Himall.Model.QR_SCENE_Type.Binding)//绑定微信
                                        {
                                            echostr = Binding(requestScan, requestScan.EventKey, sceneModel);
                                            actionResult = Content(echostr);
                                        }
                                    }
                                }
                                break;
                            case Event.card_pass_check:
                                //TODO:DZY[150907] 卡券审核通过
                                var reqpasscard = requestMsg as Senparc.Weixin.MP.Entities.RequestMessageEvent_Card_Pass_Check;
                                if (!string.IsNullOrWhiteSpace(reqpasscard.CardId))
                                {
                                    cardser.Event_Audit(reqpasscard.CardId, WXCardLogInfo.AuditStatusEnum.Audited);
                                }
                                break;
                            case Event.card_not_pass_check:
                                //TODO:DZY[150907] 卡券审核失败
                                var reqnopasscard = requestMsg as Senparc.Weixin.MP.Entities.RequestMessageEvent_Card_Pass_Check;
                                if (!string.IsNullOrWhiteSpace(reqnopasscard.CardId))
                                {
                                    cardser.Event_Audit(reqnopasscard.CardId, WXCardLogInfo.AuditStatusEnum.AuditNot);
                                }
                                break;
                            case Event.user_del_card:
                                //TODO:DZY[150907] 删除卡包内优惠券
                                var requdelcard = requestMsg as Senparc.Weixin.MP.Entities.RequestMessageEvent_User_Del_Card;
                                if (!string.IsNullOrWhiteSpace(requdelcard.CardId) && !string.IsNullOrWhiteSpace(requdelcard.UserCardCode))
                                {
                                    cardser.Event_Unavailable(requdelcard.CardId, requdelcard.UserCardCode);
                                }
                                break;
                            case Event.user_get_card:
                                //TODO:DZY[150907] 用户获取优惠券
                                var requgetcard = requestMsg as Senparc.Weixin.MP.Entities.RequestMessageEvent_User_Get_Card;
                                Log.Debug("WXCard:" + requgetcard.CardId + "_" + requgetcard.UserCardCode);
                                if (!string.IsNullOrWhiteSpace(requgetcard.CardId) && !string.IsNullOrWhiteSpace(requgetcard.UserCardCode))
                                {
                                    cardser.Event_Send(requgetcard.CardId, requgetcard.UserCardCode, requgetcard.FromUserName, requgetcard.OuterId);
                                }
                                break;
                        }
                        break;
                    #endregion
                    case RequestMsgType.Text:
                        textCase(requestBaseMsg);
                        break;
                }
                Response.End();
            }
            return actionResult;
        }
 /// <summary>
 /// 新回复
 /// </summary>
 /// <returns></returns>
 public ActionResult NewsReplay()
 {
     return((ActionResult)this.View((object)(WeixinAutoReplyApplication.GetAutoReplyByKey(ReplyType.Msg, "", true, false, false) ?? new AutoReplyInfo())));
 }