Esempio n. 1
0
        /// <summary>
        /// 获取默认 无关键词 匹配回复
        /// </summary>
        /// <param name="wxRequest"></param>
        /// <param name="account"></param>
        /// <param name="globalConfig"></param>
        /// <returns></returns>
        public string GetWXResponseDefaultMsg(WXReqBaseMsg wxRequest, WeChatAccountTmp account)
        {
            //获取账号默认回复设置
            DefaultSet defaultSet = ServiceIoc.Get <DefaultSetService>().GetDefaultSet();

            //默认无匹配回复
            if (defaultSet != null && !string.IsNullOrEmpty(defaultSet.d_reply_value) && defaultSet.d_reply_value.IndexOf("#") != -1 && defaultSet.d_reply_isopen)
            {
                //关注回复类型
                string d_type = defaultSet.d_reply_value.Split('#')[1];

                //关注回复业务ID
                int d_bizid = int.Parse(defaultSet.d_reply_value.Split('#')[0].ToString());

                //文本回复
                if (KeyWordBizType.TextReply.Equals(d_type))
                {
                    return(ServiceIoc.Get <TextReplyService>().GetWXResponseMsg(wxRequest, account, d_bizid));
                }
                else if (KeyWordBizType.ImgTextReply.Equals(d_type))
                {
                    return(ServiceIoc.Get <ImgTextReplyService>().GetWXResponseMsg(wxRequest, account, d_bizid));
                }
            }

            return(string.Empty);
        }
Esempio n. 2
0
        public WXReqBaseMsg GetRequest(string postStr)
        {
            //XML文档处理对象
            XmlDocument postObj = new XmlDocument();

            //加载xml格式请求数据
            postObj.LoadXml(postStr);

            //获取xml结构根目录
            XmlElement postElement = postObj.DocumentElement;

            //获取请求消息类型
            string msgtype = postElement.SelectSingleNode("MsgType").InnerText;

            WXReqBaseMsg entitybase = null;

            //判断接收消息类型
            switch (msgtype)
            {
            //文本消息
            case WXReqMsgType.text:
                entitybase = XmlConvertHelper.DeserializeObject <WXReqTextMsg>(postStr);
                break;

            //图片消息
            case WXReqMsgType.image:
                entitybase = XmlConvertHelper.DeserializeObject <WXReqImageMsg>(postStr);
                break;

            //语音消息
            case WXReqMsgType.voice:
                entitybase = XmlConvertHelper.DeserializeObject <WXReqVoiceMsg>(postStr);
                break;

            //视频消息
            case WXReqMsgType.video:
                entitybase = XmlConvertHelper.DeserializeObject <WXReqVideoMsg>(postStr);
                break;

            //地理位置消息
            case WXReqMsgType.location:
                entitybase = XmlConvertHelper.DeserializeObject <WXReqLocationMsg>(postStr);
                break;

            //链接消息
            case WXReqMsgType.url:
                entitybase = XmlConvertHelper.DeserializeObject <WXReqLinkMsg>(postStr);
                break;

            //事件消息
            case WXReqMsgType.wxevent:
                entitybase = XmlConvertHelper.DeserializeObject <WXReqEventMsg>(postStr);
                break;
            }
            return(entitybase);
        }
Esempio n. 3
0
        /// <summary>
        /// 微信客服回复序列化
        /// </summary>
        /// <param name="wxRequest"></param>
        /// <returns></returns>
        public string GetWXResponseMsg(WXReqBaseMsg wxRequest)
        {
            WXRepBaseMsg wXRepTextReply = new WXRepBaseMsg();

            wXRepTextReply.CreateTime   = DateTime.Now.Ticks;
            wXRepTextReply.FromUserName = wxRequest.ToUserName;
            wXRepTextReply.ToUserName   = wxRequest.FromUserName;
            wXRepTextReply.MsgType      = "transfer_customer_service";

            return(XmlConvertHelper.SerializeObject <WXRepBaseMsg>(wXRepTextReply));
        }
