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

            BaseGroupMessageDataPreview baseData = new GroupMessagePreview_TextData()
            {
                touser = openId,
                text   = new GroupMessagePreview_Content()
                {
                    content = content
                },
                msgtype = "text"
            };

            return(CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData));
        }
コード例 #2
0
        /// <summary>
        /// 【异步方法】预览接口【订阅号与服务号认证后均可用】
        /// 注意:openId与wxName两者任选其一,同时传入以wxName优先
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</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 async Task <SendResult> SendGroupMessagePreviewAsync(string accessTokenOrAppId, GroupMessageType type, string value, string openId, string wxName = null, int timeOut = Config.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                string urlFormat = Config.ApiMpHost + "/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方法。");

                default:
                    throw new Exception("参数错误。");
                }
                return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
コード例 #3
0
ファイル: GroupMessageAPI.cs プロジェクト: shifeng744/lst1
        /// <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 accessToken, GroupMessageType type, string value, string openId, string wxName = null)
        {
            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方法。");

            default:
                throw new Exception("参数错误。");
            }
            return(ApiHelper.Post <SendResult>(accessToken, urlFormat, baseData));
        }