From 8fd8f09d1e5865ca10278a7b9c526efbb6d0ee88 Mon Sep 17 00:00:00 2001 From: Owen <595466820@qq.com> Date: Thu, 2 Jan 2025 20:04:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=BF=E5=B7=9E=E7=94=B5=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/haoka/api/ApiHaiNanDXService.java | 19 +++++ .../api/hainandianxin/HaiNanDianXinApi.java | 78 +++++++++++++++---- .../admin/api/HaokaApiHaiNanDXController.java | 13 ++++ 3 files changed, 97 insertions(+), 13 deletions(-) diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHaiNanDXService.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHaiNanDXService.java index 76897ab24e..864d614316 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHaiNanDXService.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHaiNanDXService.java @@ -16,6 +16,8 @@ public class ApiHaiNanDXService extends ApiConfigService { public static final String Key_md5Key = "md5Key"; public static final String Key_publicKey = "publicKey"; public static final String Key_privateKey = "privateKey"; + public static final String Key_xAppId="xAppId"; + public static final String Key_xAppKey="xAppKey"; private HaiNanDianXinApi.HaiNanDianXinApiConfig getConfig() { Map devConfig = this.getDevConfig(); @@ -26,7 +28,11 @@ public class ApiHaiNanDXService extends ApiConfigService { String md5Key = devConfig.get(Key_md5Key); String publicKey = devConfig.get(Key_publicKey); String privateKey = devConfig.get(Key_privateKey); + String xAppId = devConfig.get(Key_xAppId); + String xAppKey = devConfig.get(Key_xAppKey); HaiNanDianXinApi.HaiNanDianXinApiConfig config = new HaiNanDianXinApi.HaiNanDianXinApiConfig(); + config.setXAppId(xAppId); + config.setXAppKey(xAppKey); config.setUrl(url); config.setAppCode(appCode); config.setAbilityCode(abilityCode); @@ -41,6 +47,19 @@ public class ApiHaiNanDXService extends ApiConfigService { return HaiNanDianXinApi.qryNbrList(logVO, this.getConfig(), param); } + /** + * 收货地址查询 + * + * @param logVO 日志记录对象 + * @param param 收货地址查询请求参数 + * @return 收货地址查询返回结果 + * @throws UnirestException 请求异常 + */ + public HaiNanDianXinApi.HaiNanResponseInfo + qryReceiveAddr(final SuperiorApiLogSaveReqVO logVO, HaiNanDianXinApi.QryReceiveAddrRequest param) throws UnirestException { + return HaiNanDianXinApi.qryReceiveAddr(logVO, this.getConfig(), param); + } + /** * 防诈校验接口查询 */ diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hainandianxin/HaiNanDianXinApi.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hainandianxin/HaiNanDianXinApi.java index f8226b6edf..d41f4cf847 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hainandianxin/HaiNanDianXinApi.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hainandianxin/HaiNanDianXinApi.java @@ -11,6 +11,7 @@ import lombok.Data; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import java.util.UUID; @@ -28,8 +29,11 @@ public class HaiNanDianXinApi { private String md5Key = "your_md5_key"; // 平台分配的密钥 private String publicKey = "your_rsa_public_key"; // RSA加密公钥 private String privateKey = ""; // RSA 私钥 + private String xAppId = ""; + private String xAppKey = ""; } + // {"message":"JTEOP: Missing APP ID found in request","reason":"APPID not found","code":"10001","referenceError":"","status":401} @Data public static class HaiNanResponseInfo { private T data; @@ -37,6 +41,10 @@ public class HaiNanDianXinApi { private String code; private String errMsg; private String resTime; + private String message; + private String reason; + private String referenceError; + private String status; } /** @@ -54,6 +62,48 @@ public class HaiNanDianXinApi { return config.appCode + ";" + abilityCode + ";" + transactionId + ";" + sign + ";" + reqTime; } + /** + * 收货地址查询 + * + * @param request 收货地址查询请求参数 + * @return 收货地址查询返回结果 + * @throws UnirestException 请求异常 + */ + public static HaiNanResponseInfo qryReceiveAddr(final SuperiorApiLogSaveReqVO logVO, HaiNanDianXinApiConfig config, QryReceiveAddrRequest request) throws UnirestException { + return doPost(logVO, config, "qryReceiveAddr", request, QryReceiveAddrResponse.class); + } + + /** + * 收货地址查询请求参数类 + */ + @Data + public static class QryReceiveAddrRequest { + private String addrLevel; // 查询地址等级 (1:省;2:市;3:区县;4:镇/街道) + private String parentName; // 上级地址名称(查省级地址时不传值) + private String parentCode; // 上级地址编码(查省级地址时不传值) + } + + /** + * 收货地址查询返回结果类 + */ + @Data + public static class QryReceiveAddrResponse { + private String code; // 状态编码:0:成功;-1:失败 + private String errMsg; // 失败原因 + private List addrList; // 收货地址列表 + private String resTime; // 请求返回时间 + } + + /** + * 收货地址信息类 + */ + @Data + public static class AddrInfo { + private String addrName; // 地址名称 + private String addrCode; // 地址编码 + private String addrLevel; // 地址等级 + } + /** * 防诈校验接口查询 * @@ -61,8 +111,8 @@ public class HaiNanDianXinApi { * @return 防诈校验返回结果 * @throws UnirestException 请求异常 */ - public static HaiNanResponseInfo fraudCheck(final SuperiorApiLogSaveReqVO logVO,HaiNanDianXinApiConfig config, FraudCheckRequest request) throws UnirestException { - return doPost( logVO,config, "fraudCheck", request, FraudCheckResponse.class); + public static HaiNanResponseInfo fraudCheck(final SuperiorApiLogSaveReqVO logVO, HaiNanDianXinApiConfig config, FraudCheckRequest request) throws UnirestException { + return doPost(logVO, config, "fraudCheck", request, FraudCheckResponse.class); } /** @@ -72,8 +122,8 @@ public class HaiNanDianXinApi { * @return 号码查询列表返回结果 * @throws UnirestException 请求异常 */ - public static HaiNanResponseInfo qryNbrList(final SuperiorApiLogSaveReqVO logVO,HaiNanDianXinApiConfig config, QryNbrListRequest request) throws UnirestException { - return doPost( logVO,config, "qryNbrList", request, QryNbrListResponse.class); + public static HaiNanResponseInfo qryNbrList(final SuperiorApiLogSaveReqVO logVO, HaiNanDianXinApiConfig config, QryNbrListRequest request) throws UnirestException { + return doPost(logVO, config, "qryNbrList", request, QryNbrListResponse.class); } /** @@ -83,8 +133,8 @@ public class HaiNanDianXinApi { * @return 订单信息查询返回结果 * @throws UnirestException 请求异常 */ - public static HaiNanResponseInfo queryOrderInfo(final SuperiorApiLogSaveReqVO logVO,HaiNanDianXinApiConfig config, QueryOrderInfoRequest request) throws UnirestException { - return doPost( logVO,config, "queryOrderInfo", request, QueryOrderInfoResponse.class); + public static HaiNanResponseInfo queryOrderInfo(final SuperiorApiLogSaveReqVO logVO, HaiNanDianXinApiConfig config, QueryOrderInfoRequest request) throws UnirestException { + return doPost(logVO, config, "queryOrderInfo", request, QueryOrderInfoResponse.class); } /** @@ -96,7 +146,7 @@ public class HaiNanDianXinApi { */ public static HaiNanResponseInfo getLogisticsTrajectory(final SuperiorApiLogSaveReqVO logVO, HaiNanDianXinApiConfig config, GetLogisticsTrajectoryRequest request) throws UnirestException { - return doPost( logVO,config, "getLogisticsTrajectory", request, GetLogisticsTrajectoryResponse.class); + return doPost(logVO, config, "getLogisticsTrajectory", request, GetLogisticsTrajectoryResponse.class); } /** @@ -106,8 +156,8 @@ public class HaiNanDianXinApi { * @return 号卡订单收敛返回结果 * @throws UnirestException 请求异常 */ - public static HaiNanResponseInfo synOrderInfo(final SuperiorApiLogSaveReqVO logVO,HaiNanDianXinApiConfig config, SynOrderInfoRequest request) throws UnirestException { - return doPost(logVO,config, "synOrderInfo", request, SynOrderInfoResponse.class); + public static HaiNanResponseInfo synOrderInfo(final SuperiorApiLogSaveReqVO logVO, HaiNanDianXinApiConfig config, SynOrderInfoRequest request) throws UnirestException { + return doPost(logVO, config, "synOrderInfo", request, SynOrderInfoResponse.class); } /** @@ -129,10 +179,12 @@ public class HaiNanDianXinApi { HttpResponse response = Unirest.post(config.url) .header("Content-Type", "application/json") .header("x-auth", xAuthHeader) + .header("X-APP-ID", config.xAppId) + .header("X-APP-KEY", config.xAppKey) .body(encryptedBody) .asString(); logVO.setResponse(response.getBody()); - return dealResponse(response, rClass); + return dealResponse(config, response, rClass); } /** @@ -143,7 +195,7 @@ public class HaiNanDianXinApi { * @param 返回结果泛型 * @return 返回结果 */ - private static HaiNanResponseInfo dealResponse(HttpResponse response, Class tClass) { + private static HaiNanResponseInfo dealResponse(HaiNanDianXinApiConfig config, HttpResponse response, Class tClass) { // int status = response.getStatus(); // if (status != 200) { // return null; @@ -154,9 +206,9 @@ public class HaiNanDianXinApi { }); String biz = haiNanResponseInfo.getBiz(); if (StringUtils.isNotEmpty(biz)) { - String bizDecrypt = UopRSAUtils.decryptByPrivateKey(body, biz); + String bizDecrypt = UopRSAUtils.decryptByPrivateKey(biz, config.getPrivateKey()); // T t = JSON.parseObject(bizDecrypt, tClass); - T t = JSON.parseObject(body, new TypeReference() { + T t = JSON.parseObject(bizDecrypt, new TypeReference() { }); haiNanResponseInfo.setData(t); } diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaApiHaiNanDXController.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaApiHaiNanDXController.java index d4e5c1a7ab..86ca59594b 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaApiHaiNanDXController.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaApiHaiNanDXController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +@PermitAll @Tag(name = "API---上游接口---海南电信") @RestController @RequestMapping("/haoka/api/hainan-dx") @@ -23,6 +24,14 @@ public class HaokaApiHaiNanDXController { @Resource private ApiHaiNanDXService apiHaiNanDXService; + @PermitAll + @PostMapping("/qryReceiveAddr") + @Operation(summary = "海南电信-收货地址查询接口") + public CommonResult> + qryReceiveAddr(@RequestBody HaiNanDianXinApi.QryReceiveAddrRequest param) throws UnirestException { + return success(apiHaiNanDXService.qryReceiveAddr(new SuperiorApiLogSaveReqVO(), param)); + } + @PermitAll @PostMapping("/qryNbrList") @Operation(summary = "海南电信-选号接口") @@ -31,6 +40,7 @@ public class HaokaApiHaiNanDXController { return success(apiHaiNanDXService.qryNbrList(new SuperiorApiLogSaveReqVO(), param)); } + @PermitAll @PostMapping("/fraudCheck") @Operation(summary = "海南电信-防诈校验接口") public CommonResult> @@ -38,6 +48,7 @@ public class HaokaApiHaiNanDXController { return success(apiHaiNanDXService.fraudCheck(new SuperiorApiLogSaveReqVO(), param)); } + @PermitAll @PostMapping("/queryOrderInfo") @Operation(summary = "海南电信-订单信息查询接口") public CommonResult> @@ -45,6 +56,7 @@ public class HaokaApiHaiNanDXController { return success(apiHaiNanDXService.queryOrderInfo(new SuperiorApiLogSaveReqVO(), param)); } + @PermitAll @PostMapping("/getLogisticsTrajectory") @Operation(summary = "海南电信-物流轨迹查询接口") public CommonResult> @@ -52,6 +64,7 @@ public class HaokaApiHaiNanDXController { return success(apiHaiNanDXService.getLogisticsTrajectory(new SuperiorApiLogSaveReqVO(), param)); } + @PermitAll @PostMapping("/synOrderInfo") @Operation(summary = "海南电信-号卡订单收敛接口") public CommonResult>