Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// 扫描二维码关注 同步粉丝信息
        /// </summary>
        /// <param name="open_id"></param>
        /// <param name="phone"></param>
        public void Subscribe(WeChatAccountTmp account, string open_id, long user_id)
        {
            //获取ToKen
            WXAccessTokenCache token = ServiceIoc.Get <WeChatTokenService>().AccessToken(account.appid, account.app_secret);

            //通过微信接口获取
            string WeChatUser_json = WeChatUserHelper.GetWXUserInfo(token.token, open_id);
            //序列化用户
            WeChatUser user = JsonConvert.DeserializeObject <WeChatUser>(WeChatUser_json);

            SyncWXUser(user, user_id);
        }
        /// <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));
        }
        /// <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);
        }
Exemple #5
0
        /// <summary>
        /// 根据信息类型获取对应链接
        /// </summary>
        /// <param name="content_type"></param>
        /// <param name="content_value"></param>
        /// <returns></returns>
        public static string GetLinkByType(WeChatAccountTmp account, int sid, int content_type, string usercode, string content_value)
        {
            StringBuilder sb = new StringBuilder();

            switch (content_type)
            {
            //一键拨号
            case MsgContentType.OneTouchDial:
                return(sb.Append("tel:").Append(content_value).ToString());

            //外链
            case MsgContentType.OutLink:
                return(content_value);

            //图文
            case MsgContentType.ImgTextDetails:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Res"));
                sb.Append("Home/InfoDetails/").Append(content_value).Append(".html");
                return(sb.ToString());

            //导航
            case MsgContentType.Navigation:
                sb.Append("http://api.map.baidu.com/marker?location=");
                if (!string.IsNullOrEmpty(content_value) && content_value.IndexOf(",") != -1 && content_value.IndexOf("#") != -1)
                {
                    int    index    = content_value.IndexOf("#");
                    string location = content_value.Substring(0, index);
                    string address  = content_value.Substring(index + 1, content_value.Length - index - 1);
                    sb.Append(location);
                    sb.Append("&title=").Append(account.nick_name);
                    sb.Append("&content=").Append(address);
                    sb.Append("&output=html");
                }
                return(sb.ToString());

            //微活动
            case MsgContentType.WeiActivity:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));
                sb.Append("weiactivity.aspx?");
                sb.Append("aid=" + account.id + "&");
                sb.Append("bid=" + content_value.Split('#')[0].ToString() + "&");
                sb.Append("code=" + content_value.Split('#')[1].ToString() + "&");
                sb.Append("usercode=" + usercode);
                return(sb.ToString());

            //微相册
            case MsgContentType.WeiAlbum:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));
                sb.Append("Album/Album.aspx?");
                sb.Append("bid=" + content_value);
                return(sb.ToString());

            //微留言
            case MsgContentType.WeiMessage:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));
                sb.Append("weimessage.aspx?");
                sb.Append("code=" + content_value + "&");
                sb.Append("usercode=" + usercode);
                return(sb.ToString());

            //名片
            case MsgContentType.VisitingCard:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));
                sb.Append("Home/MyQRCode");
                return(sb.ToString());

            //完成注册
            case MsgContentType.Register:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));
                sb.Append("Home/Register");
                return(sb.ToString());

            //微商城
            case MsgContentType.WeiMall:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));
                sb.Append("index");
                return(sb.ToString());

            //微预约
            case MsgContentType.WeiResv:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));
                sb.Append("WeiReservation/ResvOrderSubmit.aspx?");
                sb.Append("aid=" + account.id + "&");
                sb.Append("bid=" + content_value);
                return(sb.ToString());

            //微信会员卡
            case MsgContentType.MemberCard:
                sb.Append(ConfigManage.AppSettings <string>("AppSettings:Mob"));

                //存在会员卡号
                if (content_value.IndexOf("#") != -1)
                {
                    sb.Append("MemberCard/Index.aspx?");
                    sb.Append("aid=" + account.id + "&");
                    sb.Append("bid=" + content_value.Split('#')[0] + "&");
                    sb.Append(usercode);
                }    //不存在会员卡号
                else
                {
                    sb.Append("MemberCard/ResvOrderSubmit.aspx?");
                    sb.Append("aid=" + account.id + "&");
                    sb.Append("bid=" + content_value);
                }

                return(sb.ToString());

            default:
                return("");
            }
        }
Exemple #6
0
 public static string GetLinkByType(WeChatAccountTmp account, int sid, int content_type, string content_value)
 {
     return(GetLinkByType(account, sid, content_type, "", content_value));
 }
Exemple #7
0
 public static string GetLinkByType(WeChatAccountTmp account, int content_type, string usercode, string content_value)
 {
     return(GetLinkByType(account, 0, content_type, usercode, content_value));
 }
        /// <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);
        }