|
@@ -1,48 +1,47 @@
|
|
|
package com.ruoyi.web.controller.sf;
|
|
|
|
|
|
-
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.system.domain.sf.SfBean;
|
|
|
+import com.ruoyi.system.domain.sf.SfRespVo;
|
|
|
+import com.ruoyi.system.domain.wx.WxPayOrderReqVo;
|
|
|
import com.sf.csim.express.service.CallExpressServiceTools;
|
|
|
import com.sf.csim.express.service.HttpClientUtil;
|
|
|
import com.sf.csim.express.service.IServiceCodeStandard;
|
|
|
import com.sf.csim.express.service.code.ExpressServiceCodeEnum;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import springfox.documentation.spring.web.SpringfoxWebMvcConfiguration;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* @Author: tjf
|
|
|
- * @Date: 2024/1/16 17:08
|
|
|
+ * @Date: 2024/1/18 14:54
|
|
|
* @Describe:
|
|
|
*/
|
|
|
-public class CallExpressNewAPIServiceUtil {
|
|
|
+@RestController
|
|
|
+@RequestMapping("/sf")
|
|
|
+public class SfExpressController {
|
|
|
|
|
|
- /**
|
|
|
- * 丰桥新沙箱测试顾客编码 Yg4Zf06w_sxZs3A5D
|
|
|
- * 校验码 3Xdk1jqeG1Xod9nUXus8Op7DNOkchTnw
|
|
|
- **/
|
|
|
- //此处替换为您在丰桥平台获取的顾客编码
|
|
|
- private static final String CLIENT_CODE = "ZXYJS48Y74BY";
|
|
|
- //生产校验码
|
|
|
- private static final String CHECK_WORD = "BoSL7gKn7aFKht0E0OwEePsM1oo0oJxG";
|
|
|
- //沙箱校验码
|
|
|
- private static final String CHECK_WORD_BOX = "sl0E3IdF3leaRDEOQXKmSKUY1ybg36j9";
|
|
|
+ @Resource
|
|
|
+ private SfBean sfBean;
|
|
|
|
|
|
- //沙箱环境的地址 -PRO
|
|
|
- private static final String CALL_URL_BOX = "https://sfapi-sbox.sf-express.com/std/service";
|
|
|
- //生产环境的地址 -PRO
|
|
|
- private static final String CALL_URL_PROD = "https://bspgw.sf-express.com/std/service";
|
|
|
- /**
|
|
|
- * @Description: 调用顺丰API方法
|
|
|
- * checkPhoneNo:电话号码验证手机号后四位
|
|
|
- * trackingType: 顺丰运单号
|
|
|
- * @Date: 2023/3/20 17:25
|
|
|
- **/
|
|
|
- public static JSONArray callSFApi(String checkPhoneNo , String trackingType) throws Exception {
|
|
|
- //验证请求参数
|
|
|
- if (StringUtils.isEmpty(checkPhoneNo) || StringUtils.isEmpty(trackingType)) {
|
|
|
+ @PostMapping("/callSFApi")
|
|
|
+ public AjaxResult callSfApi(@RequestBody SfRespVo sfRespVo) throws Exception {
|
|
|
+ //验证请求参数
|
|
|
+ if (StringUtils.isEmpty(sfRespVo.getCheckPhoneNo()) || StringUtils.isEmpty(sfRespVo.getTrackingType())) {
|
|
|
throw new Exception("参数不能为空!");
|
|
|
}
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
@@ -50,18 +49,18 @@ public class CallExpressNewAPIServiceUtil {
|
|
|
//查询号类别 1:根据顺丰运单号查询,trackingNumber将被当作顺丰运单号处理
|
|
|
jsonObject.put("trackingType", "1");
|
|
|
//快递单号
|
|
|
- jsonObject.put("trackingNumber", trackingType);
|
|
|
+ jsonObject.put("trackingNumber", sfRespVo.getTrackingType());
|
|
|
//1:标准路由查询
|
|
|
jsonObject.put("methodType", "1");
|
|
|
//收件人手机号码后4位
|
|
|
- jsonObject.put("checkPhoneNo", checkPhoneNo);
|
|
|
+ jsonObject.put("checkPhoneNo", sfRespVo.getCheckPhoneNo());
|
|
|
String msgData = jsonObject.toString();
|
|
|
IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ROUTES;
|
|
|
// set common header
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
String timeStamp = String.valueOf(System.currentTimeMillis());
|
|
|
// 顾客编码 ,对应丰桥上获取的clientCode
|
|
|
- params.put("partnerID", CLIENT_CODE);
|
|
|
+ params.put("partnerID", sfBean.getClientCode());
|
|
|
//请求唯一号UUID
|
|
|
params.put("requestID", UUID.randomUUID().toString().replace("-", ""));
|
|
|
// 接口服务码
|
|
@@ -71,26 +70,26 @@ public class CallExpressNewAPIServiceUtil {
|
|
|
//报文
|
|
|
params.put("msgData", msgData);
|
|
|
//数字签名
|
|
|
- params.put("msgDigest", CallExpressServiceTools.getMsgDigest(msgData, timeStamp, CHECK_WORD));
|
|
|
+ params.put("msgDigest", CallExpressServiceTools.getMsgDigest(msgData, timeStamp, sfBean.getCheckWord()));
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
System.out.println("====调用实际请求:" + params);
|
|
|
- String result = HttpClientUtil.post(CALL_URL_PROD, params);
|
|
|
- System.out.println("====调用丰桥的接口服务代码:" + String.valueOf(standardService.getCode()) + " 接口耗时:"+ String.valueOf(System.currentTimeMillis()-startTime)+"====");
|
|
|
- System.out.println("===调用地址 ===" + CALL_URL_PROD);
|
|
|
- System.out.println("===顾客编码 ===" + CLIENT_CODE);
|
|
|
+ String result = HttpClientUtil.post(sfBean.getCallUrlProd(), params);
|
|
|
+ System.out.println("====调用丰桥的接口服务代码:" + String.valueOf(standardService.getCode()) + " 接口耗时:" + String.valueOf(System.currentTimeMillis() - startTime) + "====");
|
|
|
+ System.out.println("===调用地址 ===" + sfBean.getCallUrlProd());
|
|
|
+ System.out.println("===顾客编码 ===" + sfBean.getClientCode());
|
|
|
System.out.println("===返回结果:" + result);
|
|
|
JSONObject apiResultData = JSONUtil.parseObj(JSONUtil.parseObj(result).get("apiResultData"));
|
|
|
- if(!apiResultData.getBool("success")){
|
|
|
+ if (!apiResultData.getBool("success")) {
|
|
|
throw new Exception("暂无物流信息");
|
|
|
}
|
|
|
JSONObject resultMsgData = JSONUtil.parseObj(apiResultData.get("msgData"));
|
|
|
JSONArray routeResps = JSONUtil.parseArray(resultMsgData.get("routeResps"));
|
|
|
JSONArray routes = routeResps.getJSONObject(0).getJSONArray("routes");
|
|
|
- if (routes.isEmpty()){
|
|
|
+ if (routes.isEmpty()) {
|
|
|
throw new Exception("暂无物流信息");
|
|
|
}
|
|
|
//根据时间翻转
|
|
|
- Collections.reverse(routes);
|
|
|
- return routes;
|
|
|
+ routeResps.getJSONObject(0).put("routes",routeResps.getJSONObject(0).getJSONArray("routes"));
|
|
|
+ return AjaxResult.success(routeResps);
|
|
|
}
|
|
|
}
|