杭州公司网站建设哪家好,建设网站是否等于开展网络营销,贵州网站建设营销公司,无锡网站制作启航提示#xff1a;学习express#xff0c;搭建管理系统 文章目录 前言一、安装md5#xff0c;axios二、新建config/logistics.js三、修改routes/order.js四、查询物流信息五、试错与误区总结 前言 需求#xff1a;主要学习express#xff0c;所以先写service部分 快递100API… 提示学习express搭建管理系统 文章目录 前言一、安装md5axios二、新建config/logistics.js三、修改routes/order.js四、查询物流信息五、试错与误区总结 前言 需求主要学习express所以先写service部分 快递100API文档 一、安装md5axios
npm install axios md5 --save-dev二、新建config/logistics.js
config/logistics.js
//快递100
const axios require(axios);
const md5 require(md5);//查询物流信息url
let url https://poll.kuaidi100.com/poll/query.do;
//customer
let customer xxxxxxxxxxxxxxxxxxxxxxxxx;
//授权key
let key xxxxxxxxx;const logistics {query:async (param){//一定要把param转换成JSON不然一直报签名错误let paramJson JSON.stringify(param);let sign md5(paramJsonkeycustomer);sign sign.toUpperCase();axios.defaults.headers.get[Content-Type] application/x-www-form-urlencoded;const res await axios.get(url?customer${customer}sign${sign}param${paramJson});return res.data}
}module.exports logistics;customerkey通过 快递100企业信息获取 customer对应customer key对应授权key 三、修改routes/order.js
routes/order.js
const OrderDao require(../dao/order);
const logistics require(../config/logistics);
const OrderRoutes (router){router.post(/order/addGoodsToOrder,async (req,res){const result await OrderDao.addGoodsToOrder(req.body);res.json(result);});router.get(/order/queryGoodsByUserIdFromOrder,async (req,res){const result await OrderDao.queryGoodsByUserIdFromOrder(req.query);res.json(result);});router.post(/order/queryOrderLogistics,async (req,res){const result await logistics.query(req.body);res.json(result);});
}
module.exports OrderRoutes;四、查询物流信息
url:http://localhost:1990/order/queryOrderLogistics
params:{{com: yuantong,num: xxxxxxxxxxx,phone: ,from: ,to: ,resultv2: 4,show: 0,order: desc
}}免费版本试用100次 五、试错与误区 用于签名的param和get请求url上的param 必须是JSON.stringify(param)的JSON格式 不能是Object格式不然一直报签名错误 总结
踩坑路漫漫长~