支付宝登录

This commit is contained in:
Guoqs
2024-06-11 17:01:44 +08:00
parent 0290db1914
commit 6d5b436393
8 changed files with 18 additions and 43 deletions

View File

@@ -263,38 +263,12 @@ public class SpringBootTestController {
private NotificationService notificationService;
@Test
public void decryptPhoneNum(){
// 前端接口返回的加密信息
String response ="CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
//1. 获取解密所需要的参数
Map<String, String> openapiResult = com.alibaba.fastjson.JSON.parseObject(response, new TypeReference<Map<String, String>>() {}, Feature.OrderedField);
String charset = "UTF-8";
String encryptType = "AES";
String content = "CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
// 判断是否为加密内容
boolean isDataEncrypted = !content.startsWith("{");
String decryptKey = "B_AES_KEY"; // 商家小程序 AES 密钥
//AES密钥这里参数不能写成固定的开发阶段需传入模板的AES密钥实例化后应传入商家小程序的AES密钥
// 解密
String plainData = null;
if (isDataEncrypted) {
try {
System.out.println("AlipayEncrypt");
plainData = AlipayEncrypt.decryptContent(content, encryptType, decryptKey,charset);
System.out.println("AlipayEncrypt Trance done");
} catch (AlipayApiException e) {
//解密异常, 记录日志
try {
throw new Exception("解密异常");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} else {
plainData = content;
}
System.out.println(plainData);
public void decryptPhoneNum() throws Exception {
String content = "/CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
// 通过密文解密 获取手机号码
String mobileNumber = Factory.Util.AES().decrypt(content);
System.out.println(mobileNumber);
}
@Test