Explorar o código

fix 顺丰查询接口优化

Administrator hai 1 ano
pai
achega
2b3875c0f0

+ 8 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/news/BomanNewsController.java

@@ -3,6 +3,7 @@ package com.ruoyi.web.controller.news;
 import java.util.List;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
 
+import com.ruoyi.news.domain.BomanNews;
 import com.ruoyi.news.service.IBomanNewsService;
 import com.ruoyi.news.service.IBomanNewsService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,10 +38,10 @@ public class BomanNewsController extends BaseController
      */
      */
     //@PreAuthorize("@ss.hasPermi('new:news:list')")
     //@PreAuthorize("@ss.hasPermi('new:news:list')")
     @GetMapping("/list")
     @GetMapping("/list")
-    public TableDataInfo list(com.ruoyi.news.domain.BomanNews bomanNews)
+    public TableDataInfo list(BomanNews bomanNews)
     {
     {
         startPage();
         startPage();
-        List<com.ruoyi.news.domain.BomanNews> list = bomanNewsService.selectBomanNewsList(bomanNews);
+        List<BomanNews> list = bomanNewsService.selectBomanNewsList(bomanNews);
         return getDataTable(list);
         return getDataTable(list);
     }
     }
 
 
@@ -50,10 +51,10 @@ public class BomanNewsController extends BaseController
     @PreAuthorize("@ss.hasPermi('new:news:export')")
     @PreAuthorize("@ss.hasPermi('new:news:export')")
     @Log(title = "boman_news", businessType = BusinessType.EXPORT)
     @Log(title = "boman_news", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     @PostMapping("/export")
-    public void export(HttpServletResponse response, com.ruoyi.news.domain.BomanNews bomanNews)
+    public void export(HttpServletResponse response, BomanNews bomanNews)
     {
     {
-        List<com.ruoyi.news.domain.BomanNews> list = bomanNewsService.selectBomanNewsList(bomanNews);
-        ExcelUtil<com.ruoyi.news.domain.BomanNews> util = new ExcelUtil<com.ruoyi.news.domain.BomanNews>(com.ruoyi.news.domain.BomanNews.class);
+        List<BomanNews> list = bomanNewsService.selectBomanNewsList(bomanNews);
+        ExcelUtil<BomanNews> util = new ExcelUtil<BomanNews>(BomanNews.class);
         util.exportExcel(response, list, "boman_news数据");
         util.exportExcel(response, list, "boman_news数据");
     }
     }
 
 
@@ -73,7 +74,7 @@ public class BomanNewsController extends BaseController
     @PreAuthorize("@ss.hasPermi('new:news:add')")
     @PreAuthorize("@ss.hasPermi('new:news:add')")
     @Log(title = "boman_news", businessType = BusinessType.INSERT)
     @Log(title = "boman_news", businessType = BusinessType.INSERT)
     @PostMapping
     @PostMapping
-    public AjaxResult add(@RequestBody com.ruoyi.news.domain.BomanNews bomanNews)
+    public AjaxResult add(@RequestBody BomanNews bomanNews)
     {
     {
         return toAjax(bomanNewsService.insertBomanNews(bomanNews));
         return toAjax(bomanNewsService.insertBomanNews(bomanNews));
     }
     }
@@ -84,7 +85,7 @@ public class BomanNewsController extends BaseController
     @PreAuthorize("@ss.hasPermi('new:news:edit')")
     @PreAuthorize("@ss.hasPermi('new:news:edit')")
     @Log(title = "boman_news", businessType = BusinessType.UPDATE)
     @Log(title = "boman_news", businessType = BusinessType.UPDATE)
     @PostMapping("/put")
     @PostMapping("/put")
-    public AjaxResult edit(@RequestBody com.ruoyi.news.domain.BomanNews bomanNews)
+    public AjaxResult edit(@RequestBody BomanNews bomanNews)
     {
     {
         return toAjax(bomanNewsService.updateBomanNews(bomanNews));
         return toAjax(bomanNewsService.updateBomanNews(bomanNews));
     }
     }

+ 38 - 39
ruoyi-admin/src/main/java/com/ruoyi/web/controller/sf/CallExpressNewAPIServiceUtil.java → ruoyi-admin/src/main/java/com/ruoyi/web/controller/sf/SfExpressController.java

@@ -1,48 +1,47 @@
 package com.ruoyi.web.controller.sf;
 package com.ruoyi.web.controller.sf;
 
 
-
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.json.JSONUtil;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.StringUtils;
 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.CallExpressServiceTools;
 import com.sf.csim.express.service.HttpClientUtil;
 import com.sf.csim.express.service.HttpClientUtil;
 import com.sf.csim.express.service.IServiceCodeStandard;
 import com.sf.csim.express.service.IServiceCodeStandard;
 import com.sf.csim.express.service.code.ExpressServiceCodeEnum;
 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
  * @Author: tjf
- * @Date: 2024/1/16 17:08
+ * @Date: 2024/1/18 14:54
  * @Describe:
  * @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("参数不能为空!");
             throw new Exception("参数不能为空!");
         }
         }
         JSONObject jsonObject = new JSONObject();
         JSONObject jsonObject = new JSONObject();
