1、IOS 接受通知信息,及对应参数信息
JSONObject iosNotification(@RequestBody JSONObject request)
2、获取加密需要解密的字符串
String signedPayLoad= request.getString("signedPayload");
3、对JWT密文进行解析
JSONObject jsonObject = ApplePayUtil.verifyAndGet(signedPayLoad);
4、对最近一次交易的详细信息进行解析
ApplePayUtil.verifyAndGet(signedTransactionInfo);
5、对关于未来续订的信息进行解析
ApplePayUtil.verifyAndGet(signedRenewalInfo);
6、解析密文方法:
public static JSONObject verifyAndGet(String jws) throws CertificateException {
DecodedJWT decodedJWT = JWT.decode(jws);
// 拿到 header 中 x5c 数组中第一个
String header = new String(java.util.Base64.getDecoder().decode(decodedJWT.getHeader()));
String x5c = JSONObject.parseObject(header).getJSONArray("x5c").getString(0);
// 获取公钥
PublicKey publicKey = getPublicKeyByX5c(x5c);
// 验证 token
Algorithm algorithm = Algorithm.ECDSA256((ECPublicKey) publicKey, null);
try {
algorithm.verify(decodedJWT);
} catch (SignatureVerificationException e) {
throw new RuntimeException("签名验证失败");
}
// 解析数据
return JSONObject.parseObject(new String(java.util.Base64.getDecoder().decode(decodedJWT.getPayload())));
}