|
@@ -0,0 +1,68 @@
|
|
|
+package com.fjhx.uitl.kd100;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fjhx.config.KD100Config;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.kuaidi100.sdk.api.QueryTrack;
|
|
|
+import com.kuaidi100.sdk.core.IBaseClient;
|
|
|
+import com.kuaidi100.sdk.pojo.HttpResult;
|
|
|
+import com.kuaidi100.sdk.request.QueryTrackParam;
|
|
|
+import com.kuaidi100.sdk.request.QueryTrackReq;
|
|
|
+import com.kuaidi100.sdk.utils.SignUtils;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.tool.api.ResultCode;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+
|
|
|
+@Log4j2
|
|
|
+public class KD100Util {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实时快递查询接口
|
|
|
+ *
|
|
|
+ * @param com 快递公司编码
|
|
|
+ * @param num 快递单号
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static JSONObject queryTrack(String com, String num) {
|
|
|
+ HttpResult result = new HttpResult();
|
|
|
+ try {
|
|
|
+ QueryTrackReq queryTrackReq = new QueryTrackReq();
|
|
|
+ QueryTrackParam queryTrackParam = new QueryTrackParam();
|
|
|
+ queryTrackParam.setCom(com);
|
|
|
+ queryTrackParam.setNum(num);
|
|
|
+ String param = new Gson().toJson(queryTrackParam);
|
|
|
+
|
|
|
+ queryTrackReq.setParam(param);
|
|
|
+ queryTrackReq.setCustomer(KD100Config.getCustomer());
|
|
|
+ queryTrackReq.setSign(SignUtils.querySign(param, KD100Config.getKey(), KD100Config.getCustomer()));
|
|
|
+
|
|
|
+ IBaseClient baseClient = new QueryTrack();
|
|
|
+ result = baseClient.execute(queryTrackReq);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.toString());
|
|
|
+ throw new ServiceException("请求第三方快递信息异常,请联系管理员!");
|
|
|
+ }
|
|
|
+ return parseData(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析数据
|
|
|
+ *
|
|
|
+ * @param result 数据结果
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static JSONObject parseData(HttpResult result) {
|
|
|
+ if (Func.isNotEmpty(result) && result.getStatus() == ResultCode.SUCCESS.getCode()) {
|
|
|
+ JSONObject body = JSONObject.parseObject(result.getBody());
|
|
|
+ if (Func.isNotEmpty(body.get("message")) && StringUtils.equalsIgnoreCase(body.getString("message"), "ok")) {
|
|
|
+ return body;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("操作失败,原因:物流信息【" + body.getString("message") + "】,请稍后重试!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("物流信息查询失败,请稍后重试,或者联系管理员!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|