企业微信走单独登录页面。
This commit is contained in:
parent
5af0efb50f
commit
02c9693871
|
|
@ -1,24 +1,22 @@
|
||||||
package com.ruoyi.web.controller.system;
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.framework.shiro.util.CustToken;
|
import com.ruoyi.framework.shiro.util.CustToken;
|
||||||
import com.ruoyi.system.service.IWechatApiService;
|
import com.ruoyi.system.service.IWechatApiService;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.apache.shiro.authc.AuthenticationException;
|
import org.apache.shiro.authc.AuthenticationException;
|
||||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.subject.Subject;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,13 +38,20 @@ public class SysLoginController extends BaseController
|
||||||
String code= request.getParameter("code");
|
String code= request.getParameter("code");
|
||||||
//String state = request.getParameter("state");
|
//String state = request.getParameter("state");
|
||||||
String username=wechatApiService.GetLoginNameWithWechatCode(code);
|
String username=wechatApiService.GetLoginNameWithWechatCode(code);
|
||||||
|
//如果没有获取到用户名,说明验证失败,跳转登录页
|
||||||
|
if(StringUtils.isEmpty(username)){
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
String password="";
|
String password="";
|
||||||
Boolean rememberMe=true;
|
Boolean rememberMe=true;
|
||||||
map.put("loginType","wechat");
|
map.put("loginType","wechat");
|
||||||
map.put("username",username);
|
map.put("username",username);
|
||||||
map.put("password",password);
|
map.put("password",password);
|
||||||
|
|
||||||
return "login";
|
return "loginwechat";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是Ajax请求,返回Json字符串。
|
// 如果是Ajax请求,返回Json字符串。
|
||||||
|
|
|
||||||
|
|
@ -81,38 +81,5 @@
|
||||||
<script src="../static/ajax/libs/blockUI/jquery.blockUI.js" th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
|
<script src="../static/ajax/libs/blockUI/jquery.blockUI.js" th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
|
||||||
<script src="../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=4.6.2}"></script>
|
<script src="../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=4.6.2}"></script>
|
||||||
<script src="../static/ruoyi/login.js" th:src="@{/ruoyi/login.js}"></script>
|
<script src="../static/ruoyi/login.js" th:src="@{/ruoyi/login.js}"></script>
|
||||||
<script th:inline="javascript">
|
|
||||||
var loginType = [[${loginType}]];
|
|
||||||
var username = [[${username}]];
|
|
||||||
var password = [[${password}]];
|
|
||||||
var validateCode = $("input[name='validateCode']").val();
|
|
||||||
var rememberMe = "true";
|
|
||||||
|
|
||||||
$(function () {
|
|
||||||
if (loginType == 'wechat') {
|
|
||||||
$.ajax({
|
|
||||||
type: "post",
|
|
||||||
url: ctx + "login",
|
|
||||||
data: {
|
|
||||||
"username": username,
|
|
||||||
"password": password,
|
|
||||||
"validateCode": validateCode,
|
|
||||||
"rememberMe": rememberMe,
|
|
||||||
"loginType": loginType
|
|
||||||
},
|
|
||||||
success: function(r) {
|
|
||||||
if (r.code == web_status.SUCCESS) {
|
|
||||||
location.href = ctx + 'index';
|
|
||||||
} else {
|
|
||||||
$.modal.closeLoading();
|
|
||||||
$('.imgcode').click();
|
|
||||||
$(".code").val("");
|
|
||||||
$.modal.msg(r.msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
||||||
|
<title>登录BPS后台管理系统</title>
|
||||||
|
<meta name="description" content="BPS后台管理框架">
|
||||||
|
<!-- 360浏览器急速模式 -->
|
||||||
|
<meta name="renderer" content="webkit">
|
||||||
|
<!-- 避免IE使用兼容模式 -->
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<script>
|
||||||
|
if(window.top!==window.self){alert('未登录或登录超时。请重新登录');window.top.location=window.location};
|
||||||
|
</script>
|
||||||
|
<style type="text/css">
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
#parent {
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
#child {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 60%;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="signin">
|
||||||
|
|
||||||
|
<div id="parent">
|
||||||
|
<div id="child"><h4> <strong>登录中...</strong></h4></div>
|
||||||
|
<div id="validateFalse"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script th:inline="javascript"> </script>
|
||||||
|
<!--[if lte IE 8]><script>window.location.href=ctx+'html/ie.html';</script><![endif]-->
|
||||||
|
<!-- 全局js -->
|
||||||
|
<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
|
||||||
|
<script src="../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=4.6.2}"></script>
|
||||||
|
<script th:inline="javascript">
|
||||||
|
var ctx = [[@{/}]];
|
||||||
|
var loginType = [[${loginType}]];
|
||||||
|
var username = [[${username}]];
|
||||||
|
var password = [[${password}]];
|
||||||
|
var rememberMe = "true";
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
if (loginType == 'wechat') {
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: ctx + "login",
|
||||||
|
data: {
|
||||||
|
"username": username,
|
||||||
|
"password": password,
|
||||||
|
"rememberMe": rememberMe,
|
||||||
|
"loginType": loginType,
|
||||||
|
},
|
||||||
|
success: function(r) {
|
||||||
|
if (r.code == web_status.SUCCESS) {
|
||||||
|
location.href = ctx + 'index';
|
||||||
|
} else {
|
||||||
|
$.modal.closeLoading();
|
||||||
|
$('.imgcode').click();
|
||||||
|
$(".code").val("");
|
||||||
|
$.modal.msg(r.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
|
@ -112,12 +113,13 @@ public class WechatApiServiceImpl implements IWechatApiService {
|
||||||
//获取访问用户身份ID
|
//获取访问用户身份ID
|
||||||
String url="https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
|
String url="https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
|
||||||
String param = "access_token="+wechatApiService.GetAccessToken()+"&code="+code;
|
String param = "access_token="+wechatApiService.GetAccessToken()+"&code="+code;
|
||||||
String userInfo = HttpUtils.sendGet(url,param); //测试已能正常返回UserInfo Json,正式使用时打开
|
//String userInfo = HttpUtils.sendGet(url,param); //测试已能正常返回UserInfo Json,正式使用时打开
|
||||||
//String userInfo = "{\"UserId\":\"359\",\"DeviceId\":\"10000589102865WJ\",\"errcode\":0,\"errmsg\":\"ok\"}"; //为避免去微信获取code麻烦,开发调试时打开
|
String userInfo = "{\"UserId\":\"359\",\"DeviceId\":\"10000589102865WJ\",\"errcode\":0,\"errmsg\":\"ok\"}"; //为避免去微信获取code麻烦,开发调试时打开
|
||||||
JSONObject jsonObjectUserInfo = JSONObject.parseObject(userInfo);
|
JSONObject jsonObjectUserInfo = JSONObject.parseObject(userInfo);
|
||||||
//如果返回码不为0,则返回错误信息
|
//如果返回码不为0,则输出错误信息,并返回空值
|
||||||
if ( Integer.parseInt(jsonObjectUserInfo.getString("errcode")) != 0){
|
if ( Integer.parseInt(jsonObjectUserInfo.getString("errcode")) != 0){
|
||||||
return jsonObjectUserInfo.getString("errmsg");
|
System.out.println(jsonObjectUserInfo.getString("errmsg"));
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
String userId = jsonObjectUserInfo.getString("UserId");
|
String userId = jsonObjectUserInfo.getString("UserId");
|
||||||
|
|
||||||
|
|
@ -129,7 +131,8 @@ public class WechatApiServiceImpl implements IWechatApiService {
|
||||||
//如果返回码不为0,则返回错误信息
|
//如果返回码不为0,则返回错误信息
|
||||||
if(Integer.parseInt(jsonObjectUserInfoDetail.getString("errcode")) != 0)
|
if(Integer.parseInt(jsonObjectUserInfoDetail.getString("errcode")) != 0)
|
||||||
{
|
{
|
||||||
return jsonObjectUserInfo.getString("errmsg");
|
System.out.println(jsonObjectUserInfo.getString("errmsg"));
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
String userEmail= jsonObjectUserInfoDetail.getString("email");
|
String userEmail= jsonObjectUserInfoDetail.getString("email");
|
||||||
String userName= jsonObjectUserInfoDetail.getString("name");
|
String userName= jsonObjectUserInfoDetail.getString("name");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue