Esempio n. 1
0
        /// <summary>
        /// 获取用户分组
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public static async Task <GetGroupIdResult> GetId(string accessToken, string openId)
        {
            var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/getid?access_token={0}";
            var data      = new { openid = openId };

            return(await MessageSend.Send <GetGroupIdResult>(accessToken, urlFormat, data));
        }
Esempio n. 2
0
        /// <summary>
        /// 上传图文消息素材
        /// </summary>
        /// <param name="accessToken">Token</param>
        /// <param name="news">图文消息组</param>
        /// <returns></returns>
        public static async Task <UploadMediaResult> UploadNews(string accessToken, params NewsModel[] news)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token={0}";
            var          data      = new
            {
                articles = news
            };

            return(await MessageSend.Send <UploadMediaResult>(accessToken, urlFormat, data));
        }
Esempio n. 3
0
        /// <summary>
        /// 移动用户分组
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="toGroupId"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> MemberUpdate(string accessToken, string openId, int toGroupId)
        {
            var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token={0}";
            var data      = new
            {
                openid     = openId,
                to_groupid = toGroupId
            };

            return(await MessageSend.Send(accessToken, urlFormat, data));
        }
        /// <summary>
        /// 删除群发消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="mediaId">发送出去的消息ID</param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> DeleteSendMessage(string accessToken, string mediaId)
        {
            //官方API地址为https://api.weixin.qq.com//cgi-bin/message/mass/delete?access_token={0},应该是多了一个/
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token={0}";

            var data = new
            {
                msgid = mediaId
            };

            return(await MessageSend.Send <WeixinErrorJson>(accessToken, urlFormat, data));
        }
Esempio n. 5
0
        /// <summary>
        /// 创建分组
        /// </summary>
        /// <returns></returns>
        public static async Task <CreateGroupResult> Create(string accessToken, string name)
        {
            var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token={0}";
            var data      = new
            {
                group = new
                {
                    name = name
                }
            };

            return(await MessageSend.Send <CreateGroupResult>(accessToken, urlFormat, data));
        }
Esempio n. 6
0
        /// <summary>
        /// 发送语音消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="mediaId"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendVoice(string accessToken, string openId, string mediaId)
        {
            var data = new
            {
                touser  = openId,
                msgtype = "voice",
                voice   = new
                {
                    media_id = mediaId
                }
            };

            return(await MessageSend.Send(accessToken, WeixinApiUrlPattern, data));
        }
Esempio n. 7
0
        /// <summary>
        /// 发送文本信息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendText(string accessToken, string openId, string content)
        {
            var data = new
            {
                touser  = openId,
                msgtype = "text",
                text    = new
                {
                    content = content
                }
            };

            return(await MessageSend.Send(accessToken, WeixinApiUrlPattern, data));
        }
Esempio n. 8
0
        /// <summary>
        /// 发送语音消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openID"></param>
        /// <param name="mediaID"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendVoice(string accessToken, string openID, string mediaID)
        {
            var data = new
            {
                touser  = openID,
                msgtype = "voice",
                voice   = new
                {
                    media_id = mediaID
                }
            };

            return(await MessageSend.Send(accessToken, "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", data));
        }
Esempio n. 9
0
        /// <summary>
        /// 创建分组
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="id"></param>
        /// <param name="name">分组名字(30个字符以内)</param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> Update(string accessToken, int id, string name)
        {
            var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/update?access_token={0}";
            var data      = new
            {
                group = new
                {
                    id   = id,
                    name = name
                }
            };

            return(await MessageSend.Send(accessToken, urlFormat, data));
        }
Esempio n. 10
0
        /// <summary>
        /// 根据OpenId进行群发
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="mediaId">用于群发的消息的media_id</param>
        /// <param name="openIds">openId字符串数组</param>
        /// <returns></returns>
        public static async Task <SendResult> SendGroupMessageByOpenId(string accessToken, string mediaId, params string[] openIds)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}";

            var data = new
            {
                touser = openIds,
                mpnews = new
                {
                    media_id = mediaId
                },
                msgtype = "mpnews"
            };

            return(await MessageSend.Send <SendResult>(accessToken, urlFormat, data));
        }
Esempio n. 11
0
        /// <summary>
        /// 发送文本消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openID"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendText(string accessToken, string openID, string content)
        {
            var data = new
            {
                touser  = openID,
                msgtype = "text",
                text    = new
                {
                    content = content
                }
            };

            return(await MessageSend.Send(accessToken,
                                          "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}",
                                          data));
        }
Esempio n. 12
0
        /// <summary>
        /// 创建永久二维码(字符串参数值)
        /// </summary>
        /// <param name="expireSeconds">该二维码有效时间,以秒为单位。 最大不超过1800。0时为永久二维码</param>
        /// <param name="sceneId">场景值ID,临时二维码时为32位整型,永久二维码时最大值为1000</param>
        /// <returns></returns>
        public static async Task <CreateQrCodeResult> Create(string accessToken, string actionName, string sceneStr)
        {
            var    urlFormat = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}";
            object data      = new
            {
                action_name = "QR_LIMIT_STR_SCENE",
                action_info = new
                {
                    scene = new
                    {
                        scene_str = sceneStr
                    }
                }
            };

            return(await MessageSend.Send <CreateQrCodeResult>(accessToken, urlFormat, data));
        }
