ShelfApi.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. 文件名:ShelfApi.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 ShelfApi
  36. {
  37. #region 同步方法
  38. /// <summary>
  39. /// 增加货架
  40. /// </summary>
  41. /// <param name="accessToken"></param>
  42. /// <param name="m1">控件1数据</param>
  43. /// <param name="m2">控件2数据</param>
  44. /// <param name="m3">控件3数据</param>
  45. /// <param name="m4">控件4数据</param>
  46. /// <param name="m5">控件5数据</param>
  47. /// <param name="shelfBanner">货架招牌图片Url</param>
  48. /// <param name="shelfName">货架名称</param>
  49. /// <returns></returns>
  50. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.AddShelves", true)]
  51. public static AddShelfResult AddShelves(string accessToken, M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, string shelfBanner, string shelfName)
  52. {
  53. var urlFormat = Config.ApiMpHost + "/merchant/shelf/add?access_token={0}";
  54. var data = new
  55. {
  56. shelf_data = new
  57. {
  58. module_infos = new object[]
  59. {
  60. m1,
  61. m2,
  62. m3,
  63. m4,
  64. m5
  65. }
  66. },
  67. shelf_banner = shelfBanner,
  68. shelf_name = shelfName
  69. };
  70. return CommonJsonSend.Send<AddShelfResult>(accessToken, urlFormat, data);
  71. }
  72. /// <summary>
  73. /// 删除货架
  74. /// </summary>
  75. /// <param name="accessToken"></param>
  76. /// <param name="shelfId">货架Id</param>
  77. /// <returns></returns>
  78. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.DeleteShelves", true)]
  79. public static WxJsonResult DeleteShelves(string accessToken, int shelfId)
  80. {
  81. var urlFormat = Config.ApiMpHost + "/merchant/shelf/del?access_token={0}";
  82. var data = new
  83. {
  84. shelf_id = shelfId
  85. };
  86. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  87. }
  88. /// <summary>
  89. /// 修改货架
  90. /// </summary>
  91. /// <param name="accessToken"></param>
  92. /// <param name="m1">控件1数据</param>
  93. /// <param name="m2">控件2数据</param>
  94. /// <param name="m3">控件3数据</param>
  95. /// <param name="m4">控件4数据</param>
  96. /// <param name="m5">控件5数据</param>
  97. /// <param name="shelfId">货架Id</param>
  98. /// <param name="shelfBanner">货架招牌图片Url</param>
  99. /// <param name="shelfName">货架名称</param>
  100. /// <returns></returns>
  101. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.ModShelves", true)]
  102. public static WxJsonResult ModShelves(string accessToken, M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, int shelfId, string shelfBanner, string shelfName)
  103. {
  104. var urlFormat = Config.ApiMpHost + "/merchant/shelf/mod?access_token={0}";
  105. var data = new
  106. {
  107. shelf_id = shelfId,
  108. shelf_data = new
  109. {
  110. module_infos = new object[]
  111. {
  112. m1,
  113. m2,
  114. m3,
  115. m4,
  116. m5
  117. }
  118. },
  119. shelf_banner = shelfBanner,
  120. shelf_name = shelfName
  121. };
  122. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  123. }
  124. /// <summary>
  125. /// 获取所有货架
  126. /// </summary>
  127. /// <param name="accessToken"></param>
  128. /// <returns></returns>
  129. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.GetAllShelves", true)]
  130. public static GetAllShelfResult GetAllShelves(string accessToken)
  131. {
  132. var urlFormat = Config.ApiMpHost + "/merchant/shelf/getall?access_token=ACCESS_TOKEN";
  133. return CommonJsonSend.Send<GetAllShelfResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  134. }
  135. /// <summary>
  136. /// 根据货架ID获取货架信息
  137. /// </summary>
  138. /// <param name="accessToken"></param>
  139. /// <param name="shelfId">货架Id</param>
  140. /// <returns></returns>
  141. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.GetByIdShelves", true)]
  142. public static GetByIdShelfResult GetByIdShelves(string accessToken, int shelfId)
  143. {
  144. var urlFormat = Config.ApiMpHost + "/merchant/shelf/getbyid?access_token={0}";
  145. var data = new
  146. {
  147. shelf_id = shelfId
  148. };
  149. return CommonJsonSend.Send<GetByIdShelfResult>(accessToken, urlFormat, data);
  150. }
  151. #endregion
  152. #if !NET35 && !NET40
  153. #region 异步方法
  154. /// <summary>
  155. /// 【异步方法】增加货架
  156. /// </summary>
  157. /// <param name="accessToken"></param>
  158. /// <param name="m1">控件1数据</param>
  159. /// <param name="m2">控件2数据</param>
  160. /// <param name="m3">控件3数据</param>
  161. /// <param name="m4">控件4数据</param>
  162. /// <param name="m5">控件5数据</param>
  163. /// <param name="shelfBanner">货架招牌图片Url</param>
  164. /// <param name="shelfName">货架名称</param>
  165. /// <returns></returns>
  166. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.AddShelvesAsync", true)]
  167. public static async Task<AddShelfResult> AddShelvesAsync(string accessToken, M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, string shelfBanner, string shelfName)
  168. {
  169. var urlFormat = Config.ApiMpHost + "/merchant/shelf/add?access_token={0}";
  170. var data = new
  171. {
  172. shelf_data = new
  173. {
  174. module_infos = new object[]
  175. {
  176. m1,
  177. m2,
  178. m3,
  179. m4,
  180. m5
  181. }
  182. },
  183. shelf_banner = shelfBanner,
  184. shelf_name = shelfName
  185. };
  186. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<AddShelfResult>(accessToken, urlFormat, data);
  187. }
  188. /// <summary>
  189. /// 【异步方法】删除货架
  190. /// </summary>
  191. /// <param name="accessToken"></param>
  192. /// <param name="shelfId">货架Id</param>
  193. /// <returns></returns>
  194. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.DeleteShelvesAsync", true)]
  195. public static async Task<WxJsonResult> DeleteShelvesAsync(string accessToken, int shelfId)
  196. {
  197. var urlFormat = Config.ApiMpHost + "/merchant/shelf/del?access_token={0}";
  198. var data = new
  199. {
  200. shelf_id = shelfId
  201. };
  202. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  203. }
  204. /// <summary>
  205. /// 【异步方法】修改货架
  206. /// </summary>
  207. /// <param name="accessToken"></param>
  208. /// <param name="m1">控件1数据</param>
  209. /// <param name="m2">控件2数据</param>
  210. /// <param name="m3">控件3数据</param>
  211. /// <param name="m4">控件4数据</param>
  212. /// <param name="m5">控件5数据</param>
  213. /// <param name="shelfId">货架Id</param>
  214. /// <param name="shelfBanner">货架招牌图片Url</param>
  215. /// <param name="shelfName">货架名称</param>
  216. /// <returns></returns>
  217. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.ModShelvesAsync", true)]
  218. public static async Task<WxJsonResult> ModShelvesAsync(string accessToken, M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, int shelfId, string shelfBanner, string shelfName)
  219. {
  220. var urlFormat = Config.ApiMpHost + "/merchant/shelf/mod?access_token={0}";
  221. var data = new
  222. {
  223. shelf_id = shelfId,
  224. shelf_data = new
  225. {
  226. module_infos = new object[]
  227. {
  228. m1,
  229. m2,
  230. m3,
  231. m4,
  232. m5
  233. }
  234. },
  235. shelf_banner = shelfBanner,
  236. shelf_name = shelfName
  237. };
  238. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  239. }
  240. /// <summary>
  241. /// 【异步方法】获取所有货架
  242. /// </summary>
  243. /// <param name="accessToken"></param>
  244. /// <returns></returns>
  245. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.GetAllShelvesAsync", true)]
  246. public static async Task<GetAllShelfResult> GetAllShelvesAsync(string accessToken)
  247. {
  248. var urlFormat = Config.ApiMpHost + "/merchant/shelf/getall?access_token=ACCESS_TOKEN";
  249. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetAllShelfResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  250. }
  251. /// <summary>
  252. /// 【异步方法】根据货架ID获取货架信息
  253. /// </summary>
  254. /// <param name="accessToken"></param>
  255. /// <param name="shelfId">货架Id</param>
  256. /// <returns></returns>
  257. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ShelfApi.GetByIdShelvesAsync", true)]
  258. public static async Task<GetByIdShelfResult> GetByIdShelvesAsync(string accessToken, int shelfId)
  259. {
  260. var urlFormat = Config.ApiMpHost + "/merchant/shelf/getbyid?access_token={0}";
  261. var data = new
  262. {
  263. shelf_id = shelfId
  264. };
  265. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetByIdShelfResult>(accessToken, urlFormat, data);
  266. }
  267. #endregion
  268. #endif
  269. }
  270. }