|
@@ -26,6 +26,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StopWatch;
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.net.URLConnection;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
@@ -66,17 +72,23 @@ public class UnionRequestService extends SuperService {
|
|
|
apiConfParam.setApiName(url);
|
|
apiConfParam.setApiName(url);
|
|
|
apiConfParam.setMethodType(MethodType.Json);
|
|
apiConfParam.setMethodType(MethodType.Json);
|
|
|
|
|
|
|
|
- data = "A";
|
|
|
|
|
|
|
+// data = "A";
|
|
|
|
|
+// JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+// jsonObject.set("requestTimestamp", "2024-08-30 14:54:41");
|
|
|
|
|
+// data = jsonObject.toString();
|
|
|
|
|
+// log.info("data: {}", data);
|
|
|
|
|
+
|
|
|
// String sign = sign(JSONUtil.parseObj(JSONUtil.toJsonStr(data)));
|
|
// String sign = sign(JSONUtil.parseObj(JSONUtil.toJsonStr(data)));
|
|
|
- String sign = AesUtils.signData(String.valueOf(data));
|
|
|
|
|
|
|
+ String str = JSONUtil.toJsonStr(data);
|
|
|
|
|
+ log.info("str: {}", str);
|
|
|
|
|
+ String sign = AesUtils.signData(str);
|
|
|
log.info("sign: {}", sign);
|
|
log.info("sign: {}", sign);
|
|
|
-
|
|
|
|
|
|
|
+// url += "?requestTimestamp=2024-08-30 14:54:41";
|
|
|
|
|
|
|
|
// 请求时间记时
|
|
// 请求时间记时
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
stopWatch.start();
|
|
stopWatch.start();
|
|
|
|
|
|
|
|
-
|
|
|
|
|
String timestamp = DateUtils.paresTime(System.currentTimeMillis(), DateUtils.unionAuth);
|
|
String timestamp = DateUtils.paresTime(System.currentTimeMillis(), DateUtils.unionAuth);
|
|
|
String nonce = CommonUtil.UUID();
|
|
String nonce = CommonUtil.UUID();
|
|
|
Map<String, Object> header = new HashMap<>();
|
|
Map<String, Object> header = new HashMap<>();
|
|
@@ -85,29 +97,28 @@ public class UnionRequestService extends SuperService {
|
|
|
log.info("appId: {}", UnionPaymentConfig.appId);
|
|
log.info("appId: {}", UnionPaymentConfig.appId);
|
|
|
log.info("timestamp: {}", timestamp);
|
|
log.info("timestamp: {}", timestamp);
|
|
|
log.info("nonce: {}", nonce);
|
|
log.info("nonce: {}", nonce);
|
|
|
|
|
+ log.info("appKey: {}", UnionPaymentConfig.appKey);
|
|
|
|
|
|
|
|
- String signature = AesUtils.signMacSHA256(c, UnionPaymentConfig.payKey);
|
|
|
|
|
|
|
+ String signature = AesUtils.signMacSHA256(c, UnionPaymentConfig.appKey);
|
|
|
log.info("signature: {}", signature);
|
|
log.info("signature: {}", signature);
|
|
|
- String sig = String.format("AppId=%s,Timestamp=%s,Nonce=%s,Signature=%s",
|
|
|
|
|
- UnionPaymentConfig.appId, timestamp, nonce, signature);
|
|
|
|
|
|
|
|
|
|
- header.put("OPEN-BODY-SIG", sig);
|
|
|
|
|
|
|
+ String sig = "OPEN-BODY-SIG AppId=" + "\"" + UnionPaymentConfig.appId + "\""
|
|
|
|
|
+ + ",Timestamp=" + "\"" + timestamp + "\""
|
|
|
|
|
+ + ",Nonce=" + "\"" + nonce + "\""
|
|
|
|
|
+ + ",Signature=" + "\"" + signature + "\"";
|
|
|
|
|
+ log.info("sig: {}", sig);
|
|
|
|
|
|
|
|
- header.put("Authorization", sig);
|
|
|
|
|
|
|
+ header.put("authorization", sig);
|
|
|
|
|
+ header.put("Content-Type", "application/json");
|
|
|
|
|
+ header.put("Accept_Charset", "UTF-8");
|
|
|
|
|
|
|
|
- header.put("AppId", UnionPaymentConfig.appId);
|
|
|
|
|
- header.put("Timestamp", timestamp);
|
|
|
|
|
- header.put("Nonce", nonce);
|
|
|
|
|
- header.put("Signature", signature);
|
|
|
|
|
-
|
|
|
|
|
- // 发送请求
|
|
|
|
|
|
|
+ log.info("url: {}", url);
|
|
|
HttpModel httpModel = HttpModel.builder()
|
|
HttpModel httpModel = HttpModel.builder()
|
|
|
.url(url).method(apiConfParam.getMethodType())
|
|
.url(url).method(apiConfParam.getMethodType())
|
|
|
.charset("utf-8").body(data).build();
|
|
.charset("utf-8").body(data).build();
|
|
|
|
|
|
|
|
httpModel.setHeader(header);
|
|
httpModel.setHeader(header);
|
|
|
ResponseModel request = HttpClientUtil.request(httpModel);
|
|
ResponseModel request = HttpClientUtil.request(httpModel);
|
|
|
-
|
|
|
|
|
int code = request.getCode();
|
|
int code = request.getCode();
|
|
|
if (code == 200) {
|
|
if (code == 200) {
|
|
|
BeanUtil.copyProperties(request.getBody(), responseModel);
|
|
BeanUtil.copyProperties(request.getBody(), responseModel);
|
|
@@ -116,7 +127,7 @@ public class UnionRequestService extends SuperService {
|
|
|
} else {
|
|
} else {
|
|
|
BeanUtil.copyProperties(request.getBody(), responseModel);
|
|
BeanUtil.copyProperties(request.getBody(), responseModel);
|
|
|
}
|
|
}
|
|
|
- log.info("response: {}", responseModel.getErrCode());
|
|
|
|
|
|
|
+ log.info("response: {} {}", responseModel.getErrCode(), code);
|
|
|
responseModel.setCode(code);
|
|
responseModel.setCode(code);
|
|
|
stopWatch.stop();
|
|
stopWatch.stop();
|
|
|
responseModel.setMillis(stopWatch.getTotalTimeMillis());
|
|
responseModel.setMillis(stopWatch.getTotalTimeMillis());
|