浏览代码

导入导出开发

anderx 2 年之前
父节点
当前提交
449fb3f994

+ 6 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/weChat/WeChatController.java

@@ -1,5 +1,7 @@
 package com.ruoyi.web.controller.weChat;
 package com.ruoyi.web.controller.weChat;
 
 
+import com.ruoyi.system.mapper.SysUserMapper;
+import com.ruoyi.system.service.ISysUserService;
 import com.ruoyi.weChat.service.WeChatService;
 import com.ruoyi.weChat.service.WeChatService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -12,6 +14,8 @@ public class WeChatController {
 
 
     @Autowired
     @Autowired
     private WeChatService weChatService;
     private WeChatService weChatService;
+    @Autowired
+    private ISysUserService userService;
 
 
 
 
     /**
     /**
@@ -29,7 +33,8 @@ public class WeChatController {
      */
      */
     @GetMapping("/getOpenId")
     @GetMapping("/getOpenId")
     public String getOpenId(String code) {
     public String getOpenId(String code) {
-        return weChatService.getOpenId(code);
+        String openId=userService.setOpenId(code);
+        return openId;
     }
     }
 
 
 
 

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@@ -205,4 +205,6 @@ public interface ISysUserService
     public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
     public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
 
 
     Object selectName(String name);
     Object selectName(String name);
+
+    String setOpenId(String code);
 }
 }

+ 14 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -7,6 +7,7 @@ import javax.validation.Validator;
 
 
 import com.ruoyi.system.mapper.*;
 import com.ruoyi.system.mapper.*;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysDeptService;
+import com.ruoyi.weChat.service.WeChatService;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -59,6 +60,8 @@ public class SysUserServiceImpl implements ISysUserService
     @Autowired
     @Autowired
     private ISysDeptService deptService;
     private ISysDeptService deptService;
     @Autowired
     @Autowired
+    private WeChatService weChatService;
+    @Autowired
     protected Validator validator;
     protected Validator validator;
 
 
     /**
     /**
@@ -548,4 +551,15 @@ public class SysUserServiceImpl implements ISysUserService
     public Object selectName(String name) {
     public Object selectName(String name) {
         return userMapper.selectName(name);
         return userMapper.selectName(name);
     }
     }
+
+    @Override
+    public String setOpenId(String code) {
+        System.out.println(code);
+        String openId = weChatService.getOpenId(code);
+        SysUser user = new SysUser();
+        user.setUserId(SecurityUtils.getUserId());
+        user.setOpenId(openId);
+        userMapper.updateUser(user);
+        return openId;
+    }
 }
 }

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/weChat/service/WeChatService.java

@@ -67,10 +67,10 @@ public class WeChatService {
 
 
 
 
 		public String getOpenId(String code) {
 		public String getOpenId(String code) {
-		String url = "https://api.weixin.qq.com/sns/jscode2session";
+		String url = "https://api.weixin.qq.com/sns/jscode2session?";
 		url=url+"appid="+appId+"&secret="+appSecret+"&js_code="+code+"&grant_type=authorization_code";
 		url=url+"appid="+appId+"&secret="+appSecret+"&js_code="+code+"&grant_type=authorization_code";
 
 
-			JSONObject js= HttpUtils.sendGetToJson(url);
+		JSONObject js= HttpUtils.sendGetToJson(url);
 		String openid=js.getString("openid");
 		String openid=js.getString("openid");
 		if (openid==null){
 		if (openid==null){
 			log.error("openId 获取异常");
 			log.error("openId 获取异常");