优化企业微信登录

This commit is contained in:
bo.yang 2021-07-30 12:02:11 +08:00
parent f6e16a6cb1
commit d18dc2c515
4 changed files with 27 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package com.ruoyi.test.conrtroller;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.service.IWechatApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -46,9 +47,13 @@ public class WechatApiController extends BaseController {
@ResponseBody
public Map<String, String> SendTextMessageToWechatUser() {
List<String> userIdList = new ArrayList<>();
userIdList.add("2342343243");
userIdList.add("erqrqwe");
userIdList.add("2342343243");//错误userId示例
userIdList.add("erqrqwe");//错误userId示例
userIdList.add(""); //空UserId示例
userIdList.add("359");
if(!ShiroUtils.getUserId().equals("359")){
userIdList.add(String.valueOf(ShiroUtils.getUserId()));
}
Map<String, String> resultMap = wechatApiService.SendTextMessageToWechatUser(userIdList,"<a href=\"www.baidu.com\">哈哈哈!</a>");
return resultMap;
}
@ -57,11 +62,15 @@ public class WechatApiController extends BaseController {
@ResponseBody
public Map<String, String> SendTextCardMessageToWechatUser() {
List<String> userIdList = new ArrayList<>();
userIdList.add("23456667");
userIdList.add("355354354");
userIdList.add("23456667"); //错误userId示例
userIdList.add("355354354"); //错误userId示例
userIdList.add(""); //空UserId示例
userIdList.add("359");
userIdList.add("454");
userIdList.add("408");
//userIdList.add("454");
//userIdList.add("408");
if(!ShiroUtils.getUserId().equals("359")){
userIdList.add(String.valueOf(ShiroUtils.getUserId()));
}
String title="号外:特大优惠!限时抢购";
String description="今年仅此一次苹果手机1000元起欢迎前来购买走过路过不要错过";
String dtailUrl="https://item.jd.com/100008348530.html";

View File

@ -38,17 +38,15 @@ public class SysLoginController extends BaseController
String code= request.getParameter("code");
//String state = request.getParameter("state");
String username=wechatApiService.GetLoginNameWithWechatCode(code);
//如果没有获取到用户说明验证失败跳转登录页
//如果没有获取到登录说明验证失败跳转登录页
if(StringUtils.isEmpty(username)){
return "login";
}
String password="";
Boolean rememberMe=true;
map.put("loginType","wechat");
map.put("username",username);
map.put("password",password);
return "loginwechat";

View File

@ -51,7 +51,7 @@
var loginType = [[${loginType}]];
var username = [[${username}]];
var password = [[${password}]];
var rememberMe = "true";
var rememberMe = true;
$(function () {
if (loginType == 'wechat') {

View File

@ -112,12 +112,19 @@ public class WechatApiServiceImpl implements IWechatApiService {
@Override
public String GetLoginNameWithWechatCode(String code)
{
if(StringUtils.isEmpty(code)){
return "";
}
//获取访问用户身份ID
String userId= GetUseridByWechatLogin(code);
if(StringUtils.isEmpty(userId)){
return "";
}
//获取用户邮箱与姓名
WechatUserInfo wechatUserInfo = GetWechatUserInfoDetailByUserId(userId);
if (null==wechatUserInfo || null==wechatUserInfo.getName()){
return "";
}
//根据用户id+邮箱名+用户名匹配本地用户对应的userId+邮箱名与用户名
SysUser sysUserWechat=new SysUser();
sysUserWechat.setUserId(Long.parseLong(wechatUserInfo.getUserid()));
@ -131,7 +138,7 @@ public class WechatApiServiceImpl implements IWechatApiService {
return ""; //系统里没有用户没有从OA同步 处理逻辑待定
}
if(count > 1){
return ""; //本地数据库存在多个姓名与邮箱相同的记录如何处理
return ""; //本地数据库存在多个姓名与邮箱相同的记录如何处理--加上了sysUserWechat.setUserId(Long.parseLong(wechatUserInfo.getUserid()));不存在这种情况了
}
String loginName= userList.get(0).getLoginName();
return loginName;