Esempio n. 13
0
        /// <summary>
        /// 根据分组进行群发
        ///
        /// 请注意:
        /// 1、该接口暂时仅提供给已微信认证的服务号
        /// 2、虽然开发者使用高级群发接口的每日调用限制为100次,但是用户每月只能接收4条,请小心测试
        /// 3、无论在公众平台网站上,还是使用接口群发,用户每月只能接收4条群发消息,多于4条的群发将对该用户发送失败。
        ///
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="groupId">群发到的分组的group_id</param>
        /// <param name="mediaId">用于群发的消息的media_id</param>
        /// <returns></returns>
        public static async Task <SendResult> SendGroupMessageByGroupId(string accessToken, string groupId, string mediaId)
        {
            const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}";
            var          data      = new
            {
                filter = new
                {
                    group_id = groupId
                },
                mpnews = new
                {
                    media_id = mediaId
                },
                msgtype = "mpnews"
            };

            return(await MessageSend.Send <SendResult>(accessToken, urlFormat, data));
        }
Esempio n. 14
0
        /// <summary>
        /// 发送音乐消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="title">音乐标题(非必须)</param>
        /// <param name="description">音乐描述(非必须)</param>
        /// <param name="musicUrl">音乐链接</param>
        /// <param name="hqMusicUrl">高品质音乐链接,wifi环境优先使用该链接播放音乐</param>
        /// <param name="thumbMediaId">视频缩略图的媒体ID</param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendMusic(string accessToken, string openId, string title, string description,
                                                             string musicUrl, string hqMusicUrl, string thumbMediaId)
        {
            var data = new
            {
                touser  = openId,
                msgtype = "music",
                music   = new
                {
                    title          = title,
                    description    = description,
                    musicurl       = musicUrl,
                    hqmusicurl     = hqMusicUrl,
                    thumb_media_id = thumbMediaId
                }
            };

            return(await MessageSend.Send(accessToken, WeixinApiUrlPattern, data));
        }
Esempio n. 15
0
        /// <summary>
        /// 发送音乐消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openID"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="musicUrl"></param>
        /// <param name="hqMusicUrl"></param>
        /// <param name="thumbMediaID"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendMusic(string accessToken, string openID, string title, string description,
                                                             string musicUrl, string hqMusicUrl, string thumbMediaID)
        {
            var data = new
            {
                touser  = openID,
                msgtype = "music",
                music   = new
                {
                    title          = title,
                    description    = description,
                    musicurl       = musicUrl,
                    hqmusicurl     = hqMusicUrl,
                    thumb_media_id = thumbMediaID
                }
            };

            return(await MessageSend.Send(accessToken, "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", data));
        }
Esempio n. 16
0
        /// <summary>
        /// 发送图文消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openID"></param>
        /// <param name="articles"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendNews(string accessToken, string openID, List <Article> articles)
        {
            var data = new
            {
                touser  = openID,
                msgtype = "news",
                news    = new
                {
                    articles = articles.Select(z => new
                    {
                        title       = z.Title,
                        description = z.Description,
                        url         = z.Url,
                        picurl      = z.PicUrl//图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80
                    }).ToList()
                }
            };

            return(await MessageSend.Send(accessToken, "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", data));
        }
Esempio n. 17
0
        /// <summary>
        /// 发送图文消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="articles"></param>
        /// <returns></returns>
        public static async Task <WeixinErrorJson> SendNews(string accessToken, string openId, List <Article> articles)
        {
            var data = new
            {
                touser  = openId,
                msgtype = "news",
                news    = new
                {
                    articles = articles.Select(z => new
                    {
                        title       = z.Title,
                        description = z.Description,
                        url         = z.Url,
                        picurl      = z.PicUrl//图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80
                    }).ToList()
                }
            };

            return(await MessageSend.Send(accessToken, WeixinApiUrlPattern, data));
        }
Esempio n. 18
0
        /// <summary>
        /// 创建临时/永久二维码(整型参数值)。
        /// </summary>
        /// <param name="expireSeconds">该二维码有效时间,以秒为单位。 最大不超过604800(即7天)。当值0时,将生成永久二维码</param>
        /// <param name="sceneId">场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000</param>
        /// <returns></returns>
        public static async Task <CreateQrCodeResult> Create(string accessToken, int expireSeconds, int sceneId)
        {
            var    urlFormat = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}";
            object data      = null;

            if (expireSeconds > 0)
            {
                data = new
                {
                    expire_seconds = expireSeconds,
                    action_name    = "QR_SCENE",
                    action_info    = new
                    {
                        scene = new
                        {
                            scene_id = sceneId
                        }
                    }
                };
            }
            else
            {
                data = new
                {
                    action_name = "QR_LIMIT_SCENE",
                    action_info = new
                    {
                        scene = new
                        {
                            scene_id = sceneId
                        }
                    }
                };
            }
            return(await MessageSend.Send <CreateQrCodeResult>(accessToken, urlFormat, data));
        }