ProductApi.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. 文件名:ProductApi.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 ProductApi
  36. {
  37. #region 同步方法
  38. /// <summary>
  39. /// 增加商品
  40. /// </summary>
  41. /// <param name="accessToken"></param>
  42. /// <param name="addProductData">提交到接口的数据(AddProductData)</param>
  43. /// <returns></returns>
  44. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.AddProduct", true)]
  45. public static AddProductResult AddProduct(string accessToken, AddProductData addProductData)
  46. {
  47. var urlFormat = Config.ApiMpHost + "/merchant/create?access_token={0}";
  48. return CommonJsonSend.Send<AddProductResult>(accessToken, urlFormat, addProductData);
  49. }
  50. /// <summary>
  51. /// 删除商品
  52. /// </summary>
  53. /// <param name="accessToken"></param>
  54. /// <param name="productId">商品的Id</param>
  55. /// <returns></returns>
  56. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.DeleteProduct", true)]
  57. public static WxJsonResult DeleteProduct(string accessToken, string productId)
  58. {
  59. var urlFormat = Config.ApiMpHost + "/merchant/del?access_token={0}";
  60. var data = new
  61. {
  62. product_id = productId
  63. };
  64. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  65. }
  66. /// <summary>
  67. /// 修改商品
  68. /// product_id表示要更新的商品的ID,其他字段说明请参考增加商品接口。
  69. /// 从未上架的商品所有信息均可修改,否则商品的名称(name)、商品分类(category)、商品属性(property)这三个字段不可修改。
  70. /// </summary>
  71. /// <param name="accessToken"></param>
  72. /// <param name="reviseProduct">修改商品的信息</param>
  73. /// <returns></returns>
  74. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.UpDateProduct", true)]
  75. public static WxJsonResult UpDateProduct(string accessToken, UpdateProductData reviseProduct)
  76. {
  77. var urlFormat = Config.ApiMpHost + "/merchant/update?access_token={0}";
  78. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, reviseProduct);
  79. }
  80. /// <summary>
  81. /// 查询商品
  82. /// </summary>
  83. /// <param name="accessToken"></param>
  84. /// <param name="productId">商品的Id</param>
  85. /// <returns></returns>
  86. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetProduct", true)]
  87. public static GetProductResult GetProduct(string accessToken, string productId)
  88. {
  89. var urlFormat = Config.ApiMpHost + "/merchant/get?access_token={0}";
  90. var data = new
  91. {
  92. product_id = productId
  93. };
  94. return CommonJsonSend.Send<GetProductResult>(accessToken, urlFormat, data);
  95. }
  96. /// <summary>
  97. /// 获取指定状态的所有商品
  98. /// </summary>
  99. /// <param name="accessToken"></param>
  100. /// <param name="status">商品状态(0-全部, 1-上架, 2-下架)</param>
  101. /// <returns></returns>
  102. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetByStatus", true)]
  103. public static GetByStatusResult GetByStatus(string accessToken, int status)
  104. {
  105. var urlFormat = Config.ApiMpHost + "/merchant/getbystatus?access_token={0}";
  106. var data = new
  107. {
  108. status = status
  109. };
  110. return CommonJsonSend.Send<GetByStatusResult>(accessToken, urlFormat, data);
  111. }
  112. /// <summary>
  113. /// 商品上下架
  114. /// </summary>
  115. /// <param name="accessToken"></param>
  116. /// <param name="status">商品上下架标识(0-下架, 1-上架)</param>
  117. /// <param name="productId">商品ID</param>
  118. /// <returns></returns>
  119. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.ModProductStatus", true)]
  120. public static WxJsonResult ModProductStatus(string accessToken, int status,string productId)
  121. {
  122. var urlFormat = Config.ApiMpHost + "/merchant/modproductstatus?access_token={0}";
  123. var data = new
  124. {
  125. product_id = productId,
  126. status = status
  127. };
  128. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  129. }
  130. /// <summary>
  131. /// 获取指定分类的所有子分类
  132. /// </summary>
  133. /// <param name="accessToken"></param>
  134. /// <param name="cateId">大分类ID(根节点分类id为1)</param>
  135. /// <returns></returns>
  136. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetSub", true)]
  137. public static GetSubResult GetSub(string accessToken, long cateId)
  138. {
  139. var urlFormat = Config.ApiMpHost + "/merchant/category/getsub?access_token={0}";
  140. var date = new
  141. {
  142. cate_id = cateId
  143. };
  144. return CommonJsonSend.Send<GetSubResult>(accessToken, urlFormat, date);
  145. }
  146. /// <summary>
  147. /// 获取指定子分类的所有SKU
  148. /// </summary>
  149. /// <param name="accessToken"></param>
  150. /// <param name="cateId">商品子分类ID</param>
  151. /// <returns></returns>
  152. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetSku", true)]
  153. public static GetSkuResult GetSku(string accessToken, long cateId)
  154. {
  155. var urlFormat = Config.ApiMpHost + "/merchant/category/getsku?access_token={0}";
  156. var data = new
  157. {
  158. cate_id = cateId
  159. };
  160. return CommonJsonSend.Send<GetSkuResult>(accessToken, urlFormat, data);
  161. }
  162. /// <summary>
  163. /// 获取指定分类的所有属性
  164. /// </summary>
  165. /// <param name="accessToken"></param>
  166. /// <param name="cateId">分类ID</param>
  167. /// <returns></returns>
  168. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetProperty", true)]
  169. public static GetPropertyResult GetProperty(string accessToken, long cateId)
  170. {
  171. var urlFormat = Config.ApiMpHost + "/merchant/category/getproperty?access_token={0}";
  172. var data = new
  173. {
  174. cate_id = cateId
  175. };
  176. return CommonJsonSend.Send<GetPropertyResult>(accessToken, urlFormat, data);
  177. }
  178. #endregion
  179. #if !NET35 && !NET40
  180. #region 异步方法
  181. /// <summary>
  182. /// 【异步方法】增加商品
  183. /// </summary>
  184. /// <param name="accessToken"></param>
  185. /// <param name="addProductData">提交到接口的数据(AddProductData)</param>
  186. /// <returns></returns>
  187. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.AddProductAsync", true)]
  188. public static async Task<AddProductResult> AddProductAsync(string accessToken, AddProductData addProductData)
  189. {
  190. var urlFormat = Config.ApiMpHost + "/merchant/create?access_token={0}";
  191. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<AddProductResult>(accessToken, urlFormat, addProductData);
  192. }
  193. /// <summary>
  194. /// 【异步方法】删除商品
  195. /// </summary>
  196. /// <param name="accessToken"></param>
  197. /// <param name="productId">商品的Id</param>
  198. /// <returns></returns>
  199. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.DeleteProductAsync", true)]
  200. public static async Task<WxJsonResult> DeleteProductAsync(string accessToken, string productId)
  201. {
  202. var urlFormat = Config.ApiMpHost + "/merchant/del?access_token={0}";
  203. var data = new
  204. {
  205. product_id = productId
  206. };
  207. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  208. }
  209. /// <summary>
  210. /// 【异步方法】修改商品
  211. /// product_id表示要更新的商品的ID,其他字段说明请参考增加商品接口。
  212. /// 从未上架的商品所有信息均可修改,否则商品的名称(name)、商品分类(category)、商品属性(property)这三个字段不可修改。
  213. /// </summary>
  214. /// <param name="accessToken"></param>
  215. /// <param name="reviseProduct">修改商品的信息</param>
  216. /// <returns></returns>
  217. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.UpDateProductAsync", true)]
  218. public static async Task<WxJsonResult> UpDateProductAsync(string accessToken, UpdateProductData reviseProduct)
  219. {
  220. var urlFormat = Config.ApiMpHost + "/merchant/update?access_token={0}";
  221. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, reviseProduct);
  222. }
  223. /// <summary>
  224. /// 【异步方法】查询商品
  225. /// </summary>
  226. /// <param name="accessToken"></param>
  227. /// <param name="productId">商品的Id</param>
  228. /// <returns></returns>
  229. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetProductAsync", true)]
  230. public static async Task<GetProductResult> GetProductAsync(string accessToken, string productId)
  231. {
  232. var urlFormat = Config.ApiMpHost + "/merchant/get?access_token={0}";
  233. var data = new
  234. {
  235. product_id = productId
  236. };
  237. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetProductResult>(accessToken, urlFormat, data);
  238. }
  239. /// <summary>
  240. /// 【异步方法】获取指定状态的所有商品
  241. /// </summary>
  242. /// <param name="accessToken"></param>
  243. /// <param name="status">商品状态(0-全部, 1-上架, 2-下架)</param>
  244. /// <returns></returns>
  245. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetByStatusAsync", true)]
  246. public static async Task<GetByStatusResult> GetByStatusAsync(string accessToken, int status)
  247. {
  248. var urlFormat = Config.ApiMpHost + "/merchant/getbystatus?access_token={0}";
  249. var data = new
  250. {
  251. status = status
  252. };
  253. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetByStatusResult>(accessToken, urlFormat, data);
  254. }
  255. /// <summary>
  256. /// 【异步方法】商品上下架
  257. /// </summary>
  258. /// <param name="accessToken"></param>
  259. /// <param name="status">商品上下架标识(0-下架, 1-上架)</param>
  260. /// <param name="productId">商品ID</param>
  261. /// <returns></returns>
  262. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.ModProductStatusAsync", true)]
  263. public static async Task<WxJsonResult> ModProductStatusAsync(string accessToken, int status, string productId)
  264. {
  265. var urlFormat = Config.ApiMpHost + "/merchant/modproductstatus?access_token={0}";
  266. var data = new
  267. {
  268. product_id = productId,
  269. status = status
  270. };
  271. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  272. }
  273. /// <summary>
  274. /// 【异步方法】获取指定分类的所有子分类
  275. /// </summary>
  276. /// <param name="accessToken"></param>
  277. /// <param name="cateId">大分类ID(根节点分类id为1)</param>
  278. /// <returns></returns>
  279. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetSubAsync", true)]
  280. public static async Task<GetSubResult> GetSubAsync(string accessToken, long cateId)
  281. {
  282. var urlFormat = Config.ApiMpHost + "/merchant/category/getsub?access_token={0}";
  283. var date = new
  284. {
  285. cate_id = cateId
  286. };
  287. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetSubResult>(accessToken, urlFormat, date);
  288. }
  289. /// <summary>
  290. /// 【异步方法】获取指定子分类的所有SKU
  291. /// </summary>
  292. /// <param name="accessToken"></param>
  293. /// <param name="cateId">商品子分类ID</param>
  294. /// <returns></returns>
  295. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetSkuAsync", true)]
  296. public static async Task<GetSkuResult> GetSkuAsync(string accessToken, long cateId)
  297. {
  298. var urlFormat = Config.ApiMpHost + "/merchant/category/getsku?access_token={0}";
  299. var data = new
  300. {
  301. cate_id = cateId
  302. };
  303. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetSkuResult>(accessToken, urlFormat, data);
  304. }
  305. /// <summary>
  306. /// 【异步方法】获取指定分类的所有属性
  307. /// </summary>
  308. /// <param name="accessToken"></param>
  309. /// <param name="cateId">分类ID</param>
  310. /// <returns></returns>
  311. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ProductApi.GetPropertyAsync", true)]
  312. public static async Task<GetPropertyResult> GetPropertyAsync(string accessToken, long cateId)
  313. {
  314. var urlFormat = Config.ApiMpHost + "/merchant/category/getproperty?access_token={0}";
  315. var data = new
  316. {
  317. cate_id = cateId
  318. };
  319. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetPropertyResult>(accessToken, urlFormat, data);
  320. }
  321. #endregion
  322. #endif
  323. }
  324. }