ExpressApi.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. 修改标识:Senparc - 20160719
  16. 修改描述:增加其接口的异步方法
  17. ----------------------------------------------------------------*/
  18. using System.Threading.Tasks;
  19. using Senparc.NeuChar;
  20. using Senparc.Weixin.CommonAPIs;
  21. using Senparc.Weixin.Entities;
  22. using Senparc.Weixin.MP.CommonAPIs;
  23. namespace Senparc.Weixin.MP.AdvancedAPIs
  24. {
  25. /// <summary>
  26. /// 微小店接口,官方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
  27. /// </summary>
  28. public static class ExpressApi
  29. {
  30. #region 同步方法
  31. /// <summary>
  32. /// 增加邮费模板
  33. /// </summary>
  34. /// <param name="accessToken"></param>
  35. /// <param name="addExpressData">增加邮费模板需要Post的数据</param>
  36. /// <returns></returns>
  37. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.AddExpress", true)]
  38. public static AddExpressResult AddExpress(string accessToken, AddExpressData addExpressData)
  39. {
  40. var urlFormat = Config.ApiMpHost + "/merchant/express/add?access_token={0}";
  41. return CommonJsonSend.Send<AddExpressResult>(accessToken, urlFormat, addExpressData);
  42. }
  43. /// <summary>
  44. /// 删除邮费模板
  45. /// </summary>
  46. /// <param name="accessToken"></param>
  47. /// <param name="templateId">邮费模板Id</param>
  48. /// <returns></returns>
  49. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.DeleteExpress", true)]
  50. public static WxJsonResult DeleteExpress(string accessToken, int templateId)
  51. {
  52. var urlFormat = Config.ApiMpHost + "/merchant/express/del?access_token={0}";
  53. var data = new
  54. {
  55. template_id = templateId
  56. };
  57. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  58. }
  59. /// <summary>
  60. /// 修改邮费模板
  61. /// </summary>
  62. /// <param name="accessToken"></param>
  63. /// <param name="upDateExpressData">修改邮费模板需要Post的数据</param>
  64. /// <returns></returns>
  65. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.UpDateExpress", true)]
  66. public static WxJsonResult UpDateExpress(string accessToken, UpDateExpressData upDateExpressData)
  67. {
  68. var urlFormat = Config.ApiMpHost + "/merchant/express/update?access_token={0}";
  69. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, upDateExpressData);
  70. }
  71. /// <summary>
  72. /// 获取指定ID的邮费模板
  73. /// </summary>
  74. /// <param name="accessToken"></param>
  75. /// <param name="templateId">邮费模板Id</param>
  76. /// <returns></returns>
  77. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.GetByIdExpress", true)]
  78. public static GetByIdExpressResult GetByIdExpress(string accessToken, int templateId)
  79. {
  80. var urlFormat = Config.ApiMpHost + "/merchant/express/getbyid?access_token={0}";
  81. var data = new
  82. {
  83. template_id = templateId
  84. };
  85. return CommonJsonSend.Send<GetByIdExpressResult>(accessToken, urlFormat, data);
  86. }
  87. /// <summary>
  88. /// 获取所有邮费模板
  89. /// </summary>
  90. /// <param name="accessToken"></param>
  91. /// <returns></returns>
  92. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.GetAllExpress", true)]
  93. public static GetAllExpressResult GetAllExpress(string accessToken)
  94. {
  95. var urlFormat = Config.ApiMpHost + "/merchant/express/getall?access_token={0}";
  96. return CommonJsonSend.Send<GetAllExpressResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  97. }
  98. #endregion
  99. #if !NET35 && !NET40
  100. #region 异步方法
  101. /// <summary>
  102. /// 【异步方法】增加邮费模板
  103. /// </summary>
  104. /// <param name="accessToken"></param>
  105. /// <param name="addExpressData">增加邮费模板需要Post的数据</param>
  106. /// <returns></returns>
  107. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.AddExpressAsync", true)]
  108. public static async Task<AddExpressResult> AddExpressAsync(string accessToken, AddExpressData addExpressData)
  109. {
  110. var urlFormat = Config.ApiMpHost + "/merchant/express/add?access_token={0}";
  111. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<AddExpressResult>(accessToken, urlFormat, addExpressData);
  112. }
  113. /// <summary>
  114. /// 【异步方法】删除邮费模板
  115. /// </summary>
  116. /// <param name="accessToken"></param>
  117. /// <param name="templateId">邮费模板Id</param>
  118. /// <returns></returns>
  119. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.DeleteExpressAsync", true)]
  120. public static async Task<WxJsonResult> DeleteExpressAsync(string accessToken, int templateId)
  121. {
  122. var urlFormat = Config.ApiMpHost + "/merchant/express/del?access_token={0}";
  123. var data = new
  124. {
  125. template_id = templateId
  126. };
  127. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  128. }
  129. /// <summary>
  130. /// 【异步方法】修改邮费模板
  131. /// </summary>
  132. /// <param name="accessToken"></param>
  133. /// <param name="upDateExpressData">修改邮费模板需要Post的数据</param>
  134. /// <returns></returns>
  135. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.UpDateExpressAsync", true)]
  136. public static async Task<WxJsonResult> UpDateExpressAsync(string accessToken, UpDateExpressData upDateExpressData)
  137. {
  138. var urlFormat = Config.ApiMpHost + "/merchant/express/update?access_token={0}";
  139. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, upDateExpressData);
  140. }
  141. /// <summary>
  142. /// 【异步方法】获取指定ID的邮费模板
  143. /// </summary>
  144. /// <param name="accessToken"></param>
  145. /// <param name="templateId">邮费模板Id</param>
  146. /// <returns></returns>
  147. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.GetByIdExpressAsync", true)]
  148. public static async Task<GetByIdExpressResult> GetByIdExpressAsync(string accessToken, int templateId)
  149. {
  150. var urlFormat = Config.ApiMpHost + "/merchant/express/getbyid?access_token={0}";
  151. var data = new
  152. {
  153. template_id = templateId
  154. };
  155. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetByIdExpressResult>(accessToken, urlFormat, data);
  156. }
  157. /// <summary>
  158. /// 【异步方法】获取所有邮费模板
  159. /// </summary>
  160. /// <param name="accessToken"></param>
  161. /// <returns></returns>
  162. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ExpressApi.GetAllExpressAsync", true)]
  163. public static async Task<GetAllExpressResult> GetAllExpressAsync(string accessToken)
  164. {
  165. var urlFormat = Config.ApiMpHost + "/merchant/express/getall?access_token={0}";
  166. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetAllExpressResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  167. }
  168. #endregion
  169. #endif
  170. }
  171. }