@@ -50,18 +49,18 @@ public class CallExpressNewAPIServiceUtil {
         //查询号类别 1:根据顺丰运单号查询,trackingNumber将被当作顺丰运单号处理
         //查询号类别 1:根据顺丰运单号查询,trackingNumber将被当作顺丰运单号处理
         jsonObject.put("trackingType", "1");
         jsonObject.put("trackingType", "1");
         //快递单号
         //快递单号
-        jsonObject.put("trackingNumber", trackingType);
+        jsonObject.put("trackingNumber", sfRespVo.getTrackingType());
         //1:标准路由查询
         //1:标准路由查询
         jsonObject.put("methodType", "1");
         jsonObject.put("methodType", "1");
         //收件人手机号码后4位
         //收件人手机号码后4位
-        jsonObject.put("checkPhoneNo", checkPhoneNo);
+        jsonObject.put("checkPhoneNo", sfRespVo.getCheckPhoneNo());
         String msgData = jsonObject.toString();
         String msgData = jsonObject.toString();
         IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ROUTES;
         IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ROUTES;
         // set common header
         // set common header
         Map<String, String> params = new HashMap<String, String>();
         Map<String, String> params = new HashMap<String, String>();
         String timeStamp = String.valueOf(System.currentTimeMillis());
         String timeStamp = String.valueOf(System.currentTimeMillis());
         // 顾客编码 ,对应丰桥上获取的clientCode
         // 顾客编码 ,对应丰桥上获取的clientCode
-        params.put("partnerID", CLIENT_CODE);
+        params.put("partnerID", sfBean.getClientCode());
         //请求唯一号UUID
         //请求唯一号UUID
         params.put("requestID", UUID.randomUUID().toString().replace("-", ""));
         params.put("requestID", UUID.randomUUID().toString().replace("-", ""));
         // 接口服务码
         // 接口服务码
@@ -71,26 +70,26 @@ public class CallExpressNewAPIServiceUtil {
         //报文
         //报文
         params.put("msgData", msgData);
         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();
         long startTime = System.currentTimeMillis();
         System.out.println("====调用实际请求:" + params);
         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);
         System.out.println("===返回结果:" + result);
         JSONObject apiResultData = JSONUtil.parseObj(JSONUtil.parseObj(result).get("apiResultData"));
         JSONObject apiResultData = JSONUtil.parseObj(JSONUtil.parseObj(result).get("apiResultData"));
-        if(!apiResultData.getBool("success")){
+        if (!apiResultData.getBool("success")) {
             throw new Exception("暂无物流信息");
             throw new Exception("暂无物流信息");
         }
         }
         JSONObject resultMsgData = JSONUtil.parseObj(apiResultData.get("msgData"));
         JSONObject resultMsgData = JSONUtil.parseObj(apiResultData.get("msgData"));
         JSONArray routeResps = JSONUtil.parseArray(resultMsgData.get("routeResps"));
         JSONArray routeResps = JSONUtil.parseArray(resultMsgData.get("routeResps"));
         JSONArray routes = routeResps.getJSONObject(0).getJSONArray("routes");
         JSONArray routes = routeResps.getJSONObject(0).getJSONArray("routes");
-        if (routes.isEmpty()){
+        if (routes.isEmpty()) {
             throw new Exception("暂无物流信息");
             throw new Exception("暂无物流信息");
         }
         }
         //根据时间翻转
         //根据时间翻转
-        Collections.reverse(routes);
-        return routes;
+        routeResps.getJSONObject(0).put("routes",routeResps.getJSONObject(0).getJSONArray("routes"));
+        return AjaxResult.success(routeResps);
     }
     }
 }
 }

