StockApi.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 StockApi
  36. {
  37. #region 同步方法
  38. /// <summary>
  39. /// 增加库存
  40. /// </summary>
  41. /// <param name="accessToken"></param>
  42. /// <param name="addStockData">增加库存需要Post的数据</param>
  43. /// <returns></returns>
  44. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "StockApi.AddStock", true)]
  45. public static WxJsonResult AddStock(string accessToken, AddStockData addStockData)
  46. {
  47. var urlFormat = Config.ApiMpHost + "/merchant/stock/add?access_token={0}";
  48. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, addStockData);
  49. }
  50. /// <summary>
  51. /// 减少库存
  52. /// </summary>
  53. /// <param name="accessToken"></param>
  54. /// <param name="reduceStockData">减少库存需要Post的数据</param>
  55. /// <returns></returns>
  56. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "StockApi.ReduceStock", true)]
  57. public static WxJsonResult ReduceStock(string accessToken, ReduceStockData reduceStockData)
  58. {
  59. var urlFormat = Config.ApiMpHost + "/merchant/stock/reduce?access_token={0}";
  60. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, reduceStockData);
  61. }
  62. #endregion
  63. #if !NET35 && !NET40
  64. #region 异步方法
  65. /// <summary>
  66. /// 【异步方法】增加库存
  67. /// </summary>
  68. /// <param name="accessToken"></param>
  69. /// <param name="addStockData">增加库存需要Post的数据</param>
  70. /// <returns></returns>
  71. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "StockApi.AddStockAsync", true)]
  72. public static async Task<WxJsonResult> AddStockAsync(string accessToken, AddStockData addStockData)
  73. {
  74. var urlFormat = Config.ApiMpHost + "/merchant/stock/add?access_token={0}";
  75. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, addStockData);
  76. }
  77. /// <summary>
  78. /// 【异步方法】减少库存
  79. /// </summary>
  80. /// <param name="accessToken"></param>
  81. /// <param name="reduceStockData">减少库存需要Post的数据</param>
  82. /// <returns></returns>
  83. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "StockApi.ReduceStockAsync", true)]
  84. public static async Task<WxJsonResult> ReduceStockAsync(string accessToken, ReduceStockData reduceStockData)
  85. {
  86. var urlFormat = Config.ApiMpHost + "/merchant/stock/reduce?access_token={0}";
  87. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, reduceStockData);
  88. }
  89. #endregion
  90. #endif
  91. }
  92. }