public static RequestApiResult <WeixinCreateShortUrlResult> GetShortUrl(string access_token, string longUrl)
        {
            WeixinCreateShortUrlArgs args = new WeixinCreateShortUrlArgs();

            args.LongUrl = longUrl;

            RequestApiResult <WeixinCreateShortUrlResult> result =
                new RequestApiResult <WeixinCreateShortUrlResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(args);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinCreateShortUrlResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 删除分组
        /// 注意本接口是删除一个用户分组,删除分组后,所有该分组内的用户自动进入默认分组。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static RequestApiResult Remove(string access_token, int groupId)
        {
            RequestApiResult result = new RequestApiResult();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/groups/delete?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(new { group = new { id = groupId } });

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            //微信接口的分组部分有问题
            //成功删除分组后,有时返回空串,有时返回40050
            //此处暂不判断其返回值了,默认成功
            //if (result.HttpRequestResult.Success)
            //{
            //    result.ApiError = WeixinApiHelper.Parse(result.HttpRequestResult.Content);
            //}
            result.ApiError = new WeixinApiErrorResult();

            return(result);
        }
        /// <summary>
        /// 获取永久图文消息素材列表
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinGetArticleMaterialListResult> GetArticleMaterialList(string access_token, WeixinGetMaterialListArgs args)
        {
            args.Type = MaterialType.News;

            RequestApiResult <WeixinGetArticleMaterialListResult> result =
                new RequestApiResult <WeixinGetArticleMaterialListResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(args);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinGetArticleMaterialListResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
        /// <summary>
        /// 根据分组进行群发【订阅号与服务号认证后均可用】
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinGroupMessageSendAllResult> SendAll(string access_token, WeixinGroupMessageSendAllArgs args)
        {
            /*
             * 此处返回的JSON又傻逼一样的和其它接口不同
             * {
             *     "errcode":0,
             *     "errmsg":"send job submission success",
             *     "msg_id":34182,
             *     "msg_data_id": 206227730
             *  }
             *
             */

            RequestApiResult <WeixinGroupMessageSendAllResult> result =
                new RequestApiResult <WeixinGroupMessageSendAllResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(args);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinGroupMessageSendAllResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
        /// <summary>
        /// 删除永久素材
        /// 可以删除公众号在公众平台官网素材管理模块中新建的图文消息、语音、视频等素材
        /// http://mp.weixin.qq.com/wiki/17/630699b9593f9a53725c26719d522101.html
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="mediaId"></param>
        /// <returns></returns>
        public static RequestApiResult RemoveMaterial(string access_token, string mediaId)
        {
            RequestApiResult result      = new RequestApiResult();
            HttpRequestArgs  requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(new { media_id = mediaId });

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiError = WeixinApiHelper.Parse(result.HttpRequestResult.Content);
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// 自定义菜单创建接口
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="accessToken"></param>
        public static RequestApiResult Create(ButtonWrapper menu, string accessToken)
        {
            RequestApiResult result = new RequestApiResult();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method  = "POST";
            requestArgs.Url     = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken;
            requestArgs.Content = JsonConvert.SerializeObject(menu);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiError = WeixinApiHelper.Parse(result.HttpRequestResult.Content);
            }

            return(result);
        }
        /// <summary>
        /// 修改永久图文素材
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult UpdateArticleMaterial(string access_token, WeixinUpdateArticleMaterialArgs args)
        {
            RequestApiResult result      = new RequestApiResult();
            HttpRequestArgs  requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/material/update_news?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(args);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiError = WeixinApiHelper.Parse(result.HttpRequestResult.Content);
            }

            return(result);
        }
        /// <summary>
        /// 上传图文消息内的图片获取URL
        /// 请注意,在图文消息的具体内容中,将过滤外部的图片链接,开发者可以通过下述接口上传图片得到URL,放到图文内容中使用。
        /// http://mp.weixin.qq.com/wiki/10/10ea5a44870f53d79449290dfd43d006.html
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="file"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinUploadImgResult> UploadImg(string access_token, string file)
        {
            RequestApiResult <WeixinUploadImgResult> result = new RequestApiResult <WeixinUploadImgResult>();
            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token={0}", access_token);
            requestArgs.File = file;

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinUploadImgResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #9
0
        /// <summary>
        /// 发消息
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult Send(string access_token, KFMessageBase message)
        {
            RequestApiResult result = new RequestApiResult();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(message);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiError = WeixinApiHelper.Parse(result.HttpRequestResult.Content);
            }

            return(result);
        }
Пример #10
0
        /// <summary>
        /// 批量移动用户分组
        /// 用户唯一标识符openid的列表(size不能超过50)
        /// 如果仅传一个不存在的OpenId,微信API会返回空串
        /// 如果用户列表中的OpenId,有存在的,有不存在的,则返回正常OK的json
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult SetUserListGroup(string access_token, WeixinSetUserListGroupArgs args)
        {
            RequestApiResult result = new RequestApiResult();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/groups/members/batchupdate?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(args);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiError = WeixinApiHelper.Parse(result.HttpRequestResult.Content);
            }

            return(result);
        }
        /// <summary>
        /// 新增永久素材
        /// http://mp.weixin.qq.com/wiki/0/21cad57369e3652f6be542c1e3a531ec.html
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="file"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinAddMaterialResult> AddNormalMaterial(string access_token, string file, MaterialType type)
        {
            RequestApiResult <WeixinAddMaterialResult> result = new RequestApiResult <WeixinAddMaterialResult>();
            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={0}&type={1}",
                access_token, EnumHelper.GetEnumMemberValue(type));
            requestArgs.File = file;

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinAddMaterialResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #12
0
        /// <summary>
        /// 独立运行时获取网页授权access token
        /// http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="appSecret"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinWebAccessTokenResult> GetWebAccessToken(string appid, string appSecret, string code)
        {
            RequestApiResult <WeixinWebAccessTokenResult> result =
                new RequestApiResult <WeixinWebAccessTokenResult>();

            HttpRequestArgs args = new HttpRequestArgs();

            args.Method = "GET";
            args.Url    = String.Format(
                "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code",
                appid, appSecret, code);

            result.HttpRequestResult = _httpService.Request(args);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinWebAccessTokenResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #13
0
        public static RequestApiResult <WeixinGetJsApiTicketResult> GetJsApiTicket(string accessToken)
        {
            RequestApiResult <WeixinGetJsApiTicketResult> result =
                new RequestApiResult <WeixinGetJsApiTicketResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "GET";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", accessToken);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinGetJsApiTicketResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #14
0
        /// <summary>
        /// 获取access token
        /// http://mp.weixin.qq.com/wiki/2/88b2bf1265a707c031e51f26ca5e6512.html
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="appSecret"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinAccessTokenResult> GetAccessToken(string appid, string appSecret)
        {
            RequestApiResult <WeixinAccessTokenResult> result =
                new RequestApiResult <WeixinAccessTokenResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "GET";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}",
                appid, appSecret);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinAccessTokenResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #15
0
        /// <summary>
        /// 查询用户所在分组
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinGetUserGroupIdResult> GetUserGroupId(string access_token, string openid)
        {
            RequestApiResult <WeixinGetUserGroupIdResult> result =
                new RequestApiResult <WeixinGetUserGroupIdResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/groups/getid?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(new { openid = openid });

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinGetUserGroupIdResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #16
0
        /// <summary>
        /// 创建二维码ticket
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinCreateQRCodeResult> Create(string access_token, WeixinCreateQRCodeArgs args)
        {
            RequestApiResult <WeixinCreateQRCodeResult> result =
                new RequestApiResult <WeixinCreateQRCodeResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(args);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinCreateQRCodeResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
        /// <summary>
        /// 查询群发消息发送状态【订阅号与服务号认证后均可用】
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinGroupMessageGetStatusResult> GetStatus(string access_token, string msgId)
        {
            RequestApiResult <WeixinGroupMessageGetStatusResult> result =
                new RequestApiResult <WeixinGroupMessageGetStatusResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "POST";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(new { msg_id = msgId });

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinGroupMessageGetStatusResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #18
0
        /// <summary>
        /// 获取用户列表
        /// 关注者列表由一串OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。
        /// 一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
        /// http://mp.weixin.qq.com/wiki/11/434109e8de46b3968639217bbcb16c2f.html
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="next_openid">第一个拉取的OPENID,不填默认从头开始拉取</param>
        /// <returns></returns>
        public static RequestApiResult <WeixinGetUserListResult> GetUserList(string access_token, string next_openid)
        {
            RequestApiResult <WeixinGetUserListResult> result =
                new RequestApiResult <WeixinGetUserListResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "GET";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}",
                access_token, next_openid);

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinGetUserListResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }
Пример #19
0
        /// <summary>
        /// 获取标签下粉丝列表
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinGetTagUserListResult> GetTagUserList(
            string access_token, int tagId, string next_openid)
        {
            RequestApiResult <WeixinGetTagUserListResult> result =
                new RequestApiResult <WeixinGetTagUserListResult>();

            HttpRequestArgs requestArgs = new HttpRequestArgs();

            requestArgs.Method = "GET";
            requestArgs.Url    = String.Format(
                "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token={0}", access_token);
            requestArgs.Content = JsonConvert.SerializeObject(new { tagid = tagId, next_openid = next_openid });

            result.HttpRequestArgs   = requestArgs;
            result.HttpRequestResult = _httpService.Request(requestArgs);

            if (result.HttpRequestResult.Success)
            {
                result.ApiResult = WeixinApiHelper.Parse <WeixinGetTagUserListResult>(
                    result.HttpRequestResult.Content, ref result.ApiError);
            }

            return(result);
        }