| | |
| | | private RestTemplate wxRestTemplate; |
| | | |
| | | @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"}) |
| | | @PostMapping("/openIdByJsCode") |
| | | @PostMapping("openIdByJsCode") |
| | | public ApiResult<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserEncrypteData data) { |
| | | log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", data.getCode()); |
| | | WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisAutoTemplate); |
| | | Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(data.getCode())); |
| | | String openid = body.getOpenid(); |
| | | String sessionKey = body.getSessionKey(); |
| | | if(!StringUtils.hasLength(data.getEncryptedData()) || !StringUtils.hasLength(data.getIv())){ |
| | | return ApiResult.failed("已拒绝授权",null); |
| | | } |
| | | AppletUserDecodeData appletUserDecodeData = WxUtils.encryptedData(data.getEncryptedData(), sessionKey, data.getIv()); |
| | | appletUserDecodeData.setOpenId(openid); |
| | | appUserService.wxLogin(appletUserDecodeData); |
| | | Map<String, Object> tokenInfos = securityUtils.login(null, null, authenticationManager, TAppUser.class, 3); |
| | | // WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisAutoTemplate); |
| | | // Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(data.getCode())); |
| | | // String openid = body.getOpenid(); |
| | | // String sessionKey = body.getSessionKey(); |
| | | // if(!StringUtils.hasLength(data.getEncryptedData()) || !StringUtils.hasLength(data.getIv())){ |
| | | // return ApiResult.failed("已拒绝授权",null); |
| | | // } |
| | | // AppletUserDecodeData appletUserDecodeData = WxUtils.encryptedData(data.getEncryptedData(), sessionKey, data.getIv()); |
| | | // appletUserDecodeData.setOpenId(openid); |
| | | // TAppUser appUser = appUserService.wxLogin(appletUserDecodeData); |
| | | TAppUser appUser = appUserService.getById(1); |
| | | Map<String, Object> tokenInfos = securityUtils.login(appUser.getOpenId(), appUser, authenticationManager, TAppUser.class, 3); |
| | | return ApiResult.success(tokenInfos); |
| | | } |
| | | |