diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiFrom.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiFrom.java index cfadaa22b6..ffa500ef12 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiFrom.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiFrom.java @@ -9,7 +9,7 @@ public enum ApiFrom { LianTong(1L,"联通Api"), GuangZhouDX(2L,"广州电信Api"), HaiNanDX(3L,"海南电信Api"), - HuNanDX(3L,"海南电信Api"); + HuNanDX(4L,"湖南电信Api"); private final Long id; private final String name; } diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHuNanDXService.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHuNanDXService.java index 7ea59d5866..37d9ede081 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHuNanDXService.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/ApiHuNanDXService.java @@ -100,7 +100,7 @@ public class ApiHuNanDXService extends ApiConfigService { * @throws Exception 如果调用接口时发生异常 */ public HaiNanDxInfo.ResponseInfo - queryPhoneNumber(HaiNanDxInfo.QueryPhoneNumberParam param) throws Exception { + queryPhoneNumber( HaiNanDxInfo.NeedSignQueryParam param) throws Exception { return HuNanDXApi.queryPhoneNumber(getConfig(), param); } @@ -112,7 +112,7 @@ public class ApiHuNanDXService extends ApiConfigService { * @throws Exception 如果调用接口时发生异常 */ public HaiNanDxInfo.ResponseInfo - possessPhoneNumber(HaiNanDxInfo.PossessPhoneNumberParam param) throws Exception { + possessPhoneNumber(HaiNanDxInfo.NeedSignQueryParam param) throws Exception { return HuNanDXApi.possessPhoneNumber(getConfig(), param); } diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HaiNanDxInfo.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HaiNanDxInfo.java index de1b4c0708..7e4ca819ff 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HaiNanDxInfo.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HaiNanDxInfo.java @@ -17,6 +17,7 @@ public class HaiNanDxInfo { @Data public static class ResponseInfo { + private String code; private String res_code; // 返回状态码 private String res_message; // 返回消息 private JSONObject result; // 返回结果数据 @@ -125,7 +126,6 @@ public class HaiNanDxInfo { private String retErrorInfo; // 返回信息 private String retFlag; // 结果是否成功(0 成功,1 失败) } - // 接口7、号码查询:qry.nmall.phoneNumberlList @Data public static class QueryPhoneNumberParam { @@ -141,6 +141,16 @@ public class HaiNanDxInfo { private String areaCode; // 地市编码 } + // 接口7、号码查询:qry.nmall.phoneNumberlList + @Data + public static class NeedSignQueryParam { + private String apiName; + private String channel; + private String sign; + private String timestamp; + private T data; + } + @Data public static class QueryPhoneNumberResp { private String respCode; // 返回状态码 diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HuNanDXApi.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HuNanDXApi.java index c08174d85a..a6cb908a1c 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HuNanDXApi.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/api/hunandianxin/HuNanDXApi.java @@ -3,72 +3,94 @@ package cn.iocoder.yudao.module.haoka.api.hunandianxin; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.util.EntityUtils; +import javax.net.ssl.SSLContext; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; import java.util.Map; import java.util.TreeMap; +@Slf4j public class HuNanDXApi { - // 接口1、校验互联网卡下单资格_新(BPS):chk.ordercheck.InternetCardQualifica public static HaiNanDxInfo.ResponseInfo checkInternetCardQualification(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.InternetCardQualificationParam param) throws Exception { - return doExecute(config, "chk.ordercheck.InternetCardQualifica", null, param, HaiNanDxInfo.InternetCardQualificationResp.class); + return doExecute(config, "chk.ordercheck.InternetCardQualifica", param, HaiNanDxInfo.InternetCardQualificationResp.class); } // 接口2、同步订单信息给BPS:syn.orderinfo.SynJdServiceOrder public static HaiNanDxInfo.ResponseInfo syncOrder(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.SyncOrderParam param) throws Exception { - return doExecute(config, "syn.orderinfo.SynJdServiceOrder", null, param, HaiNanDxInfo.SyncOrderResp.class); + return doExecute(config, "syn.orderinfo.SynJdServiceOrder", param, HaiNanDxInfo.SyncOrderResp.class); } // 接口3、查询BPS业务订单详情:qry.order.QryBpsOrderInfo public static HaiNanDxInfo.ResponseInfo queryOrder(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.QueryOrderParam param) throws Exception { - return doExecute(config, "qry.order.QryBpsOrderInfo", null, param, HaiNanDxInfo.QueryOrderResp.class); + return doExecute(config, "qry.order.QryBpsOrderInfo", param, HaiNanDxInfo.QueryOrderResp.class); } // 接口5、短信渠道短信验证码发送:push.sms.sendsmsCode public static HaiNanDxInfo.ResponseInfo sendSmsCode(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.SendSmsCodeParam param) throws Exception { - return doExecute(config, "push.sms.sendsmsCode", null, param, HaiNanDxInfo.SendSmsCodeResp.class); + return doExecute(config, "push.sms.sendsmsCode", param, HaiNanDxInfo.SendSmsCodeResp.class); } // 接口6、短信渠道下发短信验证码是否验证通过:push.sms.sendsmsCodeYz public static HaiNanDxInfo.ResponseInfo verifySmsCode(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.VerifySmsCodeParam param) throws Exception { - return doExecute(config, "push.sms.sendsmsCodeYz", null, param, HaiNanDxInfo.VerifySmsCodeResp.class); + return doExecute(config, "push.sms.sendsmsCodeYz", param, HaiNanDxInfo.VerifySmsCodeResp.class); } // 接口7、号码查询:qry.nmall.phoneNumberlList public static HaiNanDxInfo.ResponseInfo - queryPhoneNumber(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.QueryPhoneNumberParam param) throws Exception { - return doExecute(config, "qry.nmall.phoneNumberlList", "num.query.normalList", param, HaiNanDxInfo.QueryPhoneNumberResp.class); + queryPhoneNumber(HaiNanDxInfo.ConfigInfo config, + HaiNanDxInfo.NeedSignQueryParam param) throws Exception { + // 生成签名 + JSONObject jsonObject = (JSONObject) JSON.toJSON(param); + String sign = genSignFromMap(jsonObject, config.getSecret()); + param.setSign(sign); + return doExecute(config, "qry.nmall.phoneNumberlList", param, HaiNanDxInfo.QueryPhoneNumberResp.class); } // 接口8、占用号码:qry.nmall.possessPhoneNumber public static HaiNanDxInfo.ResponseInfo - possessPhoneNumber(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.PossessPhoneNumberParam param) throws Exception { - return doExecute(config, "qry.nmall.possessPhoneNumber", param.getApiName(), param, HaiNanDxInfo.PossessPhoneNumberResp.class); + possessPhoneNumber(HaiNanDxInfo.ConfigInfo config, + HaiNanDxInfo.NeedSignQueryParam param) throws Exception { + // 生成签名 + JSONObject jsonObject = (JSONObject) JSON.toJSON(param); + String sign = genSignFromMap(jsonObject, config.getSecret()); + param.setSign(sign); + return doExecute(config, "qry.nmall.possessPhoneNumber", param, HaiNanDxInfo.PossessPhoneNumberResp.class); } // 接口9、联系电话黑名单接口:getBlackDataByPhone public static HaiNanDxInfo.ResponseInfo checkBlackList(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.BlackListCheckParam param) throws Exception { - return doExecute(config, "getBlackDataByPhone", null, param, HaiNanDxInfo.BlackListCheckResp.class); + return doExecute(config, "getBlackDataByPhone", param, HaiNanDxInfo.BlackListCheckResp.class); } // 通用 API 调用方法 private static HaiNanDxInfo.ResponseInfo - doExecute(HaiNanDxInfo.ConfigInfo config, String method, String apiName, T data, Class rClass) throws Exception { + doExecute(HaiNanDxInfo.ConfigInfo config, String method, T data, Class rClass) throws Exception { JSONObject jsonObject = (JSONObject) JSON.toJSON(data); - String calledApi = callApi(config, method, apiName, jsonObject); + String calledApi = callApi(config, method, jsonObject); + System.out.println("-------{}--" + calledApi); HaiNanDxInfo.ResponseInfo responseInfo = JSON.parseObject(calledApi, HaiNanDxInfo.ResponseInfo.class); JSONObject result = responseInfo.getResult(); @@ -80,29 +102,45 @@ public class HuNanDXApi { } return objectResponseInfo; } + private static CloseableHttpClient createHttpClientIgnoreSSL() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { + // 创建信任所有证书的TrustStrategy + TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; + + // 创建SSLContext,并使用信任所有证书的TrustManager + SSLContext sslContext = SSLContextBuilder.create() + .loadTrustMaterial(null, acceptingTrustStrategy) + .build(); + + // 创建SSLConnectionSocketFactory,忽略主机名验证 + SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); + + // 创建HttpClient + return HttpClients.custom() + .setSSLSocketFactory(sslSocketFactory) + .build(); + } // 通用 API 调用方法 - private static String callApi(HaiNanDxInfo.ConfigInfo config, String method, String apiName, JSONObject data) throws Exception { - // 生成签名 - String sign = genSignFromMap(data, config.getSecret()); - + private static String callApi(HaiNanDxInfo.ConfigInfo config, String method, JSONObject data) throws Exception { // 构建请求体 Map requestBody = new TreeMap<>(); requestBody.put("access_token", config.getAccessToken()); requestBody.put("method", method); requestBody.put("version", "1.0"); requestBody.put("content", data); - requestBody.put("sign", sign); - if (apiName != null) { - requestBody.put("apiName", apiName); - } // 发送 HTTP 请求 - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + try (CloseableHttpClient httpClient = createHttpClientIgnoreSSL()) { HttpPost httpPost = new HttpPost(config.getBaseUrl()); httpPost.setHeader("Content-Type", "application/json; charset=UTF-8"); httpPost.setEntity(new StringEntity(new ObjectMapper().writeValueAsString(requestBody))); - return EntityUtils.toString(httpClient.execute(httpPost).getEntity()); + + + CloseableHttpResponse response = httpClient.execute(httpPost); + String string = EntityUtils.toString(response.getEntity()); + log.info("Response Code: " + response.getStatusLine().getStatusCode()); + httpClient.close(); + return string; } } diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaHuNanDXController.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaHuNanDXController.java index ce35d8d295..555a60ee53 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaHuNanDXController.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/api/HaokaHuNanDXController.java @@ -61,14 +61,14 @@ public class HaokaHuNanDXController { @PostMapping("/queryPhoneNumber") @Operation(summary = "湖南电信-查询号码") public CommonResult> - queryPhoneNumber(@RequestBody HaiNanDxInfo.QueryPhoneNumberParam param) throws Exception { + queryPhoneNumber(@RequestBody HaiNanDxInfo.NeedSignQueryParam param) throws Exception { return success(apiHuNanDXService.queryPhoneNumber(param)); } @PostMapping("/possessPhoneNumber") @Operation(summary = "湖南电信-占用号码") public CommonResult> - possessPhoneNumber(@RequestBody HaiNanDxInfo.PossessPhoneNumberParam param) throws Exception { + possessPhoneNumber(@RequestBody HaiNanDxInfo.NeedSignQueryParam param) throws Exception { return success(apiHuNanDXService.possessPhoneNumber(param)); }