@ApiOperation(value = "前端发送code给后端,这一步在授权那里必须要调") @GetMapping("/sendCode") //获取凭证校检接口 public JsonResult getLoginCode(String code) throws IOException, BizException { // 小程序登录接口 System.out.println(code+"1111"); String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + APPID + "&secret=" + APPSECRET + "&js_code=" + code + "&grant_type=authorization_code"; System.out.println(code); // java HTTP发送请求 HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(50000); connection.setReadTimeout(50000); // 获取响应数据 InputStream inputStream = connection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder response = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { response.append(line); } System.out.println(response); bufferedReader.close(); inputStream.close(); connection.disconnect(); // 解析响应数据,获取openid和session_key String openid = getJsonValue(response.toString(), "openid"); // String sessionKey = getJsonValue(response.toString(), "session_key"); // return openid + "," + sessionKey; HashMap map = new HashMap<String,String>(); map.put("openid",openid); // map.put("sessionKey",sessionKey); //这个时候应该把sessionKey和openid存在数据库 和对应的人的电话号码相绑定 User user = userService.getUserByOpenid(openid); // user.setSessionKey(sessionKey); //现在这个user里面 两种情况 第一种认证过后的什么都有 第二种 有userid 有openid没有电话号码 return ResponseUtil.success("授权成功,已经可以开始认证了!",map); } /** * 获取json格式数据中某个字段的值 */ private String getJsonValue(String json, String key) { int index = json.indexOf(key); if (index < 0) { return null; } String value = json.substring(index + key.length() + 3); int endIndex = value.indexOf("\""); return value.substring(0, endIndex); }我这段接口为什么前端传入code提示报错:没有传入code呢
时间: 2023-06-08 07:08:19 浏览: 69
&secret=" SECRET "&js_code=" + code + "&grant_type=authorization_code"; // 发送请求,获取 openid 和 session_key String result = HttpUtils.get(url); Map<String, Object> map = JSONObject.parseObject(result, Map.class); String openid = (String) map.get("openid"); String sessionKey = (String) map.get("session_key"); logger.info("登录成功,openid:{}", openid); // 封装返回结果 LoginResultDTO loginResultDTO = new LoginResultDTO(); loginResultDTO.setOpenid(openid); loginResultDTO.setSessionKey(sessionKey); return JsonResult.ok(loginResultDTO); }
请问这段代码是做什么的?
相关问题
@Log(查询用户) @ApiOperation(查询用户) @GetMapping(value = /queryuser) @PreAuthorize(@el.check( sysNoticeInfo:list ))
您好!您的第一个问题是关于代码注解的内容。这段代码是一个使用Spring Boot框架的Java代码段,用于查询用户信息。下面是对代码中各个注解的解释:
1. `@Log(查询用户)`:这是一个自定义注解,可能用于记录日志或跟踪代码执行过程中的查询用户操作。
2. `@ApiOperation(查询用户)`:这是Swagger框架中的注解,用于描述API接口的操作。在这种情况下,它描述了查询用户的操作。
3. `@GetMapping(value = /queryuser)`:这是Spring Web框架中的注解,用于将HTTP GET请求映射到指定的URL路径。在这种情况下,它将GET请求映射到"/queryuser"路径,用于查询用户信息。
4. `@PreAuthorize(@el.check(sysNoticeInfo:list))`:这是Spring Security框架中的注解,用于在方法执行之前进行权限验证。在这种情况下,它使用SpEL表达式(Spring Expression Language)检查当前用户是否具有"sysNoticeInfo:list"权限,如果没有则不允许执行该方法。
希望以上解释对您有帮助!如果还有其他问题,请随时提出。
@OperationLog(operationType = 4, operationContent = "镇街卡片-普法队伍") @GetMapping("/getLawPopularizationTeam") @ApiOperation(value="镇街卡片-普法队伍")
这段代码看起来像是Java代码中的注解和方法定义。其中 @OperationLog 是自定义注解,用于记录操作日志;operationType = 4 表示该操作类型为普法队伍;operationContent = "镇街卡片-普法队伍" 表示该操作内容为镇街卡片-普法队伍。
而 @GetMapping("/getLawPopularizationTeam") 和 @ApiOperation(value="镇街卡片-普法队伍") 则是Spring框架中的注解,用于定义该方法对应的URL路径和API文档中的接口描述。
综合起来看,这段代码应该是定义了一个Spring的Controller层中的API接口,用于获取镇街卡片中的普法队伍信息,并且该操作会被记录到操作日志中。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)