From 3885e64ca0b6d9252b7182b70dcb88fad3c614ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=96=AF=E7=84=B6?= <2286974448@qq.com> Date: Tue, 26 Oct 2021 21:16:27 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=AE=8C=E6=88=90=E4=BA=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=202.=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=BA=86=E6=9F=A5=E8=AF=A2=E7=94=A8=E6=88=B7=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=203.=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=BA=86=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8Faccess=5F?= =?UTF-8?q?token=E8=8E=B7=E5=8F=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- pom.xml | 1 - .../controller/LoginController.java | 69 +++++++++++++ .../controller/UserController.java | 52 +++++++++- .../mapper/ParentMapper.java | 9 ++ .../mapper/StudentMapper.java | 9 ++ .../mapper/TeacherClassApplyMapper.java | 5 +- .../mapper/TeacherMapper.java | 10 ++ ...sApplyVo.java => TeacherClassApplyVO.java} | 2 +- .../pojo/vo/UserVO.java | 37 +++++++ .../service/LoginService.java | 31 ++++++ .../service/UserService.java | 10 ++ .../service/impl/LoginServiceImpl.java | 97 +++++++++++++++++++ .../service/impl/UserServiceImpl.java | 96 ++++++++++++++++++ .../util/DateUtil.java | 3 + .../util/HttpClientUtil.java | 46 +++++++++ src/main/resources/application.yaml | 10 +- src/main/resources/mapper/ParentMapper.xml | 12 +++ src/main/resources/mapper/StudentMapper.xml | 16 +++ .../mapper/TeacherClassApplyMapper.xml | 2 +- src/main/resources/mapper/TeacherMapper.xml | 16 +++ 21 files changed, 520 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/mobile_education_platform/controller/LoginController.java rename src/main/java/com/mobile_education_platform/pojo/vo/{TeacherClassApplyVo.java => TeacherClassApplyVO.java} (96%) create mode 100644 src/main/java/com/mobile_education_platform/pojo/vo/UserVO.java create mode 100644 src/main/java/com/mobile_education_platform/service/LoginService.java create mode 100644 src/main/java/com/mobile_education_platform/service/impl/LoginServiceImpl.java create mode 100644 src/main/java/com/mobile_education_platform/util/HttpClientUtil.java diff --git a/.gitignore b/.gitignore index 549e00a..a3bd859 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ HELP.md target/ -!.mvn/wrapper/maven-wrapper.jar +!.mvn/wrapper/ !**/src/main/**/target/ !**/src/test/**/target/ diff --git a/pom.xml b/pom.xml index b4f81ec..efc5c7b 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,6 @@ lombok true - com.baomidou diff --git a/src/main/java/com/mobile_education_platform/controller/LoginController.java b/src/main/java/com/mobile_education_platform/controller/LoginController.java new file mode 100644 index 0000000..a93698a --- /dev/null +++ b/src/main/java/com/mobile_education_platform/controller/LoginController.java @@ -0,0 +1,69 @@ +package com.mobile_education_platform.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.mobile_education_platform.common.R; +import com.mobile_education_platform.service.LoginService; +import com.mobile_education_platform.service.UserService; +import com.mobile_education_platform.util.HttpClientUtil; +import io.swagger.annotations.Api; +import org.apache.http.client.utils.HttpClientUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * @Description: + * @Author: 陈斯然 + * @Date: Create in 2021/10/26 11:19 + * @Version: V1.0 + */ +@RestController +@RequestMapping("") +@Api(tags = "登录模块管理") +public class LoginController { + + @Resource + private LoginService loginService; + + @Resource + private UserService userService; + + /** + * @Description: 根据wx.login返回的code获取openid和session秘钥 + * @param code 小程序登录时获取的code + * @return openid和session_key + * @Author: 陈斯然 + * @Date: 2021/10/26 15:36 + **/ + @GetMapping("/login") + public R login(String code){ + + Map result = null; + try { + // 调用微信官方接口,通过code得到用户id和session秘钥 + result = loginService.getCode2Session(code); + } catch (IOException e) { + e.printStackTrace(); + return R.error("登录失败!"); + } + + // 通过用户openid查询该用户是否已绑定账号 + Map hasUserMap = userService.hasUser(String.valueOf(result.get("openid"))); + if (!(Boolean) hasUserMap.get("hasUser")){ + result.put("hasUser",false); + return R.ok("登录成功,请绑定相关信息!"); + } + result.put("hasUser",true); + result.put("userInfo",hasUserMap.get("userVO")); + + return R.ok("登录成功,请稍等!",result); + } + + +} diff --git a/src/main/java/com/mobile_education_platform/controller/UserController.java b/src/main/java/com/mobile_education_platform/controller/UserController.java index 27e7276..a7f1ca9 100644 --- a/src/main/java/com/mobile_education_platform/controller/UserController.java +++ b/src/main/java/com/mobile_education_platform/controller/UserController.java @@ -1,10 +1,16 @@ package com.mobile_education_platform.controller; +import com.mobile_education_platform.common.R; +import com.mobile_education_platform.service.UserService; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.RequestMapping; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; -import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; /** *

@@ -16,8 +22,48 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController @RequestMapping("/user") -@Api(tags = "") +@Api(tags = "用户信息") public class UserController { + @Resource + private UserService userService; + + /** + * @Description: 根据微信openid判断该用户为新老用户,若是则返回用户信息 + * @param openid 微信id + * @return + * @Author: 陈斯然 + * @Date: 2021/10/26 20:51 + **/ + @GetMapping("/userInfo") + @ApiOperation("根据微信openid判断该用户为新老用户,若是则返回用户信息") + @ApiImplicitParam(name = "openidopenid",value = "微信id",required = true) + public R getUserInfo(String openid){ + + Map result = userService.hasUser(openid); + Map map = new HashMap<>(); + + // 判断用户是否已绑定信息 + if ((Boolean) result.get("hasUser")){ + map.put("UserInfo",result.get("hasUser")); + } + + return R.ok("查询成功",map); + } + + /** + * @Description: 为用户绑定信息 + * @param + * @return + * @Author: 陈斯然 + * @Date: 2021/10/26 21:08 + **/ + @PostMapping("userInfo") + @ApiOperation("为用户绑定信息") + public R saveUserInfo(){ + + + return R.ok("绑定成功!"); + } } diff --git a/src/main/java/com/mobile_education_platform/mapper/ParentMapper.java b/src/main/java/com/mobile_education_platform/mapper/ParentMapper.java index 68e6a46..5d374b0 100644 --- a/src/main/java/com/mobile_education_platform/mapper/ParentMapper.java +++ b/src/main/java/com/mobile_education_platform/mapper/ParentMapper.java @@ -2,6 +2,7 @@ package com.mobile_education_platform.mapper; import com.mobile_education_platform.pojo.Parent; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mobile_education_platform.pojo.vo.UserVO; import org.springframework.stereotype.Repository; /** @@ -15,4 +16,12 @@ import org.springframework.stereotype.Repository; @Repository public interface ParentMapper extends BaseMapper { + /** + * @Description: 根据编号查询家长信息 + * @param number 家长编号 + * @return UserVO(家长信息) + * @Author: 陈斯然 + * @Date: 2021/10/26 20:07 + **/ + UserVO selectOneByNumber(String number); } diff --git a/src/main/java/com/mobile_education_platform/mapper/StudentMapper.java b/src/main/java/com/mobile_education_platform/mapper/StudentMapper.java index 470fe46..4e20b24 100644 --- a/src/main/java/com/mobile_education_platform/mapper/StudentMapper.java +++ b/src/main/java/com/mobile_education_platform/mapper/StudentMapper.java @@ -2,6 +2,7 @@ package com.mobile_education_platform.mapper; import com.mobile_education_platform.pojo.Student; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mobile_education_platform.pojo.vo.UserVO; import org.springframework.stereotype.Repository; /** @@ -15,4 +16,12 @@ import org.springframework.stereotype.Repository; @Repository public interface StudentMapper extends BaseMapper { + /** + * @Description: 根据编号查询学生信息 + * @param number 学生编号 + * @return UserVO(学生信息) + * @Author: 陈斯然 + * @Date: 2021/10/26 19:55 + **/ + UserVO selectOneByNumber(String number); } diff --git a/src/main/java/com/mobile_education_platform/mapper/TeacherClassApplyMapper.java b/src/main/java/com/mobile_education_platform/mapper/TeacherClassApplyMapper.java index 560b390..d4b8dc8 100644 --- a/src/main/java/com/mobile_education_platform/mapper/TeacherClassApplyMapper.java +++ b/src/main/java/com/mobile_education_platform/mapper/TeacherClassApplyMapper.java @@ -5,8 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mobile_education_platform.pojo.TeacherClassApply; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.mobile_education_platform.pojo.TeacherClassSubject; -import com.mobile_education_platform.pojo.vo.TeacherClassApplyVo; +import com.mobile_education_platform.pojo.vo.TeacherClassApplyVO; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -22,6 +21,6 @@ import org.springframework.stereotype.Repository; public interface TeacherClassApplyMapper extends BaseMapper { - Page selectApply(Page page, @Param(Constants.WRAPPER) QueryWrapper teacherClassApplyQueryWrapper); + Page selectApply(Page page, @Param(Constants.WRAPPER) QueryWrapper teacherClassApplyQueryWrapper); } diff --git a/src/main/java/com/mobile_education_platform/mapper/TeacherMapper.java b/src/main/java/com/mobile_education_platform/mapper/TeacherMapper.java index fcfc7b1..16de3e8 100644 --- a/src/main/java/com/mobile_education_platform/mapper/TeacherMapper.java +++ b/src/main/java/com/mobile_education_platform/mapper/TeacherMapper.java @@ -2,6 +2,8 @@ package com.mobile_education_platform.mapper; import com.mobile_education_platform.pojo.Teacher; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mobile_education_platform.pojo.vo.UserVO; +import jdk.nashorn.internal.runtime.regexp.joni.constants.CCSTATE; import org.springframework.stereotype.Repository; /** @@ -15,4 +17,12 @@ import org.springframework.stereotype.Repository; @Repository public interface TeacherMapper extends BaseMapper { + /** + * @Description: 根据编号查询教师信息 + * @param number 教师编号 + * @return UserVO(教师信息) + * @Author: 陈斯然 + * @Date: 2021/10/26 19:56 + **/ + UserVO selectOneByNumber(String number); } diff --git a/src/main/java/com/mobile_education_platform/pojo/vo/TeacherClassApplyVo.java b/src/main/java/com/mobile_education_platform/pojo/vo/TeacherClassApplyVO.java similarity index 96% rename from src/main/java/com/mobile_education_platform/pojo/vo/TeacherClassApplyVo.java rename to src/main/java/com/mobile_education_platform/pojo/vo/TeacherClassApplyVO.java index 7211464..e12297c 100644 --- a/src/main/java/com/mobile_education_platform/pojo/vo/TeacherClassApplyVo.java +++ b/src/main/java/com/mobile_education_platform/pojo/vo/TeacherClassApplyVO.java @@ -23,7 +23,7 @@ import java.util.Date; @NoArgsConstructor @Accessors(chain = true) @ApiModel(value="TeacherClassApply对象", description="") -public class TeacherClassApplyVo implements Serializable { +public class TeacherClassApplyVO implements Serializable { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/mobile_education_platform/pojo/vo/UserVO.java b/src/main/java/com/mobile_education_platform/pojo/vo/UserVO.java new file mode 100644 index 0000000..7f6f1ac --- /dev/null +++ b/src/main/java/com/mobile_education_platform/pojo/vo/UserVO.java @@ -0,0 +1,37 @@ +package com.mobile_education_platform.pojo.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +/** + * @Description: + * @Author: 陈斯然 + * @Date: Create in 2021/10/26 17:27 + * @Version: V1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = true) +@ApiModel(value="UserVO对象", description="") +public class UserVO { + + @ApiModelProperty(value = "用户id") + private String userId; + + @ApiModelProperty(value = "用户编号") + private String userNumber; + + @ApiModelProperty(value = "用户姓名") + private String userName; + + @ApiModelProperty(value = "用户个人照片") + private String userPhoto; + + @ApiModelProperty(value = "用户身份(1教师、2学生、3家长)") + private Integer userRole; +} diff --git a/src/main/java/com/mobile_education_platform/service/LoginService.java b/src/main/java/com/mobile_education_platform/service/LoginService.java new file mode 100644 index 0000000..f66ee2c --- /dev/null +++ b/src/main/java/com/mobile_education_platform/service/LoginService.java @@ -0,0 +1,31 @@ +package com.mobile_education_platform.service; + +import java.io.IOException; +import java.util.Map; + +/** + * @Description: + * @Author: 陈斯然 + * @Date: Create in 2021/10/26 15:22 + * @Version: V1.0 + */ +public interface LoginService { + + /** + * @Description: 通过官方提供的接口,调用code获取openid和session_key + * @param code 小程序登录时获取的code + * @return openid和session_key + * @Author: 陈斯然 + * @Date: 2021/10/26 15:42 + **/ + Map getCode2Session(String code) throws IOException; + + /** + * @Description: 获取小程序全局唯一后台接口调用凭据(access_token) + * @param + * @return + * @Author: 陈斯然 + * @Date: 2021/10/26 20:58 + **/ + Map getAccessToken() throws IOException; +} diff --git a/src/main/java/com/mobile_education_platform/service/UserService.java b/src/main/java/com/mobile_education_platform/service/UserService.java index f6175b1..cbfa860 100644 --- a/src/main/java/com/mobile_education_platform/service/UserService.java +++ b/src/main/java/com/mobile_education_platform/service/UserService.java @@ -3,6 +3,8 @@ package com.mobile_education_platform.service; import com.mobile_education_platform.pojo.User; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.Map; + /** *

* 服务类 @@ -13,4 +15,12 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface UserService extends IService { + /** + * @Description: 根据openid判断该用户为新老用户 + * @param openid 用户唯一id + * @return 返回查询的结果(用户是否已保定身份,若已绑定需提供身份信息) + * @Author: 陈斯然 + * @Date: 2021/10/26 20:23 + **/ + Map hasUser(String openid); } diff --git a/src/main/java/com/mobile_education_platform/service/impl/LoginServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000..99dc39a --- /dev/null +++ b/src/main/java/com/mobile_education_platform/service/impl/LoginServiceImpl.java @@ -0,0 +1,97 @@ +package com.mobile_education_platform.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.mobile_education_platform.service.LoginService; +import com.mobile_education_platform.util.HttpClientUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * @Description: + * @Author: 陈斯然 + * @Date: Create in 2021/10/26 15:22 + * @Version: V1.0 + */ +@Service +public class LoginServiceImpl implements LoginService { + + private static String APPID; + + private static String APPSECRET; + + //静态方法不能直接使用spring注解注入 + @Value("${weChatMiniProgram.APPID}") + public void setAppId(String appId){ + APPID = appId; + } + + @Value("${weChatMiniProgram.APPSECRET}") + public void setAppSecret(String appSecret){ + APPSECRET = appSecret; + } + + /** + * @Description: 通过官方提供的接口,调用code获取openid和session_key + * @param code 小程序登录时获取的code + * @return openid和session_key + * @Author: 陈斯然 + * @Date: 2021/10/26 15:46 + **/ + @Override + public Map getCode2Session(String code) throws IOException { + + // 拼接微信接口,获取openid和session秘钥 + String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + APPID + + "&secret=" + APPSECRET + "&js_code=" + code + "&grant_type=authorization_code"; + + JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(url)); + Map map = new HashMap<>(); + + String openid = jsonObject.getString("openid"); + String session_key = jsonObject.getString("session_key"); + + // 如果openid和session秘钥都不为空,则返回给前台 + if (openid != null && session_key != null){ + map.put("openid",openid); + map.put("session_key",session_key); + } + + return map; + } + + /** + * @Description: 获取小程序全局唯一后台接口调用凭据(access_token) + * @param + * @return + * @Author: 陈斯然 + * @Date: 2021/10/26 20:59 + **/ + @Override + public Map getAccessToken() throws IOException { + + // 拼接微信接口,获取openid和session秘钥 + String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APPID + + "&secret=" + APPSECRET; + + String respnse = HttpClientUtil.doGet(url); + System.out.println(respnse); + + JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(url)); + Map map = new HashMap<>(); + + String access_token = jsonObject.getString("access_token"); + String expires_in = jsonObject.getString("expires_in"); + + // 如果openid和session秘钥都不为空,则返回给前台 + if (access_token != null && expires_in != null){ + map.put("access_token",access_token); + map.put("expires_in",expires_in); + } + return map; + } +} diff --git a/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java index 6833af5..cd3c97a 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java @@ -1,11 +1,22 @@ package com.mobile_education_platform.service.impl; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.mobile_education_platform.mapper.ParentMapper; +import com.mobile_education_platform.mapper.StudentMapper; +import com.mobile_education_platform.mapper.TeacherMapper; +import com.mobile_education_platform.pojo.Student; import com.mobile_education_platform.pojo.User; import com.mobile_education_platform.mapper.UserMapper; +import com.mobile_education_platform.pojo.vo.UserVO; import com.mobile_education_platform.service.UserService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + /** *

* 服务实现类 @@ -17,4 +28,89 @@ import org.springframework.stereotype.Service; @Service public class UserServiceImpl extends ServiceImpl implements UserService { + @Resource + private TeacherMapper teacherMapper; + + @Resource + private StudentMapper studentMapper; + + @Resource + private ParentMapper parentMapper; + + /** + * @Description: 根据openid判断该用户为新老用户 + * @param openid 用户唯一id + * @return 返回查询的结果(用户是否已保定身份,若已绑定需提供身份信息) + * @Author: 陈斯然 + * @Date: 2021/10/26 16:42 + **/ + public Map hasUser(String openid){ + + Map map = new HashMap<>(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("wechat_id",openid); + User user = baseMapper.selectOne(wrapper); + + // 以openid为条件查询用户表,若不为空则表示其为老用户,反之,保存用户信息 + if (user != null){ + + //判断该用户账户是否被禁用了 + if (user.getStatus() == 0){ + throw new RuntimeException("该账号已被禁用,请联系管理员!"); + } + map.put("hasUser",true); + + UserVO userVO = getUserInfo(user.getRole(), user.getUserNumber()); + if (userVO == null){ + throw new RuntimeException("该用户信息异常,请联系管理员!"); + } + map.put("userVO",userVO); + + }else { + // 该用户未绑定 + map.put("hasUser",false); + } + + return map; + } + + /** + * @Description: 根据用户身份查询用户数据 + * @param role 用户身份 + * @param userNumber 用户编号 + * @return UserVo 用户数据对象 + * @Author: 陈斯然 + * @Date: 2021/10/26 20:10 + **/ + public UserVO getUserInfo(Integer role,String userNumber){ + + UserVO userVO = null; + switch (role){ + case 1: + userVO = teacherMapper.selectOneByNumber(userNumber); + if (userVO == null) { + throw new RuntimeException("该教师所绑定的编号有误,请联系管理员!"); + } + + break; + case 2: + userVO = studentMapper.selectOneByNumber(userNumber); + if (userVO == null) { + throw new RuntimeException("该学生所绑定的编号有误,请联系管理员!"); + } + + break; + case 3: + userVO = parentMapper.selectOneByNumber(userNumber); + if (userVO == null) { + throw new RuntimeException("该家长所绑定的编号有误,请联系管理员!"); + } + + break; + default: + throw new RuntimeException("该用户身份异常"); + } + + return userVO.setUserRole(role); + } } diff --git a/src/main/java/com/mobile_education_platform/util/DateUtil.java b/src/main/java/com/mobile_education_platform/util/DateUtil.java index 15874c5..56087d6 100644 --- a/src/main/java/com/mobile_education_platform/util/DateUtil.java +++ b/src/main/java/com/mobile_education_platform/util/DateUtil.java @@ -1,5 +1,7 @@ package com.mobile_education_platform.util; +import org.springframework.stereotype.Component; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -9,6 +11,7 @@ import java.util.Date; * @author: * @time: 2021-9-7 23:03:30 */ +@Component public class DateUtil { /** diff --git a/src/main/java/com/mobile_education_platform/util/HttpClientUtil.java b/src/main/java/com/mobile_education_platform/util/HttpClientUtil.java new file mode 100644 index 0000000..0a73985 --- /dev/null +++ b/src/main/java/com/mobile_education_platform/util/HttpClientUtil.java @@ -0,0 +1,46 @@ +package com.mobile_education_platform.util; + +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +/** + * @Description: 请求工具类 + * @Author: 陈斯然 + * @Date: Create in 2021/10/26 15:36 + * @Version: V1.0 + */ +@Component +public class HttpClientUtil { + + final static int TIMEOUT_MSEC = 5 * 1000; + + public static String doGet(String url) throws IOException { + + //创建Client对象 + CloseableHttpClient httpClient = HttpClients.createDefault(); + String resultString = ""; + + try { + //创建http请求并设置 + HttpGet get = new HttpGet(url); + get.setConfig(RequestConfig.custom() + .setConnectTimeout(TIMEOUT_MSEC) + .setConnectionRequestTimeout(TIMEOUT_MSEC) + .setSocketTimeout(TIMEOUT_MSEC).build()); + + //得到请求的响应并格式化 + resultString = EntityUtils.toString(httpClient.execute(get).getEntity(), "UTF-8"); + + }catch (Exception e){ + throw e; + } + return resultString; + } +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index dab397c..46fbcb1 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -18,10 +18,6 @@ mybatis-plus: global-config: banner: false -#logging: -# level: -# com.education_platform.mapper: debug - aliyun: # 外网访问地址 ENDPOINT: "oss-cn-guangzhou.aliyuncs.com" @@ -33,4 +29,8 @@ aliyun: # 仓库名称 BUCKETNAME: "yjg-education-platform" # 上传成功后返回的URL前段 - SUFFER_URL: "http://yjg-education-platform.oss-cn-guangzhou.aliyuncs.com/" \ No newline at end of file + SUFFER_URL: "http://yjg-education-platform.oss-cn-guangzhou.aliyuncs.com/" + +weChatMiniProgram: + APPID: "wxab007851f68a82d6" + APPSECRET: "d0827787b43188795d7c99d826756aa6" \ No newline at end of file diff --git a/src/main/resources/mapper/ParentMapper.xml b/src/main/resources/mapper/ParentMapper.xml index e3ced6c..16a2b28 100644 --- a/src/main/resources/mapper/ParentMapper.xml +++ b/src/main/resources/mapper/ParentMapper.xml @@ -2,4 +2,16 @@ + + diff --git a/src/main/resources/mapper/StudentMapper.xml b/src/main/resources/mapper/StudentMapper.xml index b2487bd..9c9b0d7 100644 --- a/src/main/resources/mapper/StudentMapper.xml +++ b/src/main/resources/mapper/StudentMapper.xml @@ -2,4 +2,20 @@ + + diff --git a/src/main/resources/mapper/TeacherClassApplyMapper.xml b/src/main/resources/mapper/TeacherClassApplyMapper.xml index f6a1ab9..397123e 100644 --- a/src/main/resources/mapper/TeacherClassApplyMapper.xml +++ b/src/main/resources/mapper/TeacherClassApplyMapper.xml @@ -3,7 +3,7 @@ - select teacher_class_apply.id,teacher.number as teacherNumber,teacher.name_CN as teacherNameCn, teacher.name_PT as teacherNamePt,class.id as classId,class.name as className, teacher_class_apply.result diff --git a/src/main/resources/mapper/TeacherMapper.xml b/src/main/resources/mapper/TeacherMapper.xml index 48e88ff..4b239de 100644 --- a/src/main/resources/mapper/TeacherMapper.xml +++ b/src/main/resources/mapper/TeacherMapper.xml @@ -2,4 +2,20 @@ + + -- Gitee