/// <summary>
        /// 预览接口【订阅号与服务号认证后均可用】
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="mediaId">用于群发的消息的media_id</param>
        /// <param name="type"></param>
        /// <param name="openId">接收消息用户对应该公众号的openid</param>
        /// 注意mediaId和content不可同时为空
        /// <returns></returns>
        public static SendResult SendGroupMessagePreview(string accessToken, GroupMessageType type, string mediaId, string openId)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}";

            BaseGroupMessageDataPreview baseData = null;
            switch (type)
            {
                case GroupMessageType.image:
                    baseData = new GroupMessagePreview_ImageData()
                    {
                        touser = openId,
                        image = new GroupMessagePreview_MediaId()
                        {
                            media_id = mediaId
                        },
                        msgtype = "image"
                    };
                    break;
                case GroupMessageType.voice:
                    baseData = new GroupMessagePreview_VoiceData()
                    {
                        touser = openId,
                        voice = new GroupMessagePreview_MediaId()
                        {
                            media_id = mediaId
                        },
                        msgtype = "voice"
                    };
                    break;
                case GroupMessageType.mpnews:
                    baseData = new GroupMessagePreview_MpNewsData()
                    {
                        touser = openId,
                        mpnews = new GroupMessagePreview_MediaId()
                        {
                            media_id = mediaId
                        },
                        msgtype = "mpnews"
                    };
                    break;
                case GroupMessageType.video:
                    baseData = new GroupMessagePreview_MpVideoData()
                    {
                        touser = openId,
                        mpvideo = new GroupMessagePreview_MediaId()
                        {
                            media_id = mediaId
                        },
                        msgtype = "mpvideo"
                    };
                    break;
                case GroupMessageType.text:
                    throw new Exception("发送文本信息请使用SendTextGroupMessagePreview方法。");
                    break;
                default:
                    throw new Exception("参数错误。");
                    break;
            }
            return CommonJsonSend.Send<SendResult>(accessToken, urlFormat, baseData);
        }
示例#2
0
        /// <summary>
        /// 预览接口【订阅号与服务号认证后均可用】
        /// 注意:openId与wxName两者任选其一,同时传入以wxName优先
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="value">群发媒体消息时为media_id,群发文本信息为content</param>
        /// <param name="type"></param>
        /// <param name="openId">接收消息用户对应该公众号的openid</param>
        /// <param name="wxName">接收消息用户的微信号</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static SendResult SendGroupMessagePreview(string accessTokenOrAppId, GroupMessageType type, string value, string openId, string wxName = null, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}";

                BaseGroupMessageDataPreview baseData = null;
                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessagePreview_ImageData()
                    {
                        touser = openId,
                        towxname = wxName,
                        image = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessagePreview_VoiceData()
                    {
                        touser = openId,
                        towxname = wxName,
                        voice = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessagePreview_MpNewsData()
                    {
                        touser = openId,
                        towxname = wxName,
                        mpnews = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.video:
                    baseData = new GroupMessagePreview_MpVideoData()
                    {
                        touser = openId,
                        towxname = wxName,
                        mpvideo = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpvideo"
                    };
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessagePreview_TextData()
                    {
                        touser = openId,
                        towxname = wxName,
                        text = new GroupMessagePreview_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                case GroupMessageType.wxcard:
                    throw new Exception("发送卡券息请使用WxCardGroupMessagePreview方法。");
                    break;

                default:
                    throw new Exception("参数错误。");
                    break;
                }
                return CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
        /// <summary>
        /// 预览接口【订阅号与服务号认证后均可用】
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="mediaId">用于群发的消息的media_id</param>
        /// <param name="type"></param>
        /// <param name="openId">接收消息用户对应该公众号的openid</param>
        /// 注意mediaId和content不可同时为空
        /// <returns></returns>
        public static SendResult SendGroupMessagePreview(string accessToken, GroupMessageType type, string mediaId, string openId)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}";

            BaseGroupMessageDataPreview baseData = null;

            switch (type)
            {
            case GroupMessageType.image:
                baseData = new GroupMessagePreview_ImageData()
                {
                    touser = openId,
                    image  = new GroupMessagePreview_MediaId()
                    {
                        media_id = mediaId
                    },
                    msgtype = "image"
                };
                break;

            case GroupMessageType.voice:
                baseData = new GroupMessagePreview_VoiceData()
                {
                    touser = openId,
                    voice  = new GroupMessagePreview_MediaId()
                    {
                        media_id = mediaId
                    },
                    msgtype = "voice"
                };
                break;

            case GroupMessageType.mpnews:
                baseData = new GroupMessagePreview_MpNewsData()
                {
                    touser = openId,
                    mpnews = new GroupMessagePreview_MediaId()
                    {
                        media_id = mediaId
                    },
                    msgtype = "mpnews"
                };
                break;

            case GroupMessageType.video:
                baseData = new GroupMessagePreview_MpVideoData()
                {
                    touser  = openId,
                    mpvideo = new GroupMessagePreview_MediaId()
                    {
                        media_id = mediaId
                    },
                    msgtype = "mpvideo"
                };
                break;

            case GroupMessageType.text:
                throw new Exception("发送文本信息请使用SendTextGroupMessagePreview方法。");
                break;

            default:
                throw new Exception("参数错误。");
                break;
            }
            return(CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData));
        }
