[Y] R service 加密参数格式

master
taylor.dang 5 years ago
parent 9ac244038a
commit e173e25dcf

@ -9,7 +9,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId> <artifactId>manage</artifactId>
<version>1.3.0</version> <version>1.3.1</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>1.4.0</jib-maven-plugin.version> <jib-maven-plugin.version>1.4.0</jib-maven-plugin.version>

@ -38,16 +38,26 @@ public class RetailRSvcServiceImpl implements RetailRSvcService {
throw new BadRequestException("this channel config is wrong"); throw new BadRequestException("this channel config is wrong");
} }
RSvcMchBean svcMchBean = clientManager.findSvcMchByAccountId(device.getString("account_id")); RSvcMchBean svcMchBean = clientManager.findSvcMchByAccountId(device.getString("account_id"));
String pubKeyEncCredentialCode = SignUtils.encData(svcMchBean.getCredentialCode(), svcInfo.getString("channel_pub_key"));
String aesKeyStr = Base64.encodeBase64String(AESCrypt.randomKey().getEncoded()); String aesKeyStr = Base64.encodeBase64String(AESCrypt.randomKey().getEncoded());
Key key = AESCrypt.fromKeyString(Base64.decodeBase64(aesKeyStr)); Key key = AESCrypt.fromKeyString(Base64.decodeBase64(aesKeyStr));
String decCredentialCode = Base64.encodeBase64String(AESCrypt.encrypt(pubKeyEncCredentialCode.getBytes(StandardCharsets.UTF_8), key));
JSONObject result = (JSONObject) JSON.toJSON(svcMchBean); JSONObject result = (JSONObject) JSON.toJSON(svcMchBean);
result.put("sign_type", "RSA2"); result.put("sign_type", "RSA2");
result.put("enc_data", decCredentialCode); result.put("enc_data", new JSONObject(true) {
{
put("credentialCode", encData(svcMchBean.getCredentialCode(), key, svcInfo.getString("channel_pub_key")));
put("payHost", encData(svcMchBean.getPayHost(), key, svcInfo.getString("channel_pub_key")));
put("partnerCode", encData(svcMchBean.getPartnerCode(), key, svcInfo.getString("channel_pub_key")));
put("merchantNumber", encData(svcMchBean.getMerchantNumber(), key, svcInfo.getString("channel_pub_key")));
}
});
result.put("nonce_str", aesKeyStr); result.put("nonce_str", aesKeyStr);
result.put("timestamp", System.currentTimeMillis()); result.put("timestamp", System.currentTimeMillis());
result.put("sign", SignUtils.buildSign(result.toJSONString(), svcInfo.getString("platform_pri_key"))); result.put("sign", SignUtils.buildSign(result.toJSONString(), svcInfo.getString("platform_pri_key")));
return result; return result;
} }
private String encData(String data, Key key, String publicKey) {
String pubKeyEncData = SignUtils.encData(data, publicKey);
return org.apache.commons.codec.binary.Base64.encodeBase64String(AESCrypt.encrypt(pubKeyEncData.getBytes(StandardCharsets.UTF_8), key));
}
} }

Loading…
Cancel
Save