コード例 #1
0
ファイル: MpDataSyncApi.cs プロジェクト: xjh1230/sanfengli
        /// <summary>
        /// 将原公众号菜单按钮调整为自定义click类型
        /// </summary>
        /// <param name="item"></param>
        private Button ChangeButton(MpButtonJsonResult item)
        {
            //需要转换的按钮类型
            string        btnType  = item.type;
            List <string> typeList = new List <string>()
            {
                "img", "news", "text", "voice", "video"
            };

            if (typeList.Contains(btnType.ToLower()))
            {
                item.type = "click";
                item.key  = Guid.NewGuid().ToString("N");
            }
            Button btn = new Button()
            {
                name      = item.name,
                type      = item.type,
                key       = item.key,
                replyType = btnType
            };

            switch (btnType)
            {
            case "text":
                btn.replyContent = EConvert.DConvertEmojiHtml(item.value).UrlEncode().Replace("+", "%20");
                break;

            case "view":
                btn.replyContent = item.url;
                break;

            default:
                btn.replyContent = item.value;
                break;
            }
            if (btn.type == "click")
            {
                MpEventBll.SaveEventInfo(new mpeventreply()
                {
                    EventKey     = item.key,
                    EventType    = "click",
                    ReplyType    = btnType,
                    ReplyContent = item.value
                });
            }
            return(btn);
        }
コード例 #2
0
ファイル: MpDataSyncApi.cs プロジェクト: xjh1230/sanfengli
        public bool SaveMsgReplyData()
        {
            var mpMsgData = AutoReplyApi.GetCurrentAutoreplyInfo(BaseClass.AppId);

            if (mpMsgData.errcode == 0)
            {
                //初始化关注回复
                if (mpMsgData.add_friend_autoreply_info != null)
                {
                    var sereply = mpMsgData.add_friend_autoreply_info;
                    if (sereply.type.ToString() == "text")
                    {
                        sereply.content = EConvert.DConvertEmojiHtml(sereply.content).UrlEncode().Replace("+", "%20");
                    }
                    MpEventBll.SaveEventInfo(new mpeventreply()
                    {
                        EventType    = WxEventTypeEnum.subscribe.ToString(),
                        EventKey     = "ych_subscribe",
                        ReplyType    = sereply.type.ToString(),
                        ReplyContent = sereply.content,
                    });
                }
                //初始化自动消息回复
                if (mpMsgData.message_default_autoreply_info != null)
                {
                    var autoreply = mpMsgData.message_default_autoreply_info;
                    if (autoreply.type.ToString() == "text")
                    {
                        autoreply.content = EConvert.DConvertEmojiHtml(autoreply.content).UrlEncode().Replace("+", "%20");
                    }
                    MpEventBll.SaveEventInfo(new mpeventreply()
                    {
                        EventType    = WxEventTypeEnum.automsg.ToString(),
                        EventKey     = "ych_automsg",
                        ReplyType    = autoreply.type.ToString(),
                        ReplyContent = autoreply.content
                    });
                }
                //初始化关键字回复
                if (mpMsgData.keyword_autoreply_info?.list != null && mpMsgData.keyword_autoreply_info.list.Count > 0)
                {
                    mpMsgData.keyword_autoreply_info.list.Reverse();
                    foreach (var ruleItem in mpMsgData.keyword_autoreply_info.list)
                    {
                        var dto = new MsgReplyResult
                        {
                            Msg =
                            {
                                RuleName  = ruleItem.rule_name,
                                ReplyMode = ruleItem.reply_mode.ToString()
                            }
                        };
                        if (ruleItem.keyword_list_info != null && ruleItem.keyword_list_info.Count > 0)
                        {
                            foreach (var keyItem in ruleItem.keyword_list_info)
                            {
                                mpmsgreplykey key = new mpmsgreplykey
                                {
                                    KeyVal    = keyItem.content,
                                    MatchMode = keyItem.match_mode.ToString()
                                };
                                dto.Keys.Add(key);
                            }
                        }
                        if (ruleItem.reply_list_info != null && ruleItem.reply_list_info.Count > 0)
                        {
                            foreach (var contentItem in ruleItem.reply_list_info)
                            {
                                if (contentItem.type.ToString() == "text")
                                {
                                    contentItem.content = EConvert.DConvertEmojiHtml(contentItem.content).UrlEncode().Replace("+", "%20");
                                }
                                mpmsgreplycontent content = new mpmsgreplycontent
                                {
                                    ReplyType    = contentItem.type.ToString(),
                                    ReplyContent = contentItem.content
                                };
                                dto.Contents.Add(content);
                            }
                        }
                        MsgReplyBll.SaveMsgRule(dto);
                    }
                }
            }
            return(true);
        }