use of com.stardata.starshop2.authcontext.domain.user.WxAuthInfo in project starshop by beautautumn.
the class StarshopAuthLoginTests method should_wx_login_with_token_success_given_login_valid_and_unused_code_.
/**
* 任务级测试:微信用户登录——4.生成微信登录令牌;(组合任务,领域服务)
* 按照先聚合再端口、先原子再组合、从内向外的原则。
* 设计相关任务级测试案例包括:
* 4.1. 微信登录成功,生成登录令牌;(组合任务,领域服务)
* 4.2. 微信登录异常,未生成微信登录令牌;(组合任务,领域服务)
*/
// 4.1. 微信登录成功,生成登录令牌;(组合任务,领域服务)
@Test
@Transactional
@Rollback(true)
void should_wx_login_with_token_success_given_login_valid_and_unused_code_() {
// given: 有效的微信前端code、有效的微信认证用户rawData和signature、有效的用户信息
String code = "081sloll28T8d94nl8nl2hxKhh3slolv";
String rawData = "{\"nickName\":\"深清秋\",\"gender\":0,\"language\":\"zh_CN\",\"city\":\"\",\"province\":\"\",\"country\":\"\",\"avatarUrl\":\"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKq2CRmib1mpu4hOFYtcIHgAmS7DicCEfYkUHoPmPQn74BXH5GerjoMOxIqib7iafNNBw2ZAicBj6gZGUQ/132\"}";
String signature = "06846a4ba8b003af5d98fadfaf376a652e5d75d7";
WxAuthInfo wxAuthInfo = new WxAuthInfo(rawData, signature);
User frontUser = User.of("testUser", 2).avatarUrl("testUrl").country("testCountry").province("testProvince").city("testCity").language("testLanguage");
// when: 调用wxLoginWithTokenService.loginWithToken()
User loginUser = wxLoginWithTokenService.loginWithToken(code, wxAuthInfo, frontUser);
// then: 有效的用户令牌
UserToken token = loginUser.currentToken();
WxOpenId openid = loginUser.getOpenid();
assertNotNull(token);
assertFalse(StringUtils.isBlank(token.getToken()));
assertNotNull(openid);
assertFalse(StringUtils.isBlank(openid.toString()));
}
use of com.stardata.starshop2.authcontext.domain.user.WxAuthInfo in project starshop by beautautumn.
the class WxLoginWithTokenService method loginWithToken.
public User loginWithToken(String code, WxAuthInfo wxAuthInfo, User loginUser) {
WxOpenId openid = wxLoginService.wxLogin(code, wxAuthInfo);
User user = userExistenceService.ensureUser(openid, loginUser);
userTokenService.generateLoginToken(user, wxAuthInfo.getSessionKey());
return user;
}
Aggregations