use of com.stardata.starshop2.authcontext.pl.WxEncryptedUserInfo in project starshop by beautautumn.
the class AuthAppService method decryptWxMobileNumber.
public MobileNumberResponse decryptWxMobileNumber(SessionUser loginUser, WxEncryptedUserInfo encryptedUserInfo) {
LongIdentity userId = LongIdentity.from(loginUser.getId());
String encryptedData = encryptedUserInfo.getEncryptedData();
String iv = encryptedUserInfo.getIv();
MobileNumber mobileNumber = decryptService.decryptWxMobileNumber(userId, encryptedData, iv);
return MobileNumberResponse.from(mobileNumber);
}
use of com.stardata.starshop2.authcontext.pl.WxEncryptedUserInfo in project starshop by beautautumn.
the class StarshopAuthDecryptingTests method should_get_mobile_phone_correctly_given_exists_userid_and_correct_encrypted_data_iv.
// 2.1. 正常的已有用户、加密数据encryptedData、iv,成功解密手机号,并更新用户对象手机号
@Test
@Transactional
@Rollback(true)
void should_get_mobile_phone_correctly_given_exists_userid_and_correct_encrypted_data_iv() {
// given: 正常的已有用户、加密数据encryptedData、iv
User existsUser = User.of("深清秋", 1).avatarUrl("https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKq2CRmib1mpu4hOFYtcIHgAmS7DicCEfYkUHoPmPQn74BXH5GerjoMOxIqib7iafNNBw2ZAicBj6gZGUQ/132").country("中国").province("江苏").city("南京").language("zh_CN");
existsUser.refreshLoginToken("EfUbtTDsTz/S3lSvdkx2jg==");
userRepository.add(existsUser);
Long userId = existsUser.getId().value();
SessionUser sessionUser = new SessionUser();
sessionUser.setId(userId);
String encryptedData = "NkSHcnyy8jJZwvsTBpb8Kw7jKIdYz1UnVqJ9Gf2NGFAn3DEeObh7W2Vh5hlgvs5zvtfNsV/IW+oHxEtzN4DY1E/tsGWnhiZYN+pYQun/8gNPrUNsjlR8saZIYoTGNcKpchNp+QEPzP/JFtGqIH+Etpk11RVRWepNJdYNzG3aNLUVmYQRqgCom7kYRrbM7g7GDu/jnqzvMn65ps48GawfQA==";
String iv = "S2r8F/Gr0aUEs7BoerD5ZQ==";
WxEncryptedUserInfo wxEncryptedUserInfo = new WxEncryptedUserInfo();
wxEncryptedUserInfo.setEncryptedData(encryptedData);
wxEncryptedUserInfo.setIv(iv);
// when: 解密手机号
MobileNumberResponse response = authAppService.decryptWxMobileNumber(sessionUser, wxEncryptedUserInfo);
User loadedUser = userRepository.instanceOf(LongIdentity.from(userId));
// then: 判定解密手机号是否正确
assertNotNull(response.getMobileNumber());
assertEquals(response.getMobileNumber(), "18652012976");
assertEquals(loadedUser.getMobileNumber().value(), "18652012976");
}
Aggregations