/// <summary> /// 查询订单返回 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public static string QueryOrder(string orderId) { string url = string.Format(domain + "/rest/v1.0/order/query/access_token/{0}/sf_appid/{1}/sf_appkey/{2}", QueryAccessToken(), SFAppId, SFAppKey); MessageReq <OrderQueryReqDto> req = new MessageReq <OrderQueryReqDto>(); req.head.transType = 203; req.head.transMessageId = DateTime.Now.ToLongTimeString(); req.body = new OrderQueryReqDto(); req.body.orderId = orderId; MessageResp <OrderQueryRespDto> res = HttpWebHelper.doPost <MessageReq <OrderQueryReqDto>, MessageResp <OrderQueryRespDto> >(url, req); //return HttpWebHelper.ObjectToJson(res); if (res.head.code == "EX_CODE_OPENAPI_0105") { GetAccessToken(); QueryOrder(orderId); } if (res.head.transType == 4203) { return(res.body.mailNo); } else { throw new Exception(res.head.message); } }
} //获取流水号 流水号格式 20171130+10位(时间戳) private void testwaybill(String id) { string url = "https://open-sbox.sf-express.com/rest/v1.0/waybill/image/access_token/" + accesstoken + "/sf_appid/00037521/sf_appkey/21662E074E84B37EB4DBA0F89F9803AA"; MessageReq <WaybillReqDto> req = new MessageReq <WaybillReqDto>(); HeadMessageReq req2 = new HeadMessageReq { transType = 0xcd, transMessageId = GettransMessageId() }; req.head = req2; WaybillReqDto dto = new WaybillReqDto { orderId = id }; req.body = dto; MessageResp <WaybillRespDto> resp = WaybillDownloadTools.waybillDownload(url, req); //resp.body.images{string[]}; string newLine = "打印信息:" + resp.head.message + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); if (resp.head.code.Equals("EX_CODE_OPENAPI_0200")) { String[] a = resp.body.images; Base64ToImg(a[0]); } }
private void RouteQuery() { string url = "https://open-sbox.sf-express.com/rest/v1.0/route/query/access_token/" + accesstoken + "/sf_appid/00037521/sf_appkey/21662E074E84B37EB4DBA0F89F9803AA"; MessageReq <RouteReqDto> req = new MessageReq <RouteReqDto>(); HeadMessageReq req2 = new HeadMessageReq { transType = 0x1f5, transMessageId = GettransMessageId() }; req.head = req2; RouteReqDto dto = new RouteReqDto { methodType = 2, trackingType = 1, trackingNumber = textBox2.Text.ToString() }; req.body = dto; MessageResp <List <RouteRespDto> > resp = RouteTools.routeQuery(url, req); string newLine = "订单追踪message:" + resp.head.message + "\n"; //richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); if (resp.head.code.Equals("EX_CODE_OPENAPI_0200")) { for (int i = 0; i < resp.body.Count; i++) { newLine = "{\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = " 快递接收地址:" + resp.body[i].acceptAddress + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = " 快递接收时间:" + resp.body[i].acceptTime + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = " 客户订单号:" + resp.body[i].orderId + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = " 快递运单号:" + resp.body[i].mailNo + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = " 操作码:" + resp.body[i].opcode + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = " 备注:" + resp.body[i].remark + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = "}\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); } } else { newLine = "订单追踪message:" + resp.head.message + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); } }
} //获取流水号 流水号格式 20171130+10位(时间戳) public void OrderQuery(String OrderId_check) { string url = "https://open-sbox.sf-express.com/rest/v1.0/order/query/access_token/" + accesstoken + "/sf_appid/00037521/sf_appkey/21662E074E84B37EB4DBA0F89F9803AA"; MessageReq <OrderQueryReqDto> req = new MessageReq <OrderQueryReqDto>(); HeadMessageReq req2 = new HeadMessageReq { transType = 0xcb, transMessageId = GettransMessageId() }; req.head = req2; OrderQueryReqDto dto = new OrderQueryReqDto { orderId = OrderId_check }; req.body = dto; MessageResp <OrderQueryRespDto> resp = OrderTools.orderQuery(url, req); string newLine = "message:" + resp.head.message + "\n"; //richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); /* newLine = "transMessageId(流水号):" + resp.head.transMessageId + "\n"; * richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); * newLine = "transType(处理类型):" + resp.head.transType + "\n"; * richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); * newLine = "code(状态码):" + resp.head.code + "\n"; * richTextBox1.Text = richTextBox1.Text.Insert(0, newLine);*/ if (resp.head.code.Equals("EX_CODE_OPENAPI_0200")) { newLine = "resp.body.destcode(目的地代码):" + resp.body.destCode + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = "resp.body.originCode(原寄地代码):" + resp.body.originCode + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = "resp.body.orderId(订单号):" + resp.body.orderId + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = "resp.body.maiNo(顺丰运单号):" + resp.body.mailNo + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = "resp.body.remark(留言):" + resp.body.remark + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); newLine = null; textBox2.Text = resp.body.mailNo; } else { newLine = "查询失败,错误信息:" + resp.head.message + "\n"; richTextBox1.Text = richTextBox1.Text.Insert(0, newLine); } }
//沙盒环境{domain} :open-sbox.sf-express.com //生产环境{domain} :open-prod.sf-express.com /// <summary> /// 获取Token 有效期为1小时 /// </summary> /// <returns></returns> private static string GetAccessToken() { string url = string.Format(domain + "/public/v1.0/security/access_token/sf_appid/{0}/sf_appkey/{1}", SFAppId, SFAppKey); MessageReq <TokenEntity> accessTokenReq = new MessageReq <TokenEntity>(); accessTokenReq.head.transType = 301; accessTokenReq.head.transMessageId = DateTime.Now.ToLongTimeString(); MessageResp <TokenEntity> res = HttpWebHelper.doPost <MessageReq <TokenEntity>, MessageResp <TokenEntity> >(url, accessTokenReq); if (res.head.transType == 4301) { return(res.body.accessToken); } else { throw new Exception(res.head.message); } }
public static string QueryRoute(string trackingNumber) { string url = string.Format(domain + "/rest/v1.0/route/query/access_token/{0}/sf_appid/{1}/sf_appkey/{2}", QueryAccessToken(), SFAppId, SFAppKey); MessageReq <RouteReqDto> req = new MessageReq <RouteReqDto>(); req.head.transType = 501; req.head.transMessageId = DateTime.Now.ToLongTimeString(); req.body = new RouteReqDto(); req.body.trackingNumber = trackingNumber; req.body.trackingType = 2;//2 订单号查询 1 运单号查询 req.body.methodType = 1; MessageResp <List <RouteRespDto> > res = HttpWebHelper.doPost <MessageReq <RouteReqDto>, MessageResp <List <RouteRespDto> > >(url, req); if (res.head.code == "EX_CODE_OPENAPI_0105") { GetAccessToken(); QueryRoute(trackingNumber); } return(HttpWebHelper.ObjectToJson(res)); }
public static string SubmitOrder(string province, string city, string address, string contact, string tel, string goodsName, short payMethod) { string url = string.Format(domain + "/rest/v1.0/order/access_token/{0}/sf_appid/{1}/sf_appkey/{2}", QueryAccessToken(), SFAppId, SFAppKey); MessageReq <OrderReqEntity> req = new MessageReq <OrderReqEntity>(); req.head.transType = 200; req.head.transMessageId = DateTime.Now.ToLongTimeString(); req.body = new OrderReqEntity(); req.body.orderId = "SF" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); req.body.expressType = 1; //标准快递 req.body.isDoCall = 1; //通知收派员上门取件 req.body.payMethod = payMethod; //付款方式 1月结 2收方付 3第三方付 if (req.body.payMethod == 1) { req.body.custId = SFYuJieCode;//顺丰月结卡号 10 位数字 } req.body.consigneeInfo = new DeliverConsigneeInfoDto(); req.body.consigneeInfo.address = address; req.body.consigneeInfo.city = city; req.body.consigneeInfo.company = "顺丰"; req.body.consigneeInfo.contact = contact; req.body.consigneeInfo.tel = tel; req.body.consigneeInfo.province = province; req.body.cargoInfo = new CargoInfoDto(); req.body.cargoInfo.cargo = goodsName; MessageResp <OrderRespEntity> res = HttpWebHelper.doPost <MessageReq <OrderReqEntity>, MessageResp <OrderRespEntity> >(url, req); if (res.head.code == "EX_CODE_OPENAPI_0105") { GetAccessToken(); SubmitOrder(province, city, address, contact, tel, goodsName, payMethod); } if (res.head.transType == 4200) { return(res.body.orderId); } else { throw new Exception(res.head.message); } }
/// <summary> /// 查询AccessToken 可以查询到数据 但是可能过期 /// </summary> /// <returns></returns> public static string QueryAccessToken() { string url = string.Format(domain + "/public/v1.0/security/access_token/query/sf_appid/{0}/sf_appkey/{1}", SFAppId, SFAppKey); MessageReq <TokenEntity> accessTokenReq = new MessageReq <TokenEntity>(); accessTokenReq.head.transType = 300; accessTokenReq.head.transMessageId = DateTime.Now.ToLongTimeString(); MessageResp <TokenEntity> res = HttpWebHelper.doPost <MessageReq <TokenEntity>, MessageResp <TokenEntity> >(url, accessTokenReq); if (res.head.code == "EX_CODE_OPENAPI_0105")//访问令牌过期 { return(GetAccessToken()); } else if (res.head.transType == 4300) { return(res.body.accessToken); } else { throw new Exception(res.head.message); } }
void MessageResponse(Resp r) { MessageResp resp = (MessageResp)r; NetTools.Log(resp.GetMsg()); }