GroupApi.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #region Apache License Version 2.0
  2. /*----------------------------------------------------------------
  3. Copyright 2019 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  5. except in compliance with the License. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software distributed under the
  8. License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  9. either express or implied. See the License for the specific language governing permissions
  10. and limitations under the License.
  11. Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
  12. ----------------------------------------------------------------*/
  13. #endregion Apache License Version 2.0
  14. /*----------------------------------------------------------------
  15. Copyright (C) 2019 Senparc
  16. 文件名:GroupApi.cs
  17. 文件功能描述:微小店分组接口
  18. 创建标识:Senparc - 20150827
  19. 修改标识;Senparc - 20160719
  20. 修改描述:增加其接口的异步方法
  21. ----------------------------------------------------------------*/
  22. /*
  23. 微小店接口,官方API:http://mp.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1%E5%B0%8F%E5%BA%97%E6%8E%A5%E5%8F%A3
  24. */
  25. using System.Threading.Tasks;
  26. using Senparc.NeuChar;
  27. using Senparc.Weixin.CommonAPIs;
  28. using Senparc.Weixin.Entities;
  29. using Senparc.Weixin.MP.CommonAPIs;
  30. namespace Senparc.Weixin.MP.AdvancedAPIs.MerChant
  31. {
  32. /// <summary>
  33. /// 微小店分组接口
  34. /// </summary>
  35. public static class GroupApi
  36. {
  37. #region 同步方法
  38. /// <summary>
  39. /// 增加分组
  40. /// </summary>
  41. /// <param name="accessToken"></param>
  42. /// <param name="addGroupData">增加分组需要Post的数据</param>
  43. /// <returns></returns>
  44. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.AddGroup", true)]
  45. public static AddGroupResult AddGroup(string accessToken, AddGroupData addGroupData)
  46. {
  47. var urlFormat = Config.ApiMpHost + "/merchant/group/add?access_token={0}";
  48. return CommonJsonSend.Send<AddGroupResult>(accessToken, urlFormat, addGroupData);
  49. }
  50. /// <summary>
  51. /// 删除分组
  52. /// </summary>
  53. /// <param name="accessToken"></param>
  54. /// <param name="groupId">分组Id</param>
  55. /// <returns></returns>
  56. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.DeleteGroup", true)]
  57. public static WxJsonResult DeleteGroup(string accessToken, int groupId)
  58. {
  59. var urlFormat = Config.ApiMpHost + "/merchant/group/del?access_token={0}";
  60. var data = new
  61. {
  62. group_id = groupId
  63. };
  64. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  65. }
  66. /// <summary>
  67. /// 修改分组属性
  68. /// </summary>
  69. /// <param name="accessToken"></param>
  70. /// <param name="propertyModGroup">修改分组属性需要Post的数据</param>
  71. /// <returns></returns>
  72. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.PropertyModGroup", true)]
  73. public static WxJsonResult PropertyModGroup(string accessToken, PropertyModGroup propertyModGroup)
  74. {
  75. var urlFormat = Config.ApiMpHost + "/merchant/group/propertymod?access_token={0}";
  76. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, propertyModGroup);
  77. }
  78. /// <summary>
  79. /// 修改分组商品
  80. /// </summary>
  81. /// <param name="accessToken"></param>
  82. /// <param name="productModGroup">修改分组商品需要Post的数据</param>
  83. /// <returns></returns>
  84. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.ProductModGroup", true)]
  85. public static WxJsonResult ProductModGroup(string accessToken, ProductModGroup productModGroup)
  86. {
  87. var urlFormat = Config.ApiMpHost + "/merchant/group/productmod?access_token={0}";
  88. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, productModGroup);
  89. }
  90. /// <summary>
  91. /// 获取所有分组
  92. /// </summary>
  93. /// <param name="accessToken"></param>
  94. /// <returns></returns>
  95. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.GetAllGroup", true)]
  96. public static GetAllGroup GetAllGroup(string accessToken)
  97. {
  98. var urlFormat = Config.ApiMpHost + "/merchant/group/getall?access_token={0}";
  99. return CommonJsonSend.Send<GetAllGroup>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  100. }
  101. /// <summary>
  102. /// 根据分组ID获取分组信息
  103. /// </summary>
  104. /// <param name="accessToken"></param>
  105. /// <param name="groupId">分组Id</param>
  106. /// <returns></returns>
  107. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.GetByIdGroup", true)]
  108. public static GetByIdGroup GetByIdGroup(string accessToken, int groupId)
  109. {
  110. var urlFormat = Config.ApiMpHost + "/merchant/group/getbyid?access_token={0}";
  111. var data = new
  112. {
  113. group_id = groupId
  114. };
  115. return CommonJsonSend.Send<GetByIdGroup>(accessToken, urlFormat, data);
  116. }
  117. #endregion
  118. #if !NET35 && !NET40
  119. #region 异步方法
  120. /// <summary>
  121. /// 【异步方法】增加分组
  122. /// </summary>
  123. /// <param name="accessToken"></param>
  124. /// <param name="addGroupData">增加分组需要Post的数据</param>
  125. /// <returns></returns>
  126. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.AddGroupAsync", true)]
  127. public static async Task<AddGroupResult> AddGroupAsync(string accessToken, AddGroupData addGroupData)
  128. {
  129. var urlFormat = Config.ApiMpHost + "/merchant/group/add?access_token={0}";
  130. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<AddGroupResult>(accessToken, urlFormat, addGroupData);
  131. }
  132. /// <summary>
  133. /// 【异步方法】删除分组
  134. /// </summary>
  135. /// <param name="accessToken"></param>
  136. /// <param name="groupId">分组Id</param>
  137. /// <returns></returns>
  138. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.DeleteGroupAsync", true)]
  139. public static async Task<WxJsonResult> DeleteGroupAsync(string accessToken, int groupId)
  140. {
  141. var urlFormat = Config.ApiMpHost + "/merchant/group/del?access_token={0}";
  142. var data = new
  143. {
  144. group_id = groupId
  145. };
  146. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  147. }
  148. /// <summary>
  149. /// 【异步方法】修改分组属性
  150. /// </summary>
  151. /// <param name="accessToken"></param>
  152. /// <param name="propertyModGroup">修改分组属性需要Post的数据</param>
  153. /// <returns></returns>
  154. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.PropertyModGroupAsync", true)]
  155. public static async Task<WxJsonResult> PropertyModGroupAsync(string accessToken, PropertyModGroup propertyModGroup)
  156. {
  157. var urlFormat = Config.ApiMpHost + "/merchant/group/propertymod?access_token={0}";
  158. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, propertyModGroup);
  159. }
  160. /// <summary>
  161. /// 【异步方法】修改分组商品
  162. /// </summary>
  163. /// <param name="accessToken"></param>
  164. /// <param name="productModGroup">修改分组商品需要Post的数据</param>
  165. /// <returns></returns>
  166. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.ProductModGroupAsync", true)]
  167. public static async Task<WxJsonResult> ProductModGroupAsync(string accessToken, ProductModGroup productModGroup)
  168. {
  169. var urlFormat = Config.ApiMpHost + "/merchant/group/productmod?access_token={0}";
  170. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, productModGroup);
  171. }
  172. /// <summary>
  173. /// 【异步方法】获取所有分组
  174. /// </summary>
  175. /// <param name="accessToken"></param>
  176. /// <returns></returns>
  177. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.GetAllGroupAsync", true)]
  178. public static async Task<GetAllGroup> GetAllGroupAsync(string accessToken)
  179. {
  180. var urlFormat = Config.ApiMpHost + "/merchant/group/getall?access_token={0}";
  181. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetAllGroup>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  182. }
  183. /// <summary>
  184. /// 【异步方法】根据分组ID获取分组信息
  185. /// </summary>
  186. /// <param name="accessToken"></param>
  187. /// <param name="groupId">分组Id</param>
  188. /// <returns></returns>
  189. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "GroupApi.GetByIdGroupAsync", true)]
  190. public static async Task<GetByIdGroup> GetByIdGroupAsync(string accessToken, int groupId)
  191. {
  192. var urlFormat = Config.ApiMpHost + "/merchant/group/getbyid?access_token={0}";
  193. var data = new
  194. {
  195. group_id = groupId
  196. };
  197. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetByIdGroup>(accessToken, urlFormat, data);
  198. }
  199. #endregion
  200. #endif
  201. }
  202. }