Search in sources :

Example 1 with WxEncryptedUserInfo

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);
}
Also used : MobileNumber(com.stardata.starshop2.sharedcontext.domain.MobileNumber) LongIdentity(com.stardata.starshop2.sharedcontext.domain.LongIdentity)

Example 2 with WxEncryptedUserInfo

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");
}
Also used : WxEncryptedUserInfo(com.stardata.starshop2.authcontext.pl.WxEncryptedUserInfo) SessionUser(com.stardata.starshop2.sharedcontext.pl.SessionUser) SessionUser(com.stardata.starshop2.sharedcontext.pl.SessionUser) User(com.stardata.starshop2.authcontext.domain.user.User) MobileNumberResponse(com.stardata.starshop2.authcontext.pl.MobileNumberResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(jakarta.transaction.Transactional)

Aggregations

User (com.stardata.starshop2.authcontext.domain.user.User)1 MobileNumberResponse (com.stardata.starshop2.authcontext.pl.MobileNumberResponse)1 WxEncryptedUserInfo (com.stardata.starshop2.authcontext.pl.WxEncryptedUserInfo)1 LongIdentity (com.stardata.starshop2.sharedcontext.domain.LongIdentity)1 MobileNumber (com.stardata.starshop2.sharedcontext.domain.MobileNumber)1 SessionUser (com.stardata.starshop2.sharedcontext.pl.SessionUser)1 Transactional (jakarta.transaction.Transactional)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Rollback (org.springframework.test.annotation.Rollback)1