1.配置
application.yml和application-dev.yml
1
2
3
wechat:
appid: ${sky.wechat.appid}
secret: ${sky.wechat.secret}
1
2
3
4
wechat:
appid: xxx
secret: xxx
2.登陆Controller代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@RestController
@RequestMapping("/user/user")
@Slf4j
@Api(tags = "C端用户相关接口")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private JwtProperties jwtProperties;
/**
* 登录
* @param userLoginDTO
* @return
*/
@ApiOperation(value = "登录")
@PostMapping("/login")
public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
log.info("微信用户登陆:{}",userLoginDTO);
//微信登陆
User user = userService.weLogin(userLoginDTO);
//为微信用户生成jwt令牌
HashMap<String, Object> claims = new HashMap<>();
claims.put(JwtClaimsConstant.USER_ID,user.getId());
String token = JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), claims);
UserLoginVO userLoginVO = UserLoginVO.builder()
.id(user.getId())
.openid((user.getOpenid()))
.token(token)
.build();
return Result.success(userLoginVO);
}
}