Пример #1
0
        /// <summary>
        /// 根据不同类型推送消息
        /// </summary>
        /// <param name="gzhClient"></param>
        /// <param name="gzhSever"></param>
        /// <param name="autoKeyword"></param>
        /// <param name="wxUser"></param>
        /// <returns></returns>
        public async Task <string> SendMsgByPush(string gzhClient, string gzhSever, WxAutoKeywordShow autoKeyword, WxUserInfo wxUser)
        {
            logHelper.Debug("SendMsgByPush:autoPushing:" + autoKeyword.JsonSerialize());
            var dtNow     = DateTime.Now;
            var timeStamp = ComHelper.ConvertDateTimeInt(dtNow);
            var apType    = ComHelper.GetEnumValueByStr <Enum_ApMsgType>(autoKeyword.ContentType);

            switch (apType)
            {
            case Enum_ApMsgType.Text:
            {
                var msg = autoKeyword.TextContent.Replace("{nickname}", wxUser.NickName);
                logHelper.Debug("SendMsgByPush:Msg:" + msg);
                return(await wxAutoComResponse.SendWxText(gzhClient, gzhSever, timeStamp, msg));
            }

            case Enum_ApMsgType.Image:
            {
                var msg = PubMsgApi.BuildImageMsg(gzhClient, gzhSever, autoKeyword.MediaId, timeStamp);
                return(await wxAutoComResponse.AutoMsgResponse(msg));
            }

            case Enum_ApMsgType.Voice:
            {
                var msg = PubMsgApi.BuildVoiceMsg(gzhClient, gzhSever, autoKeyword.MediaId, timeStamp);
                return(await wxAutoComResponse.AutoMsgResponse(msg));
            }

            case Enum_ApMsgType.News:
            {
                var lstArt = await wxAutoConvertHelper.GetResponseWxNews(autoKeyword);

                var msg = PubMsgApi.BuildArticleMsg(gzhClient, gzhSever, timeStamp, lstArt);
                return(await wxAutoComResponse.AutoMsgResponse(msg));
            }

            case Enum_ApMsgType.Video:
            {
                var msg = PubMsgApi.BuildVideoMsg(gzhClient, gzhSever, autoKeyword.MediaId, autoKeyword.VideoTitle, autoKeyword.VideoDescription, timeStamp);
                return(await wxAutoComResponse.AutoMsgResponse(msg));
            }

            case Enum_ApMsgType.BackNews:
            {
                var lstIds = autoKeyword.ArtIds.StrSplitList().Select(x => Convert.ToInt64(x)).ToList();
                if (lstIds.Count > 0)
                {
                    var lstWxArts = await wxAutoConvertHelper.GetResponseBackNews(autoKeyword, lstIds);

                    var msg = PubMsgApi.BuildArticleMsg(gzhClient, gzhSever, timeStamp, lstWxArts);
                    return(await wxAutoComResponse.AutoMsgResponse(msg));
                }
            }
            break;

            case Enum_ApMsgType.RedBag:
            {
                return(await wxAutoConvertHelper.SendResponseRedPack(gzhClient, gzhSever, autoKeyword, dtNow, timeStamp));
            }

            default:
                break;
            }

            return(wxAutoComResponse.ResponseOK());
        }