阿里云物流API
物流查询按钮
<el-button
v-if="scope.row.orderState==='已发货'"
size="mini"
type="danger"
slot="reference"
@click="wuliu(物流单号)">物流查询
</el-button>
wuliu(){
this.$http.get("/getExpressInfo").then(res => {
console.log(res.data.showapi_res_body);
let str = JSON.stringify(res.data.showapi_res_body);
let parse1 = JSON.parse(str);
console.log(parse1.data);
this.user=parse1.data;
}).catch(err => {
console.log(err);
}),
this.wuliu1=true;
},
<el-dialog title="物流信息" :visible.sync="wuliu1" width="60%"
close-on-click-modal="false" close-on-press-escape="false" show-close="false">
<div class='time-line'>
<div v-for='user in user' class='time-line-div'>
<p>{{user.time}}</p>
<p ref='circular'></p>
<p>{{user.context}}</p>
</div>
<div class='img-dotted' ref='dotted'></div>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="wuliu1 = false">取 消</el-button>
<el-button type="primary" @click="save">确 定</el-button>
</div>
</el-dialog>
data() {
return{
user:{},
wuliu1:false
}
}
wuliu(){
axios.get("/getExpressInfo").then(res => {
console.log(res.data.showapi_res_body);
let str = JSON.stringify(res.data.showapi_res_body);
let parse1 = JSON.parse(str);
console.log(parse1.data);
this.user=parse1.data;
}).catch(err => {
console.log(err);
}),
this.wuliu1=true;
},
express:
appcode: 你的appcode
ExpressControlle,控制层
@RestController
public class ExpressControlle {
@Resource
private ExpressService expressService;
//快递公司查询
@RequestMapping(value = "getExpressList")
public JSONObject getExpressList(ExpressListReqBody reqBody) {
System.out.println("123132");
JSONObject jsonObject = null;
try {
jsonObject = expressService.getExpressList(reqBody);
} catch (IOException e) {
e.printStackTrace();
}
return jsonObject;
}
//快递物流节点跟踪
@RequestMapping("/getExpressInfo")
public JSONObject getExpressInfo(ExpressInfoReqBody reqBody) {
System.out.println("getExpressInfo");
//由于是测试接口,所以这里自己填写的物流单号
reqBody.setCom("auto");
reqBody.setNu("432419993801549");
JSONObject jsonObject = null;
try {
jsonObject = expressService.getExpressInfo(reqBody);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(jsonObject);
return jsonObject;
}
//单号查快递公司名
@RequestMapping(value = "fetchCom")
public JSONObject fetchCom(@RequestParam(value = "nu",required = false) String nu) {
JSONObject jsonObject = null;
try {
jsonObject = expressService.fetchCom(nu);
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
}
ExpressService,service层
public interface ExpressService {
//快递公司查询
JSONObject getExpressList(ExpressListReqBody reqBody) throws IOException;
//快递物流节点跟踪
JSONObject getExpressInfo(ExpressInfoReqBody reqBody) throws Exception;
//单号查快递公司名
JSONObject fetchCom(String nu);
}
ExpressServiceImpl,service实现层
@Service
public class ExpressServiceImpl implements ExpressService {
//获取配置文件的appcode
@Value("${express.appcode}")
private String appcode;
@Override
public JSONObject getExpressList(ExpressListReqBody reqBody) {
String host = "https://ali-deliver.showapi.com";
String path = "/showapi_expressList";
String method = "GET";
Map<String, String> headers = new HashMap<>(16);
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<>(16);
querys.put("expName", reqBody.getExpName());
querys.put("maxSize", String.valueOf(reqBody.getMaxSize()));
querys.put("page", String.valueOf(reqBody.getPage()));
return getJsonObject(host, path, method, headers, querys);
}
@Override
public JSONObject getExpressInfo(ExpressInfoReqBody reqBody) {
String host = "https://ali-deliver.showapi.com";
String path = "/showapi_expInfo";
String method = "GET";
Map<String, String> headers = new HashMap<>(16);
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<>(16);
querys.put("com", reqBody.getCom());
querys.put("nu", reqBody.getNu());
querys.put("receiverPhone", reqBody.getReceiverPhone());
querys.put("senderPhone", reqBody.getSenderPhone());
return getJsonObject(host, path, method, headers, querys);
}
@Override
public JSONObject fetchCom(String nu) {
String host = "https://ali-deliver.showapi.com";
String path = "/fetchCom";
String method = "GET";
Map<String, String> headers = new HashMap<>(16);
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<>(16);
querys.put("nu", nu);
return getJsonObject(host, path, method, headers, querys);
}
private JSONObject getJsonObject(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) {
HttpResponse response;
String str = null;
try {
response = HttpUtils.doGet(host, path, method, headers, querys);
str = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
e.printStackTrace();
}
JSONObject jsonObject = JSONObject.parseObject(str);
return jsonObject;
}
}
Entity实体类
@Data
public class ExpressInfoReqBody {
/* 名称 类型 是否必须 描述
com STRING 必选 快递公司字母简称,可以从接口"快递公司查询" 中查到该信息 如不知道快递公司名,可以使用"auto"代替,此时将自动识别快递单号所属公司(成功率99%,因为一个单号规则可能会映射到多个快递公司。如果识别失败,系统将返回可能的快递公司列表)。不推荐大面积使用auto,建议尽量传入准确的公司编码。
nu STRING 必选 单号
receiverPhone STRING 可选 收件人手机号后四位,顺丰需要填写(手机号后四位填一个就行,多填以寄件人为准)
senderPhone STRING 可选 寄件人手机号后四位,顺丰需要填写(手机号后四位填一个就行,多填以寄件人为准)*/
private String com;
private String nu;
private String receiverPhone;
private String senderPhone;
}
@Data
public class ExpressListReqBody {
/* 名称 类型 是否必须 描述
expName STRING 可选 快递/物流公司名称,比如传入 顺丰
maxSize LONG 可选 分页时,每页返回的最大记录数
page LONG 可选 分页的页数*/
private String expName;
private Long maxSize;
private Long page;
}