|
|
@ -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));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|