添加一套连线客api

This commit is contained in:
huahua
2024-07-24 15:35:03 +08:00
parent f20b0a722a
commit f425ce9487

View File

@@ -6,6 +6,7 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zbkj.common.config.properties.SmsProperties;
import com.zbkj.common.constants.LxkOpenApiConstant;
import com.zbkj.common.constants.SysConfigConstants;
import com.zbkj.common.model.lxkopenapi.*;
import com.zbkj.common.response.lxkopenapi.Idcard.IdCardResult;
import com.zbkj.common.response.lxkopenapi.express.QueryExpressResult;
@@ -28,14 +29,24 @@ public class LxkOpenApiService {
private static final String HTTPS_URL_PREFIX = "https://saasmall.lianxianke.cn/lxk-api/";
@Autowired
private SmsProperties lxkOpenApiProperties;
@Autowired
private SystemConfigService systemConfigService;
private String getBaseUrl() {
String baseUrl = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_LXK_SERVER_API_URL);
if (StrUtil.isBlank(baseUrl)) {
baseUrl = HTTPS_URL_PREFIX;
}
return baseUrl;
}
private String getHttpsUrl(String openServiceApi) {
return String.format("%s%s", HTTPS_URL_PREFIX, openServiceApi);
return String.format("%s%s", getBaseUrl(), openServiceApi);
}
private String getHttpsPageURL(String openServiceApi, Integer pageSize, Integer pageNum, String orderByColumn, String isAsc) {
return String.format("%s%s?pageSize=%s&pageNum=%s&orderByColumn=%s&isAsc=%s",
HTTPS_URL_PREFIX, openServiceApi, pageSize, pageNum, orderByColumn, isAsc);
getBaseUrl(), openServiceApi, pageSize, pageNum, orderByColumn, isAsc);
}
/**
@@ -251,10 +262,10 @@ public class LxkOpenApiService {
jsonObject.put("no", queryExpressRequest.getNo());
log.info("查询物流,请求参数:{}", jsonObject);
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, QueryExpressResult.class);
}
@@ -267,11 +278,11 @@ public class LxkOpenApiService {
public UserPackageRecordResult expressRecord(PageQueryRequest pageQueryRequest) {
String httpsUrl = getExpressRecordURL(pageQueryRequest.getPageSize(), pageQueryRequest.getPageNum(), pageQueryRequest.getOrderByColumn(), pageQueryRequest.getIsAsc());
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, UserPackageRecordResult.class);
}
@@ -283,11 +294,11 @@ public class LxkOpenApiService {
public CommonInfoCountResult expressInfoCount() {
String httpsUrl = getExpressInfoCountURL();
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, CommonInfoCountResult.class);
}
@@ -305,10 +316,10 @@ public class LxkOpenApiService {
jsonObject.put("templateId", smsSendRequest.getTemplateId());
jsonObject.put("paramMap", smsSendRequest.getParamMap());
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, SendMesgResult.class);
}
@@ -326,10 +337,10 @@ public class LxkOpenApiService {
jsonObject.put("templateId", smsSendRequest.getTemplateId());
jsonObject.put("paramMap", smsSendRequest.getParamMap());
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, SendMesgResult.class);
}
@@ -342,11 +353,11 @@ public class LxkOpenApiService {
public UserPackageRecordResult smsRecord(PageQueryRequest pageQueryRequest) {
String httpsUrl = getSmsRecordURL(pageQueryRequest.getPageSize(), pageQueryRequest.getPageNum(), pageQueryRequest.getOrderByColumn(), pageQueryRequest.getIsAsc());
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, UserPackageRecordResult.class);
}
@@ -358,11 +369,11 @@ public class LxkOpenApiService {
public CommonInfoCountResult smsInfoCount() {
String httpsUrl = getSmsInfoCountURL();
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, CommonInfoCountResult.class);
}
@@ -378,10 +389,10 @@ public class LxkOpenApiService {
jsonObject.put("lng", geoLatLngRequest.getLng());
jsonObject.put("lat", geoLatLngRequest.getLat());
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, AddressGeoResult.class);
}
@@ -396,10 +407,10 @@ public class LxkOpenApiService {
JSONObject jsonObject = new JSONObject();
jsonObject.put("address", address);
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, AddressGeoResult.class);
}
@@ -413,11 +424,11 @@ public class LxkOpenApiService {
public UserPackageRecordResult geoRecord(PageQueryRequest pageQueryRequest) {
String httpsUrl = getGeoRecordURL(pageQueryRequest.getPageSize(), pageQueryRequest.getPageNum(), pageQueryRequest.getOrderByColumn(), pageQueryRequest.getIsAsc());
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, UserPackageRecordResult.class);
}
@@ -429,11 +440,11 @@ public class LxkOpenApiService {
public CommonInfoCountResult geoInfoCount() {
String httpsUrl = getGeoInfoCountURL();
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, CommonInfoCountResult.class);
}
@@ -451,10 +462,10 @@ public class LxkOpenApiService {
jsonObject.put("idCardNo", faceFaceRequest.getIdCardNo());
jsonObject.put("name", faceFaceRequest.getName());
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, FaceResult.class);
}
@@ -471,10 +482,10 @@ public class LxkOpenApiService {
jsonObject.put("idCardNo", facePlusRequest.getIdCardNo());
jsonObject.put("name", facePlusRequest.getName());
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, FaceResult.class);
}
@@ -496,10 +507,10 @@ public class LxkOpenApiService {
jsonObject.put("idCardNo", faceCompareRequest.getIdCardNo());
}
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, FaceResult.class);
}
@@ -512,11 +523,11 @@ public class LxkOpenApiService {
public UserPackageRecordResult facePlusRecord(PageQueryRequest pageQueryRequest) {
String httpsUrl = getFacePlusRecordURL(pageQueryRequest.getPageSize(), pageQueryRequest.getPageNum(), pageQueryRequest.getOrderByColumn(), pageQueryRequest.getIsAsc());
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, UserPackageRecordResult.class);
}
@@ -528,11 +539,11 @@ public class LxkOpenApiService {
public CommonInfoCountResult facePlusCount() {
String httpsUrl = getFacePlusInfoCountURL();
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, CommonInfoCountResult.class);
}
@@ -549,10 +560,10 @@ public class LxkOpenApiService {
jsonObject.put("name", verifyIdCardRequest.getName());
log.info(jsonObject.toJSONString(0));
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
log.info(result);
return JSONUtil.toBean(result, IdCardResult.class);
}
@@ -567,11 +578,11 @@ public class LxkOpenApiService {
public UserPackageRecordResult idCardRecord(PageQueryRequest pageQueryRequest) {
String httpsUrl = getIdCardRecordURL(pageQueryRequest.getPageSize(), pageQueryRequest.getPageNum(), pageQueryRequest.getOrderByColumn(), pageQueryRequest.getIsAsc());
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, UserPackageRecordResult.class);
}
@@ -583,11 +594,11 @@ public class LxkOpenApiService {
public CommonInfoCountResult idCardInfoCount() {
String httpsUrl = getIdCardInfoCountURL();
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, CommonInfoCountResult.class);
}
@@ -603,10 +614,10 @@ public class LxkOpenApiService {
jsonObject.put("content", verifyWordsRequest.getContent());
jsonObject.put("type", verifyWordsRequest.getType());
String result = HttpUtil.createPost(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.contentType("application/json")
.body(jsonObject.toJSONString(0)).execute().body();
return JSONUtil.toBean(result, VerifyWordsResult.class);
}
@@ -619,11 +630,11 @@ public class LxkOpenApiService {
public UserPackageRecordResult wordsRecord(PageQueryRequest pageQueryRequest) {
String httpsUrl = getWordsRecordURL(pageQueryRequest.getPageSize(), pageQueryRequest.getPageNum(), pageQueryRequest.getOrderByColumn(), pageQueryRequest.getIsAsc());
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, UserPackageRecordResult.class);
}
@@ -635,11 +646,11 @@ public class LxkOpenApiService {
public CommonInfoCountResult wordsInfoCount() {
String httpsUrl = getWordsInfoCountURL();
String result = HttpUtil.createGet(httpsUrl)
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
.header("access_key", lxkOpenApiProperties.getLxkAccessKey())
.header("secret_key", lxkOpenApiProperties.getLxkSecretKey())
.execute()
.charset("utf-8")
.body();
return JSONUtil.toBean(result, CommonInfoCountResult.class);
}
@@ -652,9 +663,9 @@ public class LxkOpenApiService {
public IpInfoResult getCurrentIp() {
String httpsUrl = getApiIpUrl();
String result = HttpUtil.createGet(httpsUrl)
.execute()
.charset("utf-8")
.body();
.execute()
.charset("utf-8")
.body();
IpResult ipResult = JSONUtil.toBean(result, IpResult.class);
return ipResult.getData();
}