Feat: 湖南ApiFix 2

This commit is contained in:
Owen 2024-12-29 01:14:51 +08:00
parent e16d0f6c9c
commit 138c3558a0
5 changed files with 77 additions and 29 deletions

View File

@ -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;
}

View File

@ -100,7 +100,7 @@ public class ApiHuNanDXService extends ApiConfigService {
* @throws Exception 如果调用接口时发生异常
*/
public HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryPhoneNumberResp>
queryPhoneNumber(HaiNanDxInfo.QueryPhoneNumberParam param) throws Exception {
queryPhoneNumber( HaiNanDxInfo.NeedSignQueryParam<HaiNanDxInfo.QueryPhoneNumberParam> param) throws Exception {
return HuNanDXApi.queryPhoneNumber(getConfig(), param);
}
@ -112,7 +112,7 @@ public class ApiHuNanDXService extends ApiConfigService {
* @throws Exception 如果调用接口时发生异常
*/
public HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.PossessPhoneNumberResp>
possessPhoneNumber(HaiNanDxInfo.PossessPhoneNumberParam param) throws Exception {
possessPhoneNumber(HaiNanDxInfo.NeedSignQueryParam<HaiNanDxInfo.PossessPhoneNumberParam> param) throws Exception {
return HuNanDXApi.possessPhoneNumber(getConfig(), param);
}

View File

@ -17,6 +17,7 @@ public class HaiNanDxInfo {
@Data
public static class ResponseInfo<T> {
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<T> {
private String apiName;
private String channel;
private String sign;
private String timestamp;
private T data;
}
@Data
public static class QueryPhoneNumberResp {
private String respCode; // 返回状态码

View File

@ -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<HaiNanDxInfo.InternetCardQualificationResp>
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同步订单信息给BPSsyn.orderinfo.SynJdServiceOrder
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.SyncOrderResp>
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<HaiNanDxInfo.QueryOrderResp>
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<HaiNanDxInfo.SendSmsCodeResp>
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<HaiNanDxInfo.VerifySmsCodeResp>
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<HaiNanDxInfo.QueryPhoneNumberResp>
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<HaiNanDxInfo.QueryPhoneNumberParam> 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<HaiNanDxInfo.PossessPhoneNumberResp>
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<HaiNanDxInfo.PossessPhoneNumberParam> 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<HaiNanDxInfo.BlackListCheckResp>
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 <T, R> HaiNanDxInfo.ResponseInfo<R>
doExecute(HaiNanDxInfo.ConfigInfo config, String method, String apiName, T data, Class<R> rClass) throws Exception {
doExecute(HaiNanDxInfo.ConfigInfo config, String method, T data, Class<R> 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<String, Object> 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;
}
}

View File

@ -61,14 +61,14 @@ public class HaokaHuNanDXController {
@PostMapping("/queryPhoneNumber")
@Operation(summary = "湖南电信-查询号码")
public CommonResult<HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryPhoneNumberResp>>
queryPhoneNumber(@RequestBody HaiNanDxInfo.QueryPhoneNumberParam param) throws Exception {
queryPhoneNumber(@RequestBody HaiNanDxInfo.NeedSignQueryParam<HaiNanDxInfo.QueryPhoneNumberParam> param) throws Exception {
return success(apiHuNanDXService.queryPhoneNumber(param));
}
@PostMapping("/possessPhoneNumber")
@Operation(summary = "湖南电信-占用号码")
public CommonResult<HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.PossessPhoneNumberResp>>
possessPhoneNumber(@RequestBody HaiNanDxInfo.PossessPhoneNumberParam param) throws Exception {
possessPhoneNumber(@RequestBody HaiNanDxInfo.NeedSignQueryParam<HaiNanDxInfo.PossessPhoneNumberParam> param) throws Exception {
return success(apiHuNanDXService.possessPhoneNumber(param));
}