170
社区成员




Course for This Assignment | 2401_MU_SE_FZU |
---|---|
Team Name | NoFantasy |
Assignment Requirements | Fifth Assignment——Alpha Sprint |
Objectives of This Assignment | Alpha Sprint |
Other References | NO reference |
Aim: Add information editing and modification in personal interface
Problem: None
Partial code
Achieve effect
Aim: set an upper limit of inactivity for each user
Problem: None
@PostMapping("/wxLogin")
public AjaxResult wxLogin(@RequestBody WxLoginBody wxLoginBody) {
String code = wxLoginBody.getCode();
//秘钥
String encryptedIv = wxLoginBody.getEncryptedIv();
//加密数据
String encryptedData = wxLoginBody.getEncryptedData();
//向微信服务器发送请求获取用户信息
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + HellConfig.getAppId() + "&secret=" + HellConfig.getAppSecret() + "&js_code=" + code + "&grant_type=authorization_code";
String res = restTemplate.getForObject(url, String.class);
JSONObject jsonObject = JSONObject.parseObject(res);
//获取session_key和openid
String sessionKey = jsonObject.getString("session_key");
String openid = jsonObject.getString("openid");
//解密
String decryptResult = "";
try {
//如果没有绑定微信开放平台,解析结果是没有unionid的。
decryptResult = decrypt(sessionKey, encryptedIv, encryptedData);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("微信登录失败!");
}
if (StringUtils.hasText(decryptResult)) {
//如果解析成功,获取token
String token = loginService.wxLogin(decryptResult,wxLoginBody.getAvatarUrl());
AjaxResult ajax = AjaxResult.success();
ajax.put(Constants.TOKEN, token);
return ajax;
} else {
return AjaxResult.error("微信登录失败!");
}
}