+ 10 - 2
ruoyi-admin/src/main/resources/application.yml

@@ -70,7 +70,7 @@ xss:
   # 过滤开关
   # 过滤开关
   enabled: true
   enabled: true
   # 排除链接(多个用逗号分隔)
   # 排除链接(多个用逗号分隔)
-  excludes: /system/notice
+  excludes: /system/notice,/new/news,/new/news/put
   # 匹配链接
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*
   urlPatterns: /system/*,/monitor/*,/tool/*
 
 
@@ -105,4 +105,12 @@ ali:
   # 接口内容加密密钥 对此密钥
   # 接口内容加密密钥 对此密钥
    content-key: +ZyQ==
    content-key: +ZyQ==
   #页面跳转同步通知页面   测试地址  后期需要修改为实际地址
   #页面跳转同步通知页面   测试地址  后期需要修改为实际地址
-   return-url: https://www.baidu.com/
+   return-url: https://www.baidu.com/
+#顺风配置
+sf:
+  #此处替换为您在丰桥平台获取的顾客编码
+  client-code: ZXYJS48Y74BY
+  #生产校验码
+  check-word: BoSL7gKn7aFKht0E0OwEePsM1oo0oJxG
+  #生产环境的地址 -PRO
+  call-url-prod: https://bspgw.sf-express.com/std/service

+ 51 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/sf/SfBean.java

@@ -0,0 +1,51 @@
+package com.ruoyi.system.domain.sf;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * 顺丰配置
+ * @Author: tjf
+ * @Date: 2024/1/18 14:56
+ * @Describe:
+ */
+@Component
+@ConfigurationProperties(prefix = "sf")
+public class SfBean {
+    private String clientCode;
+    private String checkWord;
+    private String callUrlProd;
+
+    public String getClientCode() {
+        return clientCode;
+    }
+
+    public void setClientCode(String clientCode) {
+        this.clientCode = clientCode;
+    }
+
+    public String getCheckWord() {
+        return checkWord;
+    }
+
+    public void setCheckWord(String checkWord) {
+        this.checkWord = checkWord;
+    }
+
+    public String getCallUrlProd() {
+        return callUrlProd;
+    }
+
+    public void setCallUrlProd(String callUrlProd) {
+        this.callUrlProd = callUrlProd;
+    }
+
+    @Override
+    public String toString() {
+        return "SfBean{" +
+                "clientCode='" + clientCode + '\'' +
+                ", checkWord='" + checkWord + '\'' +
+                ", callUrlProd='" + callUrlProd + '\'' +
+                '}';
+    }
+}

+ 41 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/sf/SfRespVo.java

@@ -0,0 +1,41 @@
+package com.ruoyi.system.domain.sf;
+
+/**
+ * @Author: tjf
+ * @Date: 2024/1/18 15:05
+ * @Describe:
+ */
+public class SfRespVo {
+    /**
+     * 手机号后四位
+     */
+    private String checkPhoneNo;
+    /**
+     * 顺丰单号
+     */
+    private String trackingType;
+
+    public String getCheckPhoneNo() {
+        return checkPhoneNo;
+    }
+
+    public void setCheckPhoneNo(String checkPhoneNo) {
+        this.checkPhoneNo = checkPhoneNo;
+    }
+
+    public String getTrackingType() {
+        return trackingType;
+    }
+
+    public void setTrackingType(String trackingType) {
+        this.trackingType = trackingType;
+    }
+
+    @Override
+    public String toString() {
+        return "SfRespVo{" +
+                "checkPhoneNo='" + checkPhoneNo + '\'' +
+                ", trackingType='" + trackingType + '\'' +
+                '}';
+    }
+}