Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
a84a366703
|
@ -0,0 +1,105 @@
|
|||
package shkd.sys.sys.common;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description
|
||||
* @Author Tao
|
||||
* @Date 2024/11/14
|
||||
*/
|
||||
public class ApiEntity {
|
||||
private String URL;//链接
|
||||
private String method;//请求方式
|
||||
private Map<String, Object> queryParams;//请求参数
|
||||
private Map<String, Object> headers;//请求头参数
|
||||
private JSONObject requestBody;//请求体
|
||||
|
||||
public String getURL() {
|
||||
return URL;
|
||||
}
|
||||
|
||||
public void setURL(String URL) {
|
||||
this.URL = URL;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public Map<String, Object> getQueryParams() {
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
public void setQueryParams(Map<String, Object> queryParams) {
|
||||
this.queryParams = queryParams;
|
||||
}
|
||||
|
||||
public Map<String, Object> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void setHeaders(Map<String, Object> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public JSONObject getRequestBody() {
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
public void setRequestBody(JSONObject requestBody) {
|
||||
this.requestBody = requestBody;
|
||||
}
|
||||
|
||||
public ApiEntity(String URL, String method, Map<String, Object> queryParams, Map<String, Object> headers, JSONObject requestBody) {
|
||||
this.URL = URL;
|
||||
this.method = method;
|
||||
this.queryParams = queryParams;
|
||||
this.headers = headers;
|
||||
this.requestBody = requestBody;
|
||||
}
|
||||
|
||||
public ApiEntity() {
|
||||
}
|
||||
|
||||
public static JSONObject getResponseBody(ApiEntity apiEntity) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
Map<String, Object> heads = apiEntity.getHeaders();
|
||||
if (heads != null) {
|
||||
for (String key : heads.keySet()) {
|
||||
httpHeaders.add(key, heads.get(key).toString());
|
||||
}
|
||||
}
|
||||
|
||||
HttpEntity<Object> objectHttpEntity = new HttpEntity<>(httpHeaders);
|
||||
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(apiEntity.getURL());
|
||||
Map<String, Object> params = apiEntity.getQueryParams();
|
||||
if (params != null) {
|
||||
for (String key : params.keySet()) {
|
||||
uriComponentsBuilder.queryParam(key, params.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
HttpMethod method;
|
||||
if (apiEntity.getMethod().equals("POST")) {
|
||||
method = HttpMethod.POST;
|
||||
} else {
|
||||
method = HttpMethod.GET;
|
||||
}
|
||||
ResponseEntity<String> exchange = restTemplate.exchange(uriComponentsBuilder.build().toString(), method, objectHttpEntity, String.class);
|
||||
return JSONObject.parseObject(exchange.getBody());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
package shkd.sys.sys.mservice;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import shkd.sys.sys.common.ApiEntity;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.net.ssl.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description
|
||||
* @Author Tao
|
||||
* @Date 2024/11/11
|
||||
*/
|
||||
public class BIPService {
|
||||
private static final Log logger = LogFactory.getLog(BIPService.class);
|
||||
|
||||
public static String getBIPToken() {
|
||||
String access_token = null;
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
try {
|
||||
// 禁用 SSL 证书验证
|
||||
disableSSLCertificateChecking();
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
String appKey = "22564a240d3140d0b15582aca71a748c";
|
||||
String timestamp = String.valueOf(currentTimeMillis);
|
||||
String signature = generateSignature("appKey" + appKey + "timestamp" + timestamp);
|
||||
|
||||
// 构建URL
|
||||
String urlString = "https://biptest.ctny.com.cn/iuap-api-auth/open-auth/selfAppAuth/getAccessToken" +
|
||||
"?appKey=22564a240d3140d0b15582aca71a748c" +
|
||||
"×tamp=" + currentTimeMillis +
|
||||
"&signature=" + signature;
|
||||
|
||||
URL url = new URL(urlString);
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
// 读取响应
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
// 解析响应
|
||||
JSONObject jsonObject = JSON.parseObject(response.toString());
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
access_token = data.getString("access_token");
|
||||
logger.info("getBIPToken → 接口调用成功,access_token: {}", access_token);
|
||||
} else {
|
||||
logger.error("getBIPToken → 接口调用失败,状态码: {}", responseCode);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("getBIPToken → 调用接口报错: {}", e);
|
||||
}
|
||||
return access_token;
|
||||
}
|
||||
|
||||
public static SSLContext createInsecureSSLContext() throws Exception {
|
||||
// 创建一个信任所有证书的 TrustManager
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[0];
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 安装信任所有证书的 TrustManager
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
public static void disableSSLCertificateChecking() {
|
||||
try {
|
||||
// 创建一个信任所有证书的 SSLContext
|
||||
SSLContext sslContext = createInsecureSSLContext();
|
||||
|
||||
// 设置 HttpsURLConnection 使用这个 SSLContext
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
|
||||
|
||||
// 创建一个 HostnameVerifier,信任所有主机名
|
||||
HostnameVerifier allHostsValid = (hostname, session) -> true;
|
||||
|
||||
// 安装这个 HostnameVerifier
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static String generateSignature(String toSign) throws Exception {
|
||||
// 计算 HmacSHA256 签名
|
||||
byte[] hmacData = computeHmacSha256(toSign);
|
||||
|
||||
// Base64 编码
|
||||
String base64Encoded = Base64.getEncoder().encodeToString(hmacData);
|
||||
|
||||
// URL 编码
|
||||
return URLEncoder.encode(base64Encoded, StandardCharsets.UTF_8.toString());
|
||||
}
|
||||
|
||||
private static byte[] computeHmacSha256(String data) throws Exception {
|
||||
SecretKeySpec secretKey = new SecretKeySpec("79f0b7daa428c1abd9272565dbc65486ab565c80".getBytes(StandardCharsets.UTF_8), "HmacSHA256");
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(secretKey);
|
||||
return mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装推送BIP付款单JSON
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject paymentSlipsJson() {
|
||||
ApiEntity apiEntity = new ApiEntity();
|
||||
|
||||
JSONObject root = new JSONObject();
|
||||
|
||||
// 创建"data"节点
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
// 设置"data"节点的属性
|
||||
data.put("accentity_code", "SIG1040100");
|
||||
data.put("vouchdate", "2022-04-20");
|
||||
data.put("tradetype_code", "cmp_fund_payment_other");
|
||||
data.put("exchangeRateType_code", "01");
|
||||
data.put("exchRate", 1);
|
||||
data.put("currency_code", "CNY");
|
||||
data.put("_status", "Insert");
|
||||
|
||||
// 创建"FundPayment_b"列表
|
||||
JSONArray fundPaymentList = new JSONArray();
|
||||
|
||||
// 创建"FundPayment_b"列表中的第一个对象
|
||||
JSONObject fundPayment = new JSONObject();
|
||||
fundPayment.put("quickType_code", "6");
|
||||
fundPayment.put("settlestatus", "1");
|
||||
fundPayment.put("oriSum", 5000);
|
||||
fundPayment.put("caobject", 2);
|
||||
fundPayment.put("oppositeobjectname", "11510107MB1526717D");
|
||||
fundPayment.put("_status", "Insert");
|
||||
|
||||
// 将"FundPayment_b"对象添加到列表中
|
||||
fundPaymentList.add(fundPayment);
|
||||
// 将"FundPayment_b"列表添加到"data"节点中
|
||||
data.put("FundPayment_b", fundPaymentList);
|
||||
// 将"data"节点添加到根JSON对象中
|
||||
root.put("data", data);
|
||||
|
||||
apiEntity.setURL("");
|
||||
apiEntity.setRequestBody(root);
|
||||
apiEntity.setMethod("POST");
|
||||
|
||||
Map<String, Object> queryParams = new HashMap<>();
|
||||
queryParams.put("access_token", getBIPToken());
|
||||
apiEntity.setQueryParams(queryParams);
|
||||
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("Content-Type", "application/json");
|
||||
apiEntity.setHeaders(headers);
|
||||
|
||||
return ApiEntity.getResponseBody(apiEntity);
|
||||
}
|
||||
}
|
|
@ -63,22 +63,26 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
|
|||
//收款人ID
|
||||
fieldName1 = "payee";
|
||||
|
||||
|
||||
Object payeebankObj = map.get("payeebank");
|
||||
Map<String, Object> payeebankMap = (Map<String, Object>) payeebankObj;
|
||||
bankNumber = (String) payeebankMap.get("number");
|
||||
|
||||
Map<String, Object> payeebankObj = (Map<String, Object>) map.get("payeebank");
|
||||
bankNumber = (String) payeebankObj.get("number");
|
||||
logger.info("付款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber);
|
||||
|
||||
fieldName2 = "payerbank";
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray());
|
||||
logger.info("objectType:{},objectNumber:{}", objectType, objectNumber);
|
||||
DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray());
|
||||
logger.info("amAccountbank:{}", amAccountbank);
|
||||
map.put(fieldName1, dynamicObject.getString("id"));
|
||||
|
||||
DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id,number", new QFilter("number", QCP.equals, objectNumber).toArray());
|
||||
logger.info("dynamicObjects.length:{}", dynamicObjects.length);
|
||||
if (dynamicObjects.length > 0) {
|
||||
map.put(fieldName1, dynamicObjects[0].getPkValue());
|
||||
logger.info("dynamicObjects[0]:{}", dynamicObjects[0]);
|
||||
}
|
||||
|
||||
DynamicObject[] amAccountbanks = BusinessDataServiceHelper.load("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray());
|
||||
logger.info("amAccountbanks.length:{}", amAccountbanks.length);
|
||||
Map<String, Object> payerbank = new HashMap<>();
|
||||
payerbank.put("number", amAccountbank.getDynamicObject("bank").getString("number"));
|
||||
if (amAccountbanks.length > 0) {
|
||||
payerbank.put("number", amAccountbanks[0].getDynamicObject("bank").getString("number"));
|
||||
logger.info("amAccountbanks[0]:{}", amAccountbanks[0]);
|
||||
}
|
||||
logger.info("payerbank:{}", payerbank);
|
||||
map.put(fieldName2, payerbank);
|
||||
}
|
||||
|
||||
|
@ -88,19 +92,24 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
|
|||
fieldName1 = "payer";
|
||||
|
||||
|
||||
Object accountbank = map.get("accountbank");
|
||||
Map<String, Object> accountbankMap = (Map<String, Object>) accountbank;
|
||||
bankNumber = (String) accountbankMap.get("number");
|
||||
|
||||
Map<String, Object> accountbank = (Map<String, Object>) map.get("accountbank");
|
||||
bankNumber = (String) accountbank.get("number");
|
||||
logger.info("收款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber);
|
||||
fieldName2 = "payeebank";
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray());
|
||||
logger.info("objectType:{},objectNumber:{}", objectType, objectNumber);
|
||||
DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray());
|
||||
logger.info("amAccountbank:{}", amAccountbank);
|
||||
map.put(fieldName1, dynamicObject.getString("id"));
|
||||
DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id,number", new QFilter("number", QCP.equals, objectNumber).toArray());
|
||||
logger.info("dynamicObjects.length:{}", dynamicObjects.length);
|
||||
if (dynamicObjects.length > 0) {
|
||||
map.put(fieldName1, dynamicObjects[0].getPkValue());
|
||||
logger.info("dynamicObjects[0]:{}", dynamicObjects[0]);
|
||||
}
|
||||
|
||||
DynamicObject[] amAccountbanks = BusinessDataServiceHelper.load("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray());
|
||||
logger.info("amAccountbanks.length:{}", amAccountbanks.length);
|
||||
Map<String, Object> payeebank = new HashMap<>();
|
||||
payeebank.put("number", amAccountbank.getDynamicObject("bank").getString("number"));
|
||||
if (amAccountbanks.length > 0) {
|
||||
payeebank.put("number", amAccountbanks[0].getDynamicObject("bank").getString("number"));
|
||||
}
|
||||
logger.info("payerbank:{}", payeebank);
|
||||
map.put(fieldName2, payeebank);
|
||||
}
|
||||
shkd_businessid = map.get("shkd_businessid").toString();
|
||||
|
@ -133,7 +142,9 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin
|
|||
} else {
|
||||
logger.info("进入else");
|
||||
//其他类型的出参序列化
|
||||
return null;
|
||||
String responseStr = new ObjectMapper().writeValueAsString(response);
|
||||
JSONObject jsonObject = JSON.parseObject(responseStr);
|
||||
return new SerializerResult(MediaType.TEXT_PLAIN, jsonObject.toJSONString());
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.info("catch");
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package shkd.sys.sys.plugin.form;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import kd.bos.form.control.Toolbar;
|
||||
import kd.bos.form.control.events.ItemClickEvent;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import shkd.sys.sys.mservice.BIPService;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
* 单据界面插件
|
||||
*/
|
||||
public class ApiTestBillPlugin extends AbstractBillPlugIn implements Plugin {
|
||||
@Override
|
||||
public void registerListener(EventObject e) {
|
||||
// super.registerListener(e);
|
||||
|
||||
// 获取工具栏,监听整个工具栏
|
||||
Toolbar save = this.getView().getControl("tbmain");
|
||||
// 监听工具栏这个按钮的点击事件
|
||||
save.addItemClickListener(this);
|
||||
|
||||
// 获取除了工具栏上的其他按钮
|
||||
// Button save = this.getView().getControl("qwz5_baritemap");
|
||||
// save.addClickListener(this); // 添加出菜单栏点击事件监听
|
||||
}
|
||||
@Override
|
||||
public void itemClick(ItemClickEvent evt) {
|
||||
super.itemClick(evt);
|
||||
// 获取键
|
||||
String key = evt.getItemKey();
|
||||
|
||||
if ("shkd_token".equals(key)) {
|
||||
String bipToken = BIPService.getBIPToken();
|
||||
this.getView().showTipNotification(bipToken);
|
||||
}
|
||||
|
||||
if ("shkd_api".equals(key)) {
|
||||
JSONObject jsonObject = BIPService.paymentSlipsJson();
|
||||
this.getView().showTipNotification(jsonObject.toJSONString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue