using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Http; using Codeplex.Data; using Deepleo.Weixin.SDK.Helpers; namespace Deepleo.Weixin.SDK.Merchant { /// /// 订单管理 /// public class OrderAPI { /// /// 根据订单ID获取订单详情 /// /// /// 订单ID /// 订单详情,具体请参见官方文档 public static dynamic GetById(string access_token, string order_id) { var client = new HttpClient(); var content = new StringBuilder(); content.Append("{") .Append('"' + "order_id" + '"' + ": " + '"' + order_id + '"') .Append("}"); var result = client.PostAsync(string.Format("https://api.weixin.qq.com/merchant/order/getbyid?access_token={0}", access_token), new StringContent(content.ToString())).Result; return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result); } /// ///据订单状态/创建时间获取订单详情 /// /// /// 订单状态(不带该字段-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中, ) /// 订单创建时间起始时间(不带该字段则不按照时间做筛选) /// 订单创建时间终止时间(不带该字段则不按照时间做筛选) /// 订单详情,参见官方文档 public static dynamic GetByFilter(string access_token, int status, long begintime = 0, long endtime = 0) { var client = new HttpClient(); var content = new StringBuilder(); content.Append("{") .Append('"' + "status" + '"' + ": " + status); if (begintime > 0 || endtime > 0) { content.Append(","); if (begintime <= 0) begintime = DateTime.MinValue.ToTimestamp(); if (endtime <= 0) endtime = DateTime.Now.ToTimestamp(); content.Append('"' + "begintime" + '"' + ": " + begintime).Append(","); if (endtime <= 0) endtime = DateTime.Now.ToTimestamp(); content.Append('"' + "endtime" + '"' + ": " + endtime); } content.Append("}"); var result = client.PostAsync(string.Format("https://api.weixin.qq.com/merchant/order/getbyfilter?access_token={0}", access_token), new StringContent(content.ToString())).Result; return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result); } /// /// /// /// /// 订单ID /// 商品是否需要物流(0-不需要,1-需要,无该字段默认为需要物流) /// 是否为6.4.5表之外的其它物流公司(0-否,1-是,无该字段默认为不是其它物流公司) /// 6.4.5附:物流公司ID /// 物流公司 ID /// ============================= /// 邮政EMS Fsearch_code /// 申通快递 002shentong /// 中通速递 066zhongtong /// 圆通速递 056yuantong /// 天天快递 042tiantian /// 顺丰速运 003shunfeng /// 韵达快运 059Yunda /// 宅急送 064zhaijisong /// 汇通快运 020huitong /// 易迅快递 zj001yixun /// ============================ /// /// /// 物流公司ID(参考《物流公司ID》; /// 当need_delivery为0时,可不填本字段; /// 当need_delivery为1时,该字段不能为空; /// 当need_delivery为1且is_others为1时,本字段填写其它物流公司名称) /// /// 运单ID( /// 当need_delivery为0时,可不填本字段; /// 当need_delivery为1时,该字段不能为空; /// ) /// /// /// { ///"errcode": 0, ///"errmsg": "success" ///} /// public static dynamic SetDelivery(string access_token, string order_id, int need_delivery, int is_others, string delivery_track_no = "", string delivery_company = "") { var client = new HttpClient(); var content = new StringBuilder(); content.Append("{") .Append('"' + "order_id" + '"' + ": " + '"' + order_id + '"').Append(",") .Append('"' + "need_delivery" + '"' + ": " + need_delivery).Append(",") .Append('"' + "is_others" + '"' + ": " + is_others); if (need_delivery == 1) { content.Append(",") .Append('"' + "delivery_company" + '"' + ": " + '"' + delivery_company + '"').Append(",") .Append('"' + "delivery_track_no" + '"' + ": " + '"' + delivery_track_no + '"'); } content.Append("}"); var result = client.PostAsync(string.Format("https://api.weixin.qq.com/merchant/order/setdelivery?access_token={0}", access_token), new StringContent(content.ToString())).Result; return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result); } /// /// 关闭订单 /// /// /// 订单ID /// /// { ///"errcode": 0, ///"errmsg": "success" ///} /// public static dynamic Close(string access_token, string order_id) { var client = new HttpClient(); var content = new StringBuilder(); content.Append("{") .Append('"' + "order_id" + '"' + ": " + '"' + order_id + '"') .Append("}"); var result = client.PostAsync(string.Format("https://api.weixin.qq.com/merchant/order/close?access_token={0}", access_token), new StringContent(content.ToString())).Result; return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result); } } }