|
|
@@ -0,0 +1,68 @@
|
|
|
+package com.ruoyi.front.controller;
|
|
|
+
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.core.utils.StringUtils;
|
|
|
+import com.ruoyi.common.security.annotation.InnerAuth;
|
|
|
+import com.ruoyi.front.service.IWxService;
|
|
|
+import com.ruoyi.system.api.domain.SysUser;
|
|
|
+import com.ruoyi.system.api.model.LoginUser;
|
|
|
+import com.ruoyi.system.service.ISysPermissionService;
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/front/wxmini")
|
|
|
+public class WxMiniController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWxService wxService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysPermissionService permissionService;
|
|
|
+
|
|
|
+ @InnerAuth
|
|
|
+ @GetMapping("/getOpenId")
|
|
|
+ public String getOpenId(@RequestParam("jsCode") String jsCode) {
|
|
|
+ try {
|
|
|
+ return wxService.getOpenId(jsCode);
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @InnerAuth
|
|
|
+ @GetMapping("/getPhoneNumber")
|
|
|
+ public String getPhoneNumber(@RequestParam("code") String code) {
|
|
|
+ try {
|
|
|
+ return wxService.getPhoneNumber(code);
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @InnerAuth
|
|
|
+ @PostMapping("/getUserByOpenId")
|
|
|
+ public R<LoginUser> getUserByOpenId(@RequestBody SysUser sysUser) {
|
|
|
+ SysUser currentUser = sysUserService.selectUserByOpenId(sysUser);
|
|
|
+ if (StringUtils.isNull(sysUser))
|
|
|
+ {
|
|
|
+ return R.fail("用户名或密码错误");
|
|
|
+ }
|
|
|
+ // 角色集合
|
|
|
+ Set<String> roles = permissionService.getRolePermission(currentUser);
|
|
|
+ // 权限集合
|
|
|
+ Set<String> permissions = permissionService.getMenuPermission(currentUser);
|
|
|
+ LoginUser sysUserVo = new LoginUser();
|
|
|
+ sysUserVo.setSysUser(currentUser);
|
|
|
+ sysUserVo.setRoles(roles);
|
|
|
+ sysUserVo.setPermissions(permissions);
|
|
|
+ return R.ok(sysUserVo);
|
|
|
+ }
|
|
|
+}
|