123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- #region Apache License Version 2.0
- #endregion Apache License Version 2.0
- using System.Threading.Tasks;
- using Senparc.CO2NET.Extensions;
- using Senparc.NeuChar;
- using Senparc.Weixin.CommonAPIs;
- using Senparc.Weixin.Entities;
- using Senparc.Weixin.HttpUtility;
- using Senparc.Weixin.MP.AdvancedAPIs.Groups;
- using Senparc.Weixin.MP.CommonAPIs;
- namespace Senparc.Weixin.MP.AdvancedAPIs
- {
-
-
-
- public static class GroupsApi
- {
- #region 同步方法
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.Create", true)]
- public static CreateGroupResult Create(string accessTokenOrAppId, string name, int timeOut = Config.TIME_OUT)
- {
- return ApiHandlerWapper.TryCommonApi(accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/create?access_token={0}";
- var data = new
- {
- group = new
- {
- name = name
- }
- };
- return CommonJsonSend.Send<CreateGroupResult>(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.Get", true)]
- public static GroupsJson Get(string accessTokenOrAppId)
- {
- return ApiHandlerWapper.TryCommonApi(accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/get?access_token={0}";
- var url = string.Format(urlFormat, accessToken.AsUrlData());
- return CommonJsonSend.Send< GroupsJson >(null, url, null, CommonJsonSendType.GET);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.GetId", true)]
- public static GetGroupIdResult GetId(string accessTokenOrAppId, string openId, int timeOut = Config.TIME_OUT)
- {
- return ApiHandlerWapper.TryCommonApi(accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/getid?access_token={0}";
- var data = new { openid = openId };
- return CommonJsonSend.Send<GetGroupIdResult>(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.Update", true)]
- public static WxJsonResult Update(string accessTokenOrAppId, int id, string name, int timeOut = Config.TIME_OUT)
- {
- return ApiHandlerWapper.TryCommonApi(accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/update?access_token={0}";
- var data = new
- {
- group = new
- {
- id = id,
- name = name
- }
- };
- return CommonJsonSend.Send(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.MemberUpdate", true)]
- public static WxJsonResult MemberUpdate(string accessTokenOrAppId, string openId, int toGroupId, int timeOut = Config.TIME_OUT)
- {
- return ApiHandlerWapper.TryCommonApi(accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/members/update?access_token={0}";
- var data = new
- {
- openid = openId,
- to_groupid = toGroupId
- };
- return CommonJsonSend.Send(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.BatchUpdate", true)]
- public static WxJsonResult BatchUpdate(string accessTokenOrAppId, int toGroupId, int timeOut = Config.TIME_OUT, params string[] openIds)
- {
- return ApiHandlerWapper.TryCommonApi(accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/members/batchupdate?access_token={0}";
- var data = new
- {
- openid_list = openIds,
- to_groupid = toGroupId
- };
- return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST, timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.Delete", true)]
- public static WxJsonResult Delete(string accessTokenOrAppId, int groupId, int timeOut = Config.TIME_OUT)
- {
- return ApiHandlerWapper.TryCommonApi(accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/delete?access_token={0}";
- var data = new
- {
- group = new
- {
- id = groupId
- }
- };
- return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST, timeOut);
- }, accessTokenOrAppId);
- }
- #endregion
- #if !NET35 && !NET40
- #region 异步方法
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.CreateAsync", true)]
- public static async Task<CreateGroupResult> CreateAsync(string accessTokenOrAppId, string name, int timeOut = Config.TIME_OUT)
- {
- return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/create?access_token={0}";
- var data = new
- {
- group = new
- {
- name = name
- }
- };
- return await CommonJsonSend.SendAsync<CreateGroupResult>(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.GetAsync", true)]
- public static async Task<GroupsJson> GetAsync(string accessTokenOrAppId)
- {
- return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/get?access_token={0}";
- var url = string.Format(urlFormat, accessToken.AsUrlData());
- return await CommonJsonSend.SendAsync<GroupsJson>(null, url, null, CommonJsonSendType.GET);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.GetIdAsync", true)]
- public static async Task<GetGroupIdResult> GetIdAsync(string accessTokenOrAppId, string openId, int timeOut = Config.TIME_OUT)
- {
- return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/getid?access_token={0}";
- var data = new { openid = openId };
- return await CommonJsonSend.SendAsync<GetGroupIdResult>(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.UpdateAsync", true)]
- public static async Task<WxJsonResult> UpdateAsync(string accessTokenOrAppId, int id, string name, int timeOut = Config.TIME_OUT)
- {
- return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/update?access_token={0}";
- var data = new
- {
- group = new
- {
- id = id,
- name = name
- }
- };
- return await CommonJsonSend.SendAsync(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.MemberUpdateAsync", true)]
- public static async Task<WxJsonResult> MemberUpdateAsync(string accessTokenOrAppId, string openId, int toGroupId, int timeOut = Config.TIME_OUT)
- {
- return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/members/update?access_token={0}";
- var data = new
- {
- openid = openId,
- to_groupid = toGroupId
- };
- return await CommonJsonSend.SendAsync(accessToken, urlFormat, data, timeOut: timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.BatchUpdateAsync", true)]
- public static async Task<WxJsonResult> BatchUpdateAsync(string accessTokenOrAppId, int toGroupId, int timeOut = Config.TIME_OUT, params string[] openIds)
- {
- return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/members/batchupdate?access_token={0}";
- var data = new
- {
- openid_list = openIds,
- to_groupid = toGroupId
- };
- return await CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST, timeOut);
- }, accessTokenOrAppId);
- }
-
-
-
-
-
-
-
- [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupsApi.DeleteAsync", true)]
- public static async Task<WxJsonResult> DeleteAsync(string accessTokenOrAppId, int groupId, int timeOut = Config.TIME_OUT)
- {
- return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
- {
- var urlFormat = Config.ApiMpHost + "/cgi-bin/groups/delete?access_token={0}";
- var data = new
- {
- group = new
- {
- id = groupId
- }
- };
- return await CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST, timeOut);
- }, accessTokenOrAppId);
- }
- #endregion
- #endif
- }
- }
|