Feat: 湖南ApiFix 2
This commit is contained in:
parent
e16d0f6c9c
commit
138c3558a0
|
|
@ -9,7 +9,7 @@ public enum ApiFrom {
|
||||||
LianTong(1L,"联通Api"),
|
LianTong(1L,"联通Api"),
|
||||||
GuangZhouDX(2L,"广州电信Api"),
|
GuangZhouDX(2L,"广州电信Api"),
|
||||||
HaiNanDX(3L,"海南电信Api"),
|
HaiNanDX(3L,"海南电信Api"),
|
||||||
HuNanDX(3L,"海南电信Api");
|
HuNanDX(4L,"湖南电信Api");
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final String name;
|
private final String name;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ public class ApiHuNanDXService extends ApiConfigService {
|
||||||
* @throws Exception 如果调用接口时发生异常
|
* @throws Exception 如果调用接口时发生异常
|
||||||
*/
|
*/
|
||||||
public HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryPhoneNumberResp>
|
public HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryPhoneNumberResp>
|
||||||
queryPhoneNumber(HaiNanDxInfo.QueryPhoneNumberParam param) throws Exception {
|
queryPhoneNumber( HaiNanDxInfo.NeedSignQueryParam<HaiNanDxInfo.QueryPhoneNumberParam> param) throws Exception {
|
||||||
return HuNanDXApi.queryPhoneNumber(getConfig(), param);
|
return HuNanDXApi.queryPhoneNumber(getConfig(), param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ public class ApiHuNanDXService extends ApiConfigService {
|
||||||
* @throws Exception 如果调用接口时发生异常
|
* @throws Exception 如果调用接口时发生异常
|
||||||
*/
|
*/
|
||||||
public HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.PossessPhoneNumberResp>
|
public HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.PossessPhoneNumberResp>
|
||||||
possessPhoneNumber(HaiNanDxInfo.PossessPhoneNumberParam param) throws Exception {
|
possessPhoneNumber(HaiNanDxInfo.NeedSignQueryParam<HaiNanDxInfo.PossessPhoneNumberParam> param) throws Exception {
|
||||||
return HuNanDXApi.possessPhoneNumber(getConfig(), param);
|
return HuNanDXApi.possessPhoneNumber(getConfig(), param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public class HaiNanDxInfo {
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class ResponseInfo<T> {
|
public static class ResponseInfo<T> {
|
||||||
|
private String code;
|
||||||
private String res_code; // 返回状态码
|
private String res_code; // 返回状态码
|
||||||
private String res_message; // 返回消息
|
private String res_message; // 返回消息
|
||||||
private JSONObject result; // 返回结果数据
|
private JSONObject result; // 返回结果数据
|
||||||
|
|
@ -125,7 +126,6 @@ public class HaiNanDxInfo {
|
||||||
private String retErrorInfo; // 返回信息
|
private String retErrorInfo; // 返回信息
|
||||||
private String retFlag; // 结果是否成功(0 成功,1 失败)
|
private String retFlag; // 结果是否成功(0 成功,1 失败)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 接口7、号码查询:qry.nmall.phoneNumberlList
|
// 接口7、号码查询:qry.nmall.phoneNumberlList
|
||||||
@Data
|
@Data
|
||||||
public static class QueryPhoneNumberParam {
|
public static class QueryPhoneNumberParam {
|
||||||
|
|
@ -141,6 +141,16 @@ public class HaiNanDxInfo {
|
||||||
private String areaCode; // 地市编码
|
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
|
@Data
|
||||||
public static class QueryPhoneNumberResp {
|
public static class QueryPhoneNumberResp {
|
||||||
private String respCode; // 返回状态码
|
private String respCode; // 返回状态码
|
||||||
|
|
|
||||||
|
|
@ -3,72 +3,94 @@ package cn.iocoder.yudao.module.haoka.api.hunandianxin;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
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.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.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.ssl.SSLContextBuilder;
|
||||||
import org.apache.http.util.EntityUtils;
|
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.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class HuNanDXApi {
|
public class HuNanDXApi {
|
||||||
|
|
||||||
|
|
||||||
// 接口1、校验互联网卡下单资格_新(BPS):chk.ordercheck.InternetCardQualifica
|
// 接口1、校验互联网卡下单资格_新(BPS):chk.ordercheck.InternetCardQualifica
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.InternetCardQualificationResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.InternetCardQualificationResp>
|
||||||
checkInternetCardQualification(HaiNanDxInfo.ConfigInfo config,
|
checkInternetCardQualification(HaiNanDxInfo.ConfigInfo config,
|
||||||
HaiNanDxInfo.InternetCardQualificationParam param) throws Exception {
|
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
|
// 接口2、同步订单信息给BPS:syn.orderinfo.SynJdServiceOrder
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.SyncOrderResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.SyncOrderResp>
|
||||||
syncOrder(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.SyncOrderParam param) throws Exception {
|
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
|
// 接口3、查询BPS业务订单详情:qry.order.QryBpsOrderInfo
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryOrderResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryOrderResp>
|
||||||
queryOrder(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.QueryOrderParam param) throws Exception {
|
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
|
// 接口5、短信渠道短信验证码发送:push.sms.sendsmsCode
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.SendSmsCodeResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.SendSmsCodeResp>
|
||||||
sendSmsCode(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.SendSmsCodeParam param) throws Exception {
|
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
|
// 接口6、短信渠道下发短信验证码是否验证通过:push.sms.sendsmsCodeYz
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.VerifySmsCodeResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.VerifySmsCodeResp>
|
||||||
verifySmsCode(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.VerifySmsCodeParam param) throws Exception {
|
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
|
// 接口7、号码查询:qry.nmall.phoneNumberlList
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryPhoneNumberResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryPhoneNumberResp>
|
||||||
queryPhoneNumber(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.QueryPhoneNumberParam param) throws Exception {
|
queryPhoneNumber(HaiNanDxInfo.ConfigInfo config,
|
||||||
return doExecute(config, "qry.nmall.phoneNumberlList", "num.query.normalList", param, HaiNanDxInfo.QueryPhoneNumberResp.class);
|
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
|
// 接口8、占用号码:qry.nmall.possessPhoneNumber
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.PossessPhoneNumberResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.PossessPhoneNumberResp>
|
||||||
possessPhoneNumber(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.PossessPhoneNumberParam param) throws Exception {
|
possessPhoneNumber(HaiNanDxInfo.ConfigInfo config,
|
||||||
return doExecute(config, "qry.nmall.possessPhoneNumber", param.getApiName(), param, HaiNanDxInfo.PossessPhoneNumberResp.class);
|
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
|
// 接口9、联系电话黑名单接口:getBlackDataByPhone
|
||||||
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.BlackListCheckResp>
|
public static HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.BlackListCheckResp>
|
||||||
checkBlackList(HaiNanDxInfo.ConfigInfo config, HaiNanDxInfo.BlackListCheckParam param) throws Exception {
|
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 调用方法
|
// 通用 API 调用方法
|
||||||
private static <T, R> HaiNanDxInfo.ResponseInfo<R>
|
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);
|
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);
|
HaiNanDxInfo.ResponseInfo responseInfo = JSON.parseObject(calledApi, HaiNanDxInfo.ResponseInfo.class);
|
||||||
|
|
||||||
JSONObject result = responseInfo.getResult();
|
JSONObject result = responseInfo.getResult();
|
||||||
|
|
@ -80,29 +102,45 @@ public class HuNanDXApi {
|
||||||
}
|
}
|
||||||
return objectResponseInfo;
|
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 调用方法
|
// 通用 API 调用方法
|
||||||
private static String callApi(HaiNanDxInfo.ConfigInfo config, String method, String apiName, JSONObject data) throws Exception {
|
private static String callApi(HaiNanDxInfo.ConfigInfo config, String method, JSONObject data) throws Exception {
|
||||||
// 生成签名
|
|
||||||
String sign = genSignFromMap(data, config.getSecret());
|
|
||||||
|
|
||||||
// 构建请求体
|
// 构建请求体
|
||||||
Map<String, Object> requestBody = new TreeMap<>();
|
Map<String, Object> requestBody = new TreeMap<>();
|
||||||
requestBody.put("access_token", config.getAccessToken());
|
requestBody.put("access_token", config.getAccessToken());
|
||||||
requestBody.put("method", method);
|
requestBody.put("method", method);
|
||||||
requestBody.put("version", "1.0");
|
requestBody.put("version", "1.0");
|
||||||
requestBody.put("content", data);
|
requestBody.put("content", data);
|
||||||
requestBody.put("sign", sign);
|
|
||||||
if (apiName != null) {
|
|
||||||
requestBody.put("apiName", apiName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送 HTTP 请求
|
// 发送 HTTP 请求
|
||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
try (CloseableHttpClient httpClient = createHttpClientIgnoreSSL()) {
|
||||||
HttpPost httpPost = new HttpPost(config.getBaseUrl());
|
HttpPost httpPost = new HttpPost(config.getBaseUrl());
|
||||||
httpPost.setHeader("Content-Type", "application/json; charset=UTF-8");
|
httpPost.setHeader("Content-Type", "application/json; charset=UTF-8");
|
||||||
httpPost.setEntity(new StringEntity(new ObjectMapper().writeValueAsString(requestBody)));
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,14 +61,14 @@ public class HaokaHuNanDXController {
|
||||||
@PostMapping("/queryPhoneNumber")
|
@PostMapping("/queryPhoneNumber")
|
||||||
@Operation(summary = "湖南电信-查询号码")
|
@Operation(summary = "湖南电信-查询号码")
|
||||||
public CommonResult<HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.QueryPhoneNumberResp>>
|
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));
|
return success(apiHuNanDXService.queryPhoneNumber(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/possessPhoneNumber")
|
@PostMapping("/possessPhoneNumber")
|
||||||
@Operation(summary = "湖南电信-占用号码")
|
@Operation(summary = "湖南电信-占用号码")
|
||||||
public CommonResult<HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.PossessPhoneNumberResp>>
|
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));
|
return success(apiHuNanDXService.possessPhoneNumber(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue