|
|
@@ -20,9 +20,6 @@ public class PayRequest {
|
|
|
*/
|
|
|
private static final String ALG_SM = "SM";
|
|
|
|
|
|
- private static java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
|
|
|
- private static java.util.Base64.Decoder decoder = java.util.Base64.getDecoder();
|
|
|
-
|
|
|
/**
|
|
|
* 支付请求统一方法
|
|
|
*
|
|
|
@@ -57,9 +54,9 @@ public class PayRequest {
|
|
|
jObject.add("signature", sign);
|
|
|
String source = DCHelper.serialJsonOrdered(jObject);
|
|
|
System.out.println("签名原文: " + source);
|
|
|
- byte[] signature1 = DCCryptor.CMBSM2SignWithSM3(getID_IV(userid), decoder.decode(prvKey), source.getBytes(
|
|
|
+ byte[] signature1 = DCCryptor.CMBSM2SignWithSM3(getID_IV(userid), Base64.decode(prvKey), source.getBytes(
|
|
|
StandardCharsets.UTF_8));
|
|
|
- String sigdat1 = new String(encoder.encode(signature1));
|
|
|
+ String sigdat1 = new String(Base64.encode(signature1));
|
|
|
System.out.println("签名结果: " + sigdat1);
|
|
|
sign.addProperty("sigdat", sigdat1);
|
|
|
|
|
|
@@ -68,7 +65,7 @@ public class PayRequest {
|
|
|
System.out.println("加密前req: " + plaintxt);
|
|
|
byte[] enInput = DCCryptor.CMBSM4EncryptWithCBC(aesKey.getBytes(), getID_IV(userid), plaintxt.getBytes(
|
|
|
StandardCharsets.UTF_8));
|
|
|
- String req = new String(encoder.encode(enInput));
|
|
|
+ String req = new String(Base64.encode(enInput));
|
|
|
System.out.println("加密后req: " + req);
|
|
|
|
|
|
// 发送请求
|
|
|
@@ -81,7 +78,7 @@ public class PayRequest {
|
|
|
String formResult = PayUtils.doPostForm(payurl, map);
|
|
|
System.out.println("请求结果: " + formResult);
|
|
|
try {
|
|
|
- decoder.decode(formResult);
|
|
|
+ Base64.decode(formResult);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("访问返回错误.");
|
|
|
}
|
|
|
@@ -89,7 +86,7 @@ public class PayRequest {
|
|
|
//请求报文通过校验,不再抛异常
|
|
|
if (!formResult.startsWith(PayConst.CDCServer)) {
|
|
|
// 解密请求
|
|
|
- String resPlain = new String(DCCryptor.CMBSM4DecryptWithCBC(aesKey.getBytes(), getID_IV(userid), decoder.decode(formResult)),
|
|
|
+ String resPlain = new String(DCCryptor.CMBSM4DecryptWithCBC(aesKey.getBytes(), getID_IV(userid), Base64.decode(formResult)),
|
|
|
StandardCharsets.UTF_8);
|
|
|
System.out.println("res decrypt: " + resPlain);
|
|
|
// 验签
|
|
|
@@ -101,8 +98,8 @@ public class PayRequest {
|
|
|
String resSignSource = DCHelper.serialJsonOrdered(object2);
|
|
|
System.out.println("验签原文: " + resSignSource);
|
|
|
System.out.println("验签签名值: " + resSign);
|
|
|
- Boolean verify = DCCryptor.CMBSM2VerifyWithSM3(getID_IV(userid), decoder.decode(publicKey), resSignSource.getBytes(
|
|
|
- StandardCharsets.UTF_8), decoder.decode(resSign));
|
|
|
+ Boolean verify = DCCryptor.CMBSM2VerifyWithSM3(getID_IV(userid), Base64.decode(publicKey), resSignSource.getBytes(
|
|
|
+ StandardCharsets.UTF_8), Base64.decode(resSign));
|
|
|
System.out.println("验签结果: " + verify);
|
|
|
if (verify) {
|
|
|
return resSignSource;
|