Closed StringKe closed 1 month ago
utils.ts 有相关方法,没有对外
我看看
response 能解密,还有一个 sign 参数需要校验,校验要调度那个方法?可以举个例子么? java sdk 中有一个 AlipaySignature.rsaCheck 方法
我尝试调度过这个失败,手机号获取那边没有 sign_type 这些参数
@StringKe 具体是那个文档?手机号码这个我看只需要解密成功即可。
https://opendocs.alipay.com/mini/api/getphonenumber#success%20%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0
比如这个它会返回 sign 参数,还是需要验证一下的吧
我找到一个示例代码,我先看看 https://opendocs.alipay.com/common/02mse3 ,搞定给你写到文档里面去。
String response = "小程序前端返回的加密信息";
//1. 获取验签和解密所需要的参数
Map<String, String> openapiResult = JSON.parseObject(response,new TypeReference<Map<String, String>>() {}, Feature.OrderedField);
String signType = "RSA2";
String charset = "UTF-8";
String encryptType = "AES";
String sign = openapiResult.get("sign");
String content = openapiResult.get("response");
//判断是否为加密内容
boolean isDataEncrypted = !content.startsWith("{");
boolean signCheckPass = false;
//2. 验签
String signContent = content;
String signVeriKey = "你的小程序对应的支付宝公钥(为扩展考虑建议用appId+signType做密钥存储隔离)";
String decryptKey = "你的小程序对应的加解密密钥(为扩展考虑建议用appId+encryptType做密钥存储隔离)";//如果是加密的报文则需要在密文的前后添加双引号
if (isDataEncrypted) {
signContent = "\"" + signContent + "\"";
} try {
signCheckPass = AlipaySignature.rsaCheck(signContent, sign, signVeriKey, charset, signType);
} catch (AlipayApiException e) {
// 验签异常, 日志
} if (!signCheckPass) {
//验签不通过(异常或者报文被篡改),终止流程(不需要做解密)
throw new Exception("验签失败");
}
//3. 解密
String plainData = null;
if (isDataEncrypted) {
try {
plainData = AlipayEncrypt.decryptContent(content, encryptType, decryptKey, charset);
} catch (AlipayApiException e) {
//解密异常, 记录日志
throw new Exception("解密异常");
}} else {
plainData = content;
}
https://opendocs.alipay.com/common/02mse3
AES 验签名,比如 https://opendocs.alipay.com/mini/api/getphonenumber 返回的数据进行验证