Feat: 湖南ApiFix
This commit is contained in:
parent
ff6b022eae
commit
0d2e9a763a
|
|
@ -1,42 +0,0 @@
|
|||
package cn.iocoder.yudao.module.haoka.api.hunan;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class HunanDXApi {
|
||||
public static String genSignFromMap(JSONObject data, String seckey) throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, Object> mapBody = mapper.readValue(data.toString(), Map.class);
|
||||
Map<String, String> params = (Map<String,String>) mapBody.get("data");
|
||||
|
||||
Map<String, String> map = new TreeMap<String, String>();
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
if(entry.getValue()==null||entry.getValue().equals("")){
|
||||
continue;
|
||||
}
|
||||
if (!entry.getKey().equals("sign")) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int index = 0;
|
||||
for(String _key:map.keySet()){
|
||||
if(index!=0){
|
||||
sb.append("&");
|
||||
}
|
||||
sb.append(_key);
|
||||
sb.append("=");
|
||||
sb.append(map.get(_key));
|
||||
index++;
|
||||
}
|
||||
|
||||
sb.append("&key=" + seckey);
|
||||
String md5 = MD5Utils.md5Digest(sb.toString()).toLowerCase();
|
||||
return md5;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package cn.iocoder.yudao.module.haoka.api.hunandianxin;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HaiNanDxInfo {
|
||||
@Data
|
||||
public static class ConfigInfo {
|
||||
private String accessToken; // access_token
|
||||
private String secret; // 密钥
|
||||
private String channel; // 渠道ID
|
||||
private String baseUrl;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ResponseInfo<T> {
|
||||
private String res_code;
|
||||
private String res_message;
|
||||
private JSONObject result;
|
||||
private T data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口1、校验互联网卡下单资格_新(BPS):chk.ordercheck.InternetCardQualifica
|
||||
*/
|
||||
@Data
|
||||
public static class InternetCardQualificationParam {
|
||||
private String cartNo; // 入网身份证
|
||||
private String serviceOrderSource; // 渠道ID
|
||||
private String serviceOrderSalesNumber; // 产品ID
|
||||
private String buyerName; // 入网姓名
|
||||
private String mobilePhone; // 联系电话
|
||||
private String receiverName; // 收货人姓名
|
||||
private String receiverProv; // 收货人所在省
|
||||
private String receiverCity; // 收货人所在市
|
||||
private String receiverDistrict; // 收货人所在区
|
||||
private String receiverAdress; // 收货人详细地址 Adress}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口1、校验互联网卡下单资格_新(BPS):chk.ordercheck.InternetCardQualifica
|
||||
* 响应类
|
||||
*/
|
||||
@Data
|
||||
public static class InternetCardQualificationResp {
|
||||
private String code;
|
||||
private String message;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package cn.iocoder.yudao.module.haoka.api.hunandianxin;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class HuNanDXApi {
|
||||
|
||||
|
||||
// 校验互联网卡下单资格接口
|
||||
public HaiNanDxInfo.ResponseInfo<HaiNanDxInfo.InternetCardQualificationResp>
|
||||
checkInternetCardQualification(HaiNanDxInfo.ConfigInfo config,
|
||||
HaiNanDxInfo.InternetCardQualificationParam param) throws Exception {
|
||||
String method = "chk.ordercheck.InternetCardQualifica";
|
||||
String apiName = null;
|
||||
return HuNanDXApi.doExecute(config,
|
||||
method,
|
||||
apiName,
|
||||
param,
|
||||
HaiNanDxInfo.InternetCardQualificationResp.class);
|
||||
}
|
||||
|
||||
private static <T, R> HaiNanDxInfo.ResponseInfo<R>
|
||||
doExecute(HaiNanDxInfo.ConfigInfo config,
|
||||
String method,
|
||||
String apiName,
|
||||
T data, Class<R> rClass) throws Exception {
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(data);
|
||||
String calledApi = callApi(config, method, apiName, jsonObject);
|
||||
HaiNanDxInfo.ResponseInfo responseInfo = JSON.parseObject(calledApi, HaiNanDxInfo.ResponseInfo.class);
|
||||
|
||||
JSONObject result = responseInfo.getResult();
|
||||
HaiNanDxInfo.ResponseInfo<R> objectResponseInfo = new HaiNanDxInfo.ResponseInfo<>();
|
||||
|
||||
if (result != null) {
|
||||
R dataInfo = result.toJavaObject(rClass);
|
||||
objectResponseInfo.setData(dataInfo);
|
||||
}
|
||||
return objectResponseInfo;
|
||||
}
|
||||
|
||||
|
||||
// 通用 API 调用方法
|
||||
private static String callApi(HaiNanDxInfo.ConfigInfo config, String method, String apiName, JSONObject data) throws Exception {
|
||||
// 生成签名
|
||||
String sign = genSignFromMap(data, config.getSecret());
|
||||
|
||||
// 构建请求体
|
||||
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()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String genSignFromMap(JSONObject data, String seckey) throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, Object> mapBody = mapper.readValue(data.toString(), Map.class);
|
||||
Map<String, String> params = (Map<String, String>) mapBody.get("data");
|
||||
|
||||
Map<String, String> map = new TreeMap<String, String>();
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
if (entry.getValue() == null || entry.getValue().equals("")) {
|
||||
continue;
|
||||
}
|
||||
if (!entry.getKey().equals("sign")) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int index = 0;
|
||||
for (String _key : map.keySet()) {
|
||||
if (index != 0) {
|
||||
sb.append("&");
|
||||
}
|
||||
sb.append(_key);
|
||||
sb.append("=");
|
||||
sb.append(map.get(_key));
|
||||
index++;
|
||||
}
|
||||
|
||||
sb.append("&key=" + seckey);
|
||||
String md5 = MD5Utils.md5Digest(sb.toString()).toLowerCase();
|
||||
return md5;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.haoka.api.hunan;
|
||||
package cn.iocoder.yudao.module.haoka.api.hunandianxin;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
Loading…
Reference in New Issue