OrderApi.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. 文件名:OrderApi.cs
  17. 文件功能描述:微小店订单接口
  18. 创建标识:Senparc - 20150827
  19. 修改标识:Senparc - 20160719
  20. 修改描述:增加其接口的异步方法
  21. 修改标识:Senparc - 20170522
  22. 修改描述:v16.6.2 修改 DateTime 为 DateTimeOffset
  23. ----------------------------------------------------------------*/
  24. /*
  25. 微小店接口,官方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
  26. */
  27. using System;
  28. using System.Threading.Tasks;
  29. using Senparc.CO2NET.Helpers;
  30. using Senparc.CO2NET.Helpers.Serializers;
  31. using Senparc.NeuChar;
  32. using Senparc.Weixin.CommonAPIs;
  33. using Senparc.Weixin.Entities;
  34. using Senparc.Weixin.Helpers;
  35. using Senparc.Weixin.MP.CommonAPIs;
  36. namespace Senparc.Weixin.MP.AdvancedAPIs.MerChant
  37. {
  38. /// <summary>
  39. /// 微小店订单接口
  40. /// </summary>
  41. public static class OrderApi
  42. {
  43. #region 同步方法
  44. /// <summary>
  45. /// 根据订单ID获取订单详情
  46. /// </summary>
  47. /// <param name="accessToken"></param>
  48. /// <param name="orderId">订单Id</param>
  49. /// <returns></returns>
  50. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.GetByIdOrder", true)]
  51. public static GetByIdOrderResult GetByIdOrder(string accessToken, string orderId)
  52. {
  53. var urlFormat = Config.ApiMpHost + "/merchant/order/getbyid?access_token={0}";
  54. var data = new
  55. {
  56. order_id = orderId
  57. };
  58. return CommonJsonSend.Send<GetByIdOrderResult>(accessToken, urlFormat, data);
  59. }
  60. /// <summary>
  61. /// 根据订单状态/创建时间获取订单详情
  62. /// </summary>
  63. /// <param name="accessToken"></param>
  64. /// <param name="status">订单状态(不带该字段-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中, )</param>
  65. /// <param name="beginTime">订单创建时间起始时间(不带该字段则不按照时间做筛选)</param>
  66. /// <param name="endTime">订单创建时间终止时间(不带该字段则不按照时间做筛选)</param>
  67. /// <returns></returns>
  68. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.GetByFilterOrder", true)]
  69. public static GetByFilterResult GetByFilterOrder(string accessToken, int? status, DateTime? beginTime, DateTime? endTime)
  70. {
  71. var urlFormat = Config.ApiMpHost + "/merchant/order/getbyfilter?access_token={0}";
  72. var data = new
  73. {
  74. status = status,
  75. begintime = beginTime.HasValue ? DateTimeHelper.GetUnixDateTime(beginTime.Value) : (long?)null,
  76. endtime = endTime.HasValue ? DateTimeHelper.GetUnixDateTime(endTime.Value) : (long?)null
  77. };
  78. return CommonJsonSend.Send<GetByFilterResult>(accessToken, urlFormat, data,jsonSetting:new JsonSetting(true));
  79. }
  80. /// <summary>
  81. /// 设置订单发货信息
  82. /// </summary>
  83. /// <param name="accessToken"></param>
  84. /// <param name="orderId">订单ID</param>
  85. /// <param name="deliveryCompany">物流公司ID(参考《物流公司ID》;当need_delivery为0时,可不填本字段;当need_delivery为1时,该字段不能为空;当need_delivery为1且is_others为1时,本字段填写其它物流公司名称)</param>
  86. /// <param name="deliveryTrackNo">运单ID(当need_delivery为0时,可不填本字段;当need_delivery为1时,该字段不能为空;)</param>
  87. /// <param name="needDelivery">商品是否需要物流(0-不需要,1-需要,无该字段默认为需要物流)</param>
  88. /// <param name="isOthers">是否为其它物流公司(0-否,1-是,无该字段默认为不是其它物流公司)</param>
  89. /// <returns></returns>
  90. /// 物流公司 Id
  91. /// 邮政EMS Fsearch_code
  92. /// 申通快递 002shentong
  93. /// 中通速递 066zhongtong
  94. /// 圆通速递 056yuantong
  95. /// 天天快递 042tiantian
  96. /// 顺丰速运 003shunfeng
  97. /// 韵达快运 059Yunda
  98. /// 宅急送 064zhaijisong
  99. /// 汇通快运 020huitong
  100. /// 易迅快递 zj001yixun
  101. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.SetdeliveryOrder", true)]
  102. public static WxJsonResult SetdeliveryOrder(string accessToken, string orderId, string deliveryCompany, string deliveryTrackNo, int needDelivery = 1, int isOthers = 0)
  103. {
  104. var urlFormat = Config.ApiMpHost + "/merchant/order/setdelivery?access_token={0}";
  105. var data = new
  106. {
  107. order_id = orderId,
  108. delivery_company = deliveryCompany,
  109. delivery_track_no = deliveryTrackNo,
  110. need_delivery = needDelivery,
  111. is_others = isOthers
  112. };
  113. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  114. }
  115. /// <summary>
  116. /// 关闭订单
  117. /// </summary>
  118. /// <param name="accessToken"></param>
  119. /// <param name="orderId">订单ID</param>
  120. /// <returns></returns>
  121. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.CloseOrder", true)]
  122. public static WxJsonResult CloseOrder(string accessToken, string orderId)
  123. {
  124. var urlFormat = Config.ApiMpHost + "/merchant/order/close?access_token={0}";
  125. var data = new
  126. {
  127. order_id = orderId
  128. };
  129. return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data);
  130. }
  131. #endregion
  132. #if !NET35 && !NET40
  133. #region 异步方法
  134. /// <summary>
  135. /// 【异步方法】根据订单ID获取订单详情
  136. /// </summary>
  137. /// <param name="accessToken"></param>
  138. /// <param name="orderId">订单Id</param>
  139. /// <returns></returns>
  140. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.GetByIdOrderAsync", true)]
  141. public static async Task<GetByIdOrderResult> GetByIdOrderAsync(string accessToken, string orderId)
  142. {
  143. var urlFormat = Config.ApiMpHost + "/merchant/order/getbyid?access_token={0}";
  144. var data = new
  145. {
  146. order_id = orderId
  147. };
  148. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetByIdOrderResult>(accessToken, urlFormat, data);
  149. }
  150. /// <summary>
  151. /// 【异步方法】根据订单状态/创建时间获取订单详情
  152. /// </summary>
  153. /// <param name="accessToken"></param>
  154. /// <param name="status">订单状态(不带该字段-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中, )</param>
  155. /// <param name="beginTime">订单创建时间起始时间(不带该字段则不按照时间做筛选)</param>
  156. /// <param name="endTime">订单创建时间终止时间(不带该字段则不按照时间做筛选)</param>
  157. /// <returns></returns>
  158. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.GetByFilterOrderAsync", true)]
  159. public static async Task<GetByFilterResult> GetByFilterOrderAsync(string accessToken, int? status, DateTime? beginTime, DateTime? endTime)
  160. {
  161. var urlFormat = Config.ApiMpHost + "/merchant/order/getbyfilter?access_token={0}";
  162. var data = new
  163. {
  164. status = status,
  165. begintime = beginTime.HasValue ? DateTimeHelper.GetUnixDateTime(beginTime.Value) : (long?)null,
  166. endtime = endTime.HasValue ? DateTimeHelper.GetUnixDateTime(endTime.Value) : (long?)null
  167. };
  168. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetByFilterResult>(accessToken, urlFormat, data, jsonSetting: new JsonSetting(true));
  169. }
  170. /// <summary>
  171. /// 【异步方法】设置订单发货信息
  172. /// </summary>
  173. /// <param name="accessToken"></param>
  174. /// <param name="orderId">订单ID</param>
  175. /// <param name="deliveryCompany">物流公司ID(参考《物流公司ID》;当need_delivery为0时,可不填本字段;当need_delivery为1时,该字段不能为空;当need_delivery为1且is_others为1时,本字段填写其它物流公司名称)</param>
  176. /// <param name="deliveryTrackNo">运单ID(当need_delivery为0时,可不填本字段;当need_delivery为1时,该字段不能为空;)</param>
  177. /// <param name="needDelivery">商品是否需要物流(0-不需要,1-需要,无该字段默认为需要物流)</param>
  178. /// <param name="isOthers">是否为其它物流公司(0-否,1-是,无该字段默认为不是其它物流公司)</param>
  179. /// <returns></returns>
  180. /// 物流公司 Id
  181. /// 邮政EMS Fsearch_code
  182. /// 申通快递 002shentong
  183. /// 中通速递 066zhongtong
  184. /// 圆通速递 056yuantong
  185. /// 天天快递 042tiantian
  186. /// 顺丰速运 003shunfeng
  187. /// 韵达快运 059Yunda
  188. /// 宅急送 064zhaijisong
  189. /// 汇通快运 020huitong
  190. /// 易迅快递 zj001yixun
  191. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.SetdeliveryOrderAsync", true)]
  192. public static async Task<WxJsonResult> SetdeliveryOrderAsync(string accessToken, string orderId, string deliveryCompany, string deliveryTrackNo, int needDelivery = 1, int isOthers = 0)
  193. {
  194. var urlFormat = Config.ApiMpHost + "/merchant/order/setdelivery?access_token={0}";
  195. var data = new
  196. {
  197. order_id = orderId,
  198. delivery_company = deliveryCompany,
  199. delivery_track_no = deliveryTrackNo,
  200. need_delivery = needDelivery,
  201. is_others = isOthers
  202. };
  203. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  204. }
  205. /// <summary>
  206. /// 【异步方法】关闭订单
  207. /// </summary>
  208. /// <param name="accessToken"></param>
  209. /// <param name="orderId">订单ID</param>
  210. /// <returns></returns>
  211. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "OrderApi.CloseOrderAsync", true)]
  212. public static async Task<WxJsonResult> CloseOrderAsync(string accessToken, string orderId)
  213. {
  214. var urlFormat = Config.ApiMpHost + "/merchant/order/close?access_token={0}";
  215. var data = new
  216. {
  217. order_id = orderId
  218. };
  219. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(accessToken, urlFormat, data);
  220. }
  221. #endregion
  222. #endif
  223. }
  224. }