Inheritance: BaseGroupMessageDataByOpenId
Beispiel #1
0
        /// <summary>
        /// 根据OpenID列表群发文本消息【订阅号不可用,服务号认证后可用】
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="content"></param>
        /// <param name="openIds">openId字符串数组</param>
        /// 注意mediaId和content不可同时为空
        /// <returns></returns>
        public static SendResult SendTextGroupMessageByOpenId(string accessToken, string content, params string[] openIds)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}";

            BaseGroupMessageDataByOpenId baseData = new GroupMessageByOpenId_TextData()
            {
                touser = openIds,
                text   = new GroupMessageByOpenId_Content()
                {
                    content = content
                },
                msgtype = "text"
            };

            return(CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData));
        }
        /// <summary>
        /// 根据OpenId进行群发
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId</param>
        /// <param name="type"></param>
        /// <param name="openIds">openId字符串数组</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static SendResult SendGroupMessageByOpenId(string accessToken, GroupMessageType type, string value, int timeOut = Config.TIME_OUT, params string[] openIds)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}";

            BaseGroupMessageDataByOpenId baseData = null;
            switch (type)
            {
                case GroupMessageType.image:
                    baseData = new GroupMessageByOpenId_ImageData()
                    {
                        touser = openIds,
                        image = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;
                case GroupMessageType.voice:
                    baseData = new GroupMessageByOpenId_VoiceData()
                    {
                        touser = openIds,
                        voice = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;
                case GroupMessageType.mpnews:
                    baseData = new GroupMessageByOpenId_MpNewsData()
                    {
                        touser = openIds,
                        mpnews = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;
                case GroupMessageType.wxcard:
                    baseData = new GroupMessageByOpenId_WxCardData()
                    {
                        touser = openIds,
                        wxcard = new GroupMessageByOpenId_WxCard()
                        {
                            card_id = value
                        },
                        msgtype = "wxcard"
                    };
                    break;
                case GroupMessageType.video:
                    throw new Exception("发送视频信息请使用SendVideoGroupMessageByOpenId方法。");
                    break;
                case GroupMessageType.text:
                    baseData = new GroupMessageByOpenId_TextData()
                    {
                        touser = openIds,
                        text = new GroupMessageByOpenId_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;
                default:
                    throw new Exception("参数错误。");
                    break;
            }
            return CommonJsonSend.Send<SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
        }
Beispiel #3
0
        /// <summary>
        /// 根据OpenId进行群发
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId</param>
        /// <param name="type"></param>
        /// <param name="openIds">openId字符串数组</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static SendResult SendGroupMessageByOpenId(string accessTokenOrAppId, GroupMessageType type, string value, int timeOut = Config.TIME_OUT, params string[] openIds)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}";

                BaseGroupMessageDataByOpenId baseData = null;
                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessageByOpenId_ImageData()
                    {
                        touser = openIds,
                        image = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessageByOpenId_VoiceData()
                    {
                        touser = openIds,
                        voice = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessageByOpenId_MpNewsData()
                    {
                        touser = openIds,
                        mpnews = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.wxcard:
                    baseData = new GroupMessageByOpenId_WxCardData()
                    {
                        touser = openIds,
                        wxcard = new GroupMessageByOpenId_WxCard()
                        {
                            card_id = value
                        },
                        msgtype = "wxcard"
                    };
                    break;

                case GroupMessageType.video:
                    throw new Exception("发送视频信息请使用SendVideoGroupMessageByOpenId方法。");
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessageByOpenId_TextData()
                    {
                        touser = openIds,
                        text = new GroupMessageByOpenId_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                default:
                    throw new Exception("参数错误。");
                    break;
                }
                return CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
        /// <summary>
        /// 根据OpenID列表群发文本消息【订阅号不可用,服务号认证后可用】
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="content"></param>
        /// <param name="openIds">openId字符串数组</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// 注意mediaId和content不可同时为空
        /// <returns></returns>
        public static SendResult SendTextGroupMessageByOpenId(string accessToken, string content, int timeOut = Config.TIME_OUT, params string[] openIds)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}";

            BaseGroupMessageDataByOpenId baseData = new GroupMessageByOpenId_TextData()
            {
                touser = openIds,
                text = new GroupMessageByOpenId_Content()
                {
                    content = content
                },
                msgtype = "text"
            };

            return CommonJsonSend.Send<SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
        }