haogh 1 年之前
父节点
当前提交
8b6b8d1a01

+ 33 - 7
src/main/java/com/qmth/exam/reserve/controller/student/StudentController.java

@@ -1,20 +1,29 @@
 package com.qmth.exam.reserve.controller.student;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.Constants;
 import com.qmth.exam.reserve.bean.student.StudentInfo;
 import com.qmth.exam.reserve.bean.student.WechatBindReq;
+import com.qmth.exam.reserve.config.WxProperty;
 import com.qmth.exam.reserve.controller.BaseController;
 import com.qmth.exam.reserve.service.StudentService;
+import com.qmth.exam.reserve.weixin.OauthAccessTokenRequest;
+import com.qmth.exam.reserve.weixin.response.OauthAccessTokenResponseJson;
+
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import io.swagger.annotations.ApiParam;
 
 @RestController
 @Api(tags = "【考生端】考生相关接口")
@@ -27,6 +36,9 @@ public class StudentController extends BaseController {
     @Autowired
     private StudentService studentService;
 
+    @Autowired
+    private WxProperty wxProperty;
+
     @ApiOperation(value = "考生账号与微信号绑定")
     @PostMapping(value = "/wechat/binding")
     public void binding(@RequestBody WechatBindReq req) {
@@ -46,4 +58,18 @@ public class StudentController extends BaseController {
         return studentService.findInfoByStudentId(curLoginStudent().getId());
     }
 
+    @Aac(strict = false, auth = false)
+    @ApiOperation(value = "获取用户的openid")
+    @PostMapping(value = "/wechat/get/openid")
+    public String getOpenid(@ApiParam("微信平台返回的用户code") @RequestParam String code) {
+        OauthAccessTokenRequest tokenRequest = new OauthAccessTokenRequest(code, wxProperty.getAppId(),
+                wxProperty.getAppSecret());
+        OauthAccessTokenResponseJson responseJson = tokenRequest.request();
+        if (responseJson.getErrcode() != 0) {
+            log.warn("openId获取失败:用户code:" + code);
+            throw new StatusException(Constants.SYSTEM_BUSY);
+        }
+        return responseJson.getOpenid();
+    }
+
 }

+ 0 - 23
src/main/java/com/qmth/exam/reserve/controller/student/StudentLoginController.java

@@ -6,25 +6,18 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
-import com.qmth.boot.core.exception.StatusException;
-import com.qmth.exam.reserve.bean.Constants;
 import com.qmth.exam.reserve.bean.login.LoginReq;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.login.WechatLoginReq;
-import com.qmth.exam.reserve.config.WxProperty;
 import com.qmth.exam.reserve.controller.BaseController;
 import com.qmth.exam.reserve.service.AuthService;
-import com.qmth.exam.reserve.weixin.OauthAccessTokenRequest;
-import com.qmth.exam.reserve.weixin.response.OauthAccessTokenResponseJson;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
 
 @RestController
 @Api(tags = "【考生端】考生登录相关接口")
@@ -37,9 +30,6 @@ public class StudentLoginController extends BaseController {
     @Autowired
     private AuthService authService;
 
-    @Autowired
-    private WxProperty wxProperty;
-
     @ApiOperation(value = "考生登录(账号)")
     @PostMapping(value = "/login")
     public LoginUser login(@RequestBody LoginReq req) {
@@ -59,17 +49,4 @@ public class StudentLoginController extends BaseController {
         authService.logout(curLoginStudent());
     }
 
-    @ApiOperation(value = "获取用户的openid")
-    @PostMapping(value = "/login/get/openid")
-    public String getOpenid(@ApiParam("微信平台返回的用户code") @RequestParam String code) {
-        OauthAccessTokenRequest tokenRequest = new OauthAccessTokenRequest(code, wxProperty.getAppId(),
-                wxProperty.getAppSecret());
-        OauthAccessTokenResponseJson responseJson = tokenRequest.request();
-        if (responseJson.getErrcode() != 0) {
-            log.warn("openId获取失败:用户code:" + code);
-            throw new StatusException(Constants.SYSTEM_BUSY);
-        }
-        return responseJson.getOpenid();
-    }
-
 }