Esempio n. 4
0
        /// <summary>
        /// 获取文本响应信息
        /// </summary>
        /// <param name="wxRequest"></param>
        /// <param name="account"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetWXResponseMsg(WXReqBaseMsg wxRequest, WeChatAccountTmp account, long id)
        {
            TextReply textReply = base.GetById(id);

            WXRepTextReply wXRepTextReply = new WXRepTextReply();

            wXRepTextReply.CreateTime   = DateTime.Now.Ticks;
            wXRepTextReply.FromUserName = wxRequest.ToUserName;
            wXRepTextReply.ToUserName   = wxRequest.FromUserName;
            wXRepTextReply.MsgType      = WXRepMsgType.text;

            //文本回复内容
            wXRepTextReply.Content = textReply.reply_contents;

            return(XmlConvertHelper.SerializeObject <WXRepTextReply>(wXRepTextReply));
        }
Esempio n. 5
0
        /// <summary>
        /// 获取文本响应信息
        /// </summary>
        /// <param name="wxRequest"></param>
        /// <param name="account"></param>
        /// <param name="content"></param>
        /// <param name="globalConfig"></param>
        /// <returns></returns>
        public string GetWXResponseMsg(WXReqBaseMsg wxRequest, string content)
        {
            if (!string.IsNullOrEmpty(content))
            {
                WXRepTextReply wXRepTextReply = new WXRepTextReply();

                wXRepTextReply.CreateTime   = DateTime.Now.Ticks;
                wXRepTextReply.FromUserName = wxRequest.ToUserName;
                wXRepTextReply.ToUserName   = wxRequest.FromUserName;
                wXRepTextReply.MsgType      = WXRepMsgType.text;

                //文本回复内容
                wXRepTextReply.Content = content;

                return(XmlConvertHelper.SerializeObject <WXRepTextReply>(wXRepTextReply));
            }
            return(string.Empty);
        }
        /// <summary>
        /// 微信多图文回复序列化
        /// </summary>
        /// <param name="request"></param>
        /// <param name="wXRepImgTextReply"></param>
        /// <returns></returns>
        public string GetWXResponseMsg(WXReqBaseMsg request, List <WXRepImgTextReply> wXRepImgTextReply)
        {
            //多图文信息
            if (wXRepImgTextReply != null && wXRepImgTextReply.Count > 0)
            {
                WXRepNews wXRepBaseMsg = new WXRepNews();
                //接收人
                wXRepBaseMsg.ToUserName = request.FromUserName;
                //发送人
                wXRepBaseMsg.FromUserName = request.ToUserName;
                //创建时间
                wXRepBaseMsg.CreateTime = DateTime.Now.Ticks;
                //消息类型
                wXRepBaseMsg.MsgType = WXRepMsgType.news;
                //多图文数量
                wXRepBaseMsg.imgTextReplys = wXRepImgTextReply;
                //多图文数量
                wXRepBaseMsg.ArticleCount = wXRepImgTextReply.Count;

                return(XmlConvertHelper.SerializeObject <WXRepNews>(wXRepBaseMsg));
            }
            return(string.Empty);
        }
Esempio n. 7
0
        /// <summary>
        /// 根据关键词类型获取响应消息
        /// </summary>
        /// <param name="wxRequest"></param>
        /// <param name="keyWord"></param>
        /// <returns></returns>
        protected string GetKeyWordBizTypeMsg(WXReqBaseMsg wxRequest, WeChatAccountTmp account, KeyWord keyWord)
        {
            if (keyWord == null)
            {
                return(string.Empty);
            }

            switch (keyWord.biz_type)
            {
            //活动关键词 数据拼装
            //case KeyWordBizType.Activity:
            //    return ServiceIoc.Get<ActivityBaseService>().GetWXResponseMsg(wxRequest, account, keyWord.biz_id, UserSourceType.WeiXin);

            //图文关键词 数据拼装
            case KeyWordBizType.ImgTextReply:
                return(ServiceIoc.Get <ImgTextReplyService>().GetWXResponseMsg(wxRequest, account, keyWord.biz_id));

            //文本关键词 数据拼装
            case KeyWordBizType.TextReply:
                return(ServiceIoc.Get <TextReplyService>().GetWXResponseMsg(wxRequest, account, keyWord.biz_id));
            }

            return(string.Empty);
        }
Esempio n. 8
0
        /// <summary>
        /// 处理文本消息请求 响应
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public string Response(WXReqBaseMsg wxRequest, WeChatAccountTmp account)
        {
            //响应信息
            string  responseMsg = string.Empty;
            KeyWord keyWord;

            if (wxRequest != null)
            {
                //先判断是否已开启微客服,如开启则接入微客服
                //responseMsg = ServiceIoc.Get<CustomerService>().GetWXResponseMsg(wxRequest);
                //if (!string.IsNullOrEmpty(responseMsg))
                //{
                //    return responseMsg;
                //}

                //更新联系时间
                ServiceIoc.Get <WeChatUserService>().UpdateLastContactTime(wxRequest.FromUserName);

                switch (wxRequest.MsgType)
                {
                //文本消息
                case WXReqMsgType.text:
                    //转换成为文本请求
                    WXReqTextMsg reqTextMsg = (WXReqTextMsg)wxRequest;

                    //统计关键词
                    //StatsKeyWords statsKeyWords = new StatsKeyWords();
                    //statsKeyWords.keyword = reqTextMsg.Content;
                    //statsKeyWords.req_datetime = DateTime.Now;
                    keyWord = ServiceIoc.Get <KeyWordService>().GetKeyWordMsg(reqTextMsg.Content);
                    //if (keyWord != null)
                    //    statsKeyWords.is_hit = true;

                    //ServiceIoc.Get<StatsKeyWordsService>().Save(statsKeyWords);
                    responseMsg = GetKeyWordBizTypeMsg(wxRequest, account, keyWord);
                    break;

                //图片消息
                case WXReqMsgType.image:
                    break;

                //语音消息
                case WXReqMsgType.voice:
                    break;

                //视频消息
                case WXReqMsgType.video:
                    break;

                //地理位置消息
                case WXReqMsgType.location:
                    //responseMsg = ServiceIoc.Get<LbsReplyService>().GetWXResponseMsg((WXReqLocationMsg)wxRequest);
                    break;

                //链接消息
                case WXReqMsgType.url:
                    break;

                //事件推送
                case WXReqMsgType.wxevent:
                    Type   t          = wxRequest.GetType();
                    string event_name = t.GetProperty("Event").GetValue(wxRequest, null).ToString();

                    ServiceIoc.Get <APILogsService>().Save("WXReqMsgType.wxevent:" + event_name.ToLower());
                    switch (event_name.ToLower())
                    {
                    //订阅
                    case WXEventType.subscribe:
                        WXReqSubscribe subscribe = (WXReqSubscribe)wxRequest;
                        if (!string.IsNullOrEmpty(subscribe.EventKey) && subscribe.EventKey.ToString().IndexOf("qrscene_") != -1)
                        {
                            //获取扫码参数
                            string val = subscribe.EventKey.ToString().Replace("qrscene_", "");
                            ServiceIoc.Get <WeChatUserService>().Subscribe(account, wxRequest.FromUserName, long.Parse(val));
                        }
                        else
                        {
                            ServiceIoc.Get <WeChatUserService>().Subscribe(account, wxRequest.FromUserName, 0);
                        }
                        responseMsg = ServiceIoc.Get <DefaultSetService>().GetWXResponseAttentionMsg(wxRequest, account);
                        break;

                    //取消订阅
                    case WXEventType.unsubscribe:
                        WXReqSubscribe unSubscribe = (WXReqSubscribe)wxRequest;
                        break;

                    //菜单点击
                    case WXEventType.click:
                        WXReqSubscribe click = (WXReqSubscribe)wxRequest;
                        keyWord     = ServiceIoc.Get <KeyWordService>().GetKeyWordMsg(click.EventKey);
                        responseMsg = GetKeyWordBizTypeMsg(wxRequest, account, keyWord);
                        break;

                    //用户扫描二维码
                    case WXEventType.scan:
                        break;

                    //群发任务提回调推送事件
                    case WXEventType.masssendjobfinish:
                        WXReqMassSendJobFinish massSendJobFinish = (WXReqMassSendJobFinish)wxRequest;
                        ServiceIoc.Get <WXSendRecordService>().SetSendStatus(massSendJobFinish);
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }

                //默认无匹配回复
                return(string.IsNullOrEmpty(responseMsg) ? ServiceIoc.Get <DefaultSetService>().GetWXResponseDefaultMsg(wxRequest, account) : responseMsg);
            }
            return(string.Empty);
        }
        /// <summary>
        /// 获取多图文响应信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="id"></param>
        /// <param name="tableConfig"></param>
        /// <returns></returns>
        public string GetWXResponseMsg(WXReqBaseMsg request, WeChatAccountTmp account, long id)
        {
            //当前图文信息
            ImgTextReply imgTextReply = base.GetById(id);

            //图文回复集合
            List <ImgTextReply> imgTextReplys = new List <ImgTextReply>();

            //图文回复微信数据交互中间对象
            List <WXRepImgTextReply> wXRepImgTextReply = new List <WXRepImgTextReply>();

            if (imgTextReply != null)
            {
                //将当前图文设置在第一个位置
                imgTextReplys.Add(imgTextReply);

                //获取多图文id
                long[] ids = StringHelper.StringToLongArray(imgTextReply.quote_detailsIds);

                //获取相关多图文信息
                imgTextReplys.AddRange(GetTextReplysByIds(ids));

                foreach (ImgTextReply it in imgTextReplys)
                {
                    //微信多图文
                    WXRepImgTextReply wxRepImgText = new WXRepImgTextReply();

                    //标题
                    wxRepImgText.Title = it.title;

                    //图文消息描述
                    wxRepImgText.Description = it.introduction;

                    //图片链接
                    wxRepImgText.PicUrl = ServiceIoc.Get <ImgService>().GetImgUrl(ImgType.ImgTextReply_Title, it.id);

                    //如果是图文详情
                    if (it.content_type == MsgContentType.ImgTextDetails)
                    {
                        it.content_value = it.id.ToString();
                    }

                    string url = MsgContentType.GetLinkByType(account, it.content_type, request.FromUserName, it.content_value);
                    //if (it.content_type == MsgContentType.ImgTextDetails)
                    //{
                    //    url = MsgContentType.GetLinkByType(account, webSite.id, it.content_type, request.FromUserName, it.content_value) + "&title=" + it.title;
                    //}
                    //else
                    //{
                    //    url = MsgContentType.GetLinkByType(account, webSite.id, it.content_type, request.FromUserName, it.content_value);
                    //}

                    //链接地址
                    wxRepImgText.Url = url.Trim();

                    wXRepImgTextReply.Add(wxRepImgText);

                    //保存图文统计信息
                    //StatsImgTexts statsImgTexts = new StatsImgTexts();
                    //statsImgTexts.req_datetime = DateTime.Now;
                    //statsImgTexts.title = it.title;
                    //statsImgTexts.sta_state = 1;
                    //ServiceIoc.Get<StatsImgTextsService>().Save(statsImgTexts);
                }

                return(GetWXResponseMsg(request, wXRepImgTextReply));
            }
            return(string.Empty);
        }