示例#4
0
        /// <summary>
        /// 预览接口【订阅号与服务号认证后均可用】
        /// 注意:openId与wxName两者任选其一,同时传入以wxName优先
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="value">群发媒体消息时为media_id,群发文本信息为content</param>
        /// <param name="type"></param>
        /// <param name="openId">接收消息用户对应该公众号的openid</param>
        /// <param name="wxName">接收消息用户的微信号</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public SendResult SendGroupMessagePreview(GroupMessageType type, string value, string openId, string wxName = null, int timeOut = Config.TIME_OUT)
        {
            var    accessToken = _api.GetAccessToken();
            string url         = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}", accessToken);

            BaseGroupMessageDataPreview baseData = null;

            switch (type)
            {
            case GroupMessageType.image:
                baseData = new GroupMessagePreview_ImageData()
                {
                    touser   = openId,
                    towxname = wxName,
                    image    = new GroupMessagePreview_MediaId()
                    {
                        media_id = value
                    },
                    msgtype = "image"
                };
                break;

            case GroupMessageType.voice:
                baseData = new GroupMessagePreview_VoiceData()
                {
                    touser   = openId,
                    towxname = wxName,
                    voice    = new GroupMessagePreview_MediaId()
                    {
                        media_id = value
                    },
                    msgtype = "voice"
                };
                break;

            case GroupMessageType.mpnews:
                baseData = new GroupMessagePreview_MpNewsData()
                {
                    touser   = openId,
                    towxname = wxName,
                    mpnews   = new GroupMessagePreview_MediaId()
                    {
                        media_id = value
                    },
                    msgtype = "mpnews"
                };
                break;

            case GroupMessageType.video:
                baseData = new GroupMessagePreview_MpVideoData()
                {
                    touser   = openId,
                    towxname = wxName,
                    mpvideo  = new GroupMessagePreview_MediaId()
                    {
                        media_id = value
                    },
                    msgtype = "mpvideo"
                };
                break;

            case GroupMessageType.text:
                baseData = new GroupMessagePreview_TextData()
                {
                    touser   = openId,
                    towxname = wxName,
                    text     = new GroupMessagePreview_Content()
                    {
                        content = value
                    },
                    msgtype = "text"
                };
                break;

            case GroupMessageType.wxcard:
                throw new Exception("发送卡券息请使用WxCardGroupMessagePreview方法。");
                break;

            default:
                throw new Exception("参数错误。");
                break;
            }
            return(Post <SendResult>(url, baseData, timeOut));
        }