闭关搬了一个星期的砖,终于顺利发布项目。项目中用到.net木有办法,只好捡起来慢慢搬。为了后来的同学免于在黑暗中摸索,本帅就把这几天踩的坑填满了发一下。
做系统对接最怕的就是木有demo,一点点码,调试和解决问题。本项目需一要实现第三方商家填单后,系统调用快递100接口,给用户展示该单的物流轨迹。很多商家比较忙,导入的时候没注意核对单号,这个时候,就需要快递100的智能单号识别接口,先做个预判。排除一些错误的,张冠李戴的。
using System;
using Common;
using Common.Request;
using Common.Request.Subscribe;
using Utils;
using Newtonsoft.Json;
using Common.Request.Electronic.Image;
using Common.Request.Electronic.Html;
using Common.Request.Electronic;
using Common.Request.Electronic.Print;
using Common.Request.Sms;
using System.Collections;
class Program
{
//快递100的基础账号信息,可以在这里获取 (需要填写完整才能测试)
//https://poll.kuaidi100.com/manager/page/myinfo/enterprise
private static KuaiDi100Config config = new KuaiDi100Config()
{
key = "",
customer = "",
secret = "",
userid = "",
siid = "",
tid = "",
};
static void Main(string[] args)
{
//testQueryTrack();
//testSubscribe();
//testPrintImg();
// testPrintHtml();
// testPrintCloud();
// testSendSms();
testAutoNum();
}
///
/// 智能识别
///
static void testAutoNum()
{
AutoNum.query("773039762404825",config.key);
}
实时查询接口和订阅推送接口分别对应两种不同的查询模式,前面有说,不清楚可以直接翻看前面的文章,这里就不啰嗦了。
项目需求二:提供商家打印发货单和电子面单,自动回填单号
这个就需要拆解一下了:调用快递100电子面单接口,获取单号和生成一张电子面单供打印或传输;调用打印接口输出;调用云打印接口来同步打印发货单。这里有很多注意事项,也有很多坑,直接看代码把。
////// 电子面单图片接口 /// static void testPrintImg() { var printImgParam = new PrintImgParam(){ kuaidicom = "zhaijisong", sendManName = "张三", sendManMobile = "15999998256", sendManPrintAddr = "广东省深圳市南山区科技南十二路", recManName = "李四", recManMobile = "15999998256", recManPrintAddr = "北京市海淀区xxx路", type = "10", tempid = "180c7c8f646742ca871a92c976392b05", count = "1", weight = "76", height = "130", }; var timestamp = DateUtils.GetTimestamp(); PrintImg.query(new PrintImgReq() { method = ApiInfoConstant.ELECTRONIC_ORDER_PIC_METHOD, key = config.key, t = timestamp, sign = SignUtils.GetMD5(printImgParam.ToString() + timestamp + config.key + config.secret), param = printImgParam, }); } ////// 电子面单html接口 /// static void testPrintHtml() { var printHtmlParam = new PrintHtmlParam(){ kuaidicom = "zhaijisong", sendMan = new ManInfo() { name = "张三", mobile = "15999998256", printAddr = "广东省深圳市南山区科技南十二路", }, recMan = new ManInfo() { name = "李四", mobile = "15999998256", printAddr = "北京市海淀区xxx路", }, count = "1", needTemplate = "1", //如果需要返回电子面单,需要设置 }; var timestamp = DateUtils.GetTimestamp(); PrintHtml.query(new PrintHtmlReq() { method = ApiInfoConstant.ELECTRONIC_ORDER_HTML_METHOD, key = config.key, t = timestamp, sign = SignUtils.GetMD5(printHtmlParam.ToString() + timestamp + config.key + config.secret), param = printHtmlParam, }); } ////// 电子面单打印接口 /// static void testPrintCloud() { var printCloudParam = new PrintCloudParam(){ kuaidicom = "zhaijisong", sendMan = new ManInfo() { name = "张三", mobile = "15999998256", printAddr = "广东省深圳市南山区科技南十二路", }, recMan = new ManInfo() { name = "李四", mobile = "15999998256", printAddr = "北京市海淀区xxx路", }, count = "1", siid = config.siid, tempid = "180c7c8f646742ca871a92c976392b05", }; var timestamp = DateUtils.GetTimestamp(); PrintCloud.query(new PrintCloudReq() { method = ApiInfoConstant.ELECTRONIC_ORDER_PRINT_METHOD, key = config.key, t = timestamp, sign = SignUtils.GetMD5(printCloudParam.ToString() + timestamp + config.key + config.secret), param = printCloudParam, }); }
完整代码见:https://github.com/kuaidi100-api/.net-demo



