暂时先这样,需要搁平台的key和secret
This commit is contained in:
@@ -62,7 +62,16 @@
|
||||
<artifactId>zopsdk</artifactId>
|
||||
<version>0.11</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yundasys</groupId>
|
||||
<artifactId>kfpt-sdk</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zto.zop</groupId>
|
||||
<artifactId>zopsdk</artifactId>
|
||||
<version>0.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,12 @@ public class DynamicMailConfig {
|
||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
|
||||
// 设置SMTP服务器
|
||||
mailSender.setHost(account.getSmtpHost());
|
||||
// 判断是否为网易企业邮箱(如 freeqiye.com)
|
||||
if (account.getEmail() != null && account.getEmail().toLowerCase().endsWith("@freeqiye.com")) {
|
||||
mailSender.setHost("smtp.qiye.163.com");
|
||||
} else {
|
||||
mailSender.setHost(account.getSmtpHost());
|
||||
}
|
||||
mailSender.setPort(account.getSmtpPort() == null ? 465 : account.getSmtpPort().intValue());
|
||||
mailSender.setUsername(account.getEmail());
|
||||
mailSender.setPassword(account.getPassword());
|
||||
|
||||
@@ -162,6 +162,30 @@ public class OaExpressServiceImpl implements IOaExpressService {
|
||||
oaExpressVo.setLastUpdateTime(oaExpressVo1.getAcceptTime());
|
||||
oaExpressVo.setLastStatus(oaExpressVo1.getFirstStatusName());
|
||||
}
|
||||
}else if (expressType.equals("YD") && oaExpressVo.getStatus() == 1L) {
|
||||
// 韵达快递轨迹查询
|
||||
String result = com.ruoyi.oa.utils.YdRouteQueryUtil.queryRoute(oaExpressVo.getExpressCode());
|
||||
OaExpressVo ydVo = com.ruoyi.oa.utils.YdRouteQueryUtil.parseData(result);
|
||||
if (ydVo != null) {
|
||||
oaExpressVo.setLastUpdateTime(ydVo.getLastUpdateTime());
|
||||
oaExpressVo.setLastStatus(ydVo.getLastStatus());
|
||||
}
|
||||
} else if (expressType.equals("YT") && oaExpressVo.getStatus() == 1L) {
|
||||
// 圆通快递轨迹查询
|
||||
String result = com.ruoyi.oa.utils.YtRouteQueryUtil.queryRoute(oaExpressVo.getExpressCode());
|
||||
OaExpressVo ytVo = com.ruoyi.oa.utils.YtRouteQueryUtil.parseData(result);
|
||||
if (ytVo != null) {
|
||||
oaExpressVo.setLastUpdateTime(ytVo.getLastUpdateTime());
|
||||
oaExpressVo.setLastStatus(ytVo.getLastStatus());
|
||||
}
|
||||
} else if (expressType.equals("STO") && oaExpressVo.getStatus() == 1L) {
|
||||
// 申通快递轨迹查询
|
||||
String result = com.ruoyi.oa.utils.StoRouteQueryUtil.queryRoute(oaExpressVo.getExpressCode());
|
||||
OaExpressVo stoVo = com.ruoyi.oa.utils.StoRouteQueryUtil.parseData(result);
|
||||
if (stoVo != null) {
|
||||
oaExpressVo.setLastUpdateTime(stoVo.getLastUpdateTime());
|
||||
oaExpressVo.setLastStatus(stoVo.getLastStatus());
|
||||
}
|
||||
}
|
||||
OaExpress add = BeanUtil.toBean(oaExpressVo, OaExpress.class);
|
||||
baseMapper.updateById(add);;
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.ruoyi.oa.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.oa.domain.vo.OaExpressVo;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ZtoRouteQueryUtil {
|
||||
// 请填写你自己的key/secret
|
||||
private static final String APP_KEY = "";
|
||||
private static final String APP_SECRET = "";
|
||||
private static final String API_URL = "https://japi.zto.com/traceInterfaceNewTraces"; // 中通轨迹查询接口
|
||||
|
||||
/**
|
||||
* 查询中通轨迹
|
||||
* @param mailNo 运单号
|
||||
* @return 查询结果JSON
|
||||
*/
|
||||
public static String queryRoute(String mailNo) {
|
||||
try {
|
||||
// 构造请求参数,具体参数请参考中通官方文档
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("company_id", APP_KEY);
|
||||
params.put("msg_type", "NEW_TRACES");
|
||||
params.put("data", "[{\"billCode\":\"" + mailNo + "\"}]");
|
||||
params.put("data_digest", ""); // 签名算法见官方文档
|
||||
// 其他参数可根据实际需求补充
|
||||
|
||||
String jsonParams = params.toJSONString();
|
||||
URL url = new URL(API_URL);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
conn.setUseCaches(false);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||
OutputStream out = conn.getOutputStream();
|
||||
out.write(jsonParams.getBytes(StandardCharsets.UTF_8));
|
||||
out.flush();
|
||||
out.close();
|
||||
StringBuilder sbResult = new StringBuilder();
|
||||
if (200 == conn.getResponseCode()) {
|
||||
BufferedReader responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
|
||||
String readLine;
|
||||
while ((readLine = responseReader.readLine()) != null) {
|
||||
sbResult.append(readLine).append("\n");
|
||||
}
|
||||
responseReader.close();
|
||||
}
|
||||
return sbResult.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析中通返回数据,转为OaExpressVo
|
||||
*/
|
||||
public static OaExpressVo parseData(String result) {
|
||||
if (result == null || result.isEmpty()) return null;
|
||||
try {
|
||||
JSONObject json = JSON.parseObject(result);
|
||||
// 具体字段请根据中通返回格式调整
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
if (data == null) return null;
|
||||
OaExpressVo vo = new OaExpressVo();
|
||||
vo.setExpressCode(data.getString("billCode"));
|
||||
vo.setLastStatus(data.getString("status"));
|
||||
vo.setLastUpdateTime(data.getDate("updateTime"));
|
||||
// 你可以根据实际返回内容补充更多字段
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 中通签名算法 body+appSecret,MD5后Base64
|
||||
public static String sign(String body, String secret) {
|
||||
String text = body + secret;
|
||||
byte[] md5 = DigestUtils.md5(text);
|
||||
return Base64.encodeBase64String(md5);
|
||||
}
|
||||
|
||||
// main方法测试
|
||||
public static void main(String[] args) {
|
||||
String mailNo = "测试单号";
|
||||
String body = "{\"billCode\":\"" + mailNo + "\"}";
|
||||
String secret = "你的密钥";
|
||||
String sign = sign(body, secret);
|
||||
System.out.println("中通签名:" + sign);
|
||||
String result = queryRoute(mailNo); // 你可以根据实际参数完善queryRoute
|
||||
System.out.println("中通原始返回:" + result);
|
||||
OaExpressVo vo = parseData(result);
|
||||
System.out.println("解析后:" + vo);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@
|
||||
from oa_express_question oeq
|
||||
left join oa_express oe on oe.express_id = oeq.express_id
|
||||
${ew.getCustomSqlSegment}
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user