From dbe6994d09ec394ad4e11df2f906fa47fdb910ac Mon Sep 17 00:00:00 2001 From: jinqiming <45981669@qq.com> Date: Sun, 6 Jun 2021 13:59:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E6=89=AB=E6=8F=8F=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dingtalk/CallBackController.java | 6 +- .../dingtalk/ThirdOauthController.java | 133 +++++++++++------- .../controller/system/SysIndexController.java | 6 +- .../src/main/resources/templates/login.html | 4 +- .../src/main/resources/templates/main.html | 27 +++- .../system/user/profile/profile.html | 2 +- snow-common/pom.xml | 6 + 7 files changed, 118 insertions(+), 66 deletions(-) diff --git a/snow-admin/src/main/java/com/snow/web/controller/dingtalk/CallBackController.java b/snow-admin/src/main/java/com/snow/web/controller/dingtalk/CallBackController.java index 29f87a6..04b84b4 100644 --- a/snow-admin/src/main/java/com/snow/web/controller/dingtalk/CallBackController.java +++ b/snow-admin/src/main/java/com/snow/web/controller/dingtalk/CallBackController.java @@ -8,20 +8,16 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.snow.common.constant.Constants; import com.snow.common.enums.DingTalkListenerType; -import com.snow.dingtalk.common.EventNameEnum; import com.snow.dingtalk.sync.ISyncSysInfo; import com.snow.dingtalk.sync.SyncSysInfoFactory; import com.snow.system.domain.DingtalkCallBack; import com.snow.system.service.impl.DingtalkCallBackServiceImpl; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; import java.util.List; import java.util.Map; @@ -97,6 +93,8 @@ public class CallBackController { } } + + /** * 接收钉钉dingFlow机器人消息 * @return diff --git a/snow-admin/src/main/java/com/snow/web/controller/dingtalk/ThirdOauthController.java b/snow-admin/src/main/java/com/snow/web/controller/dingtalk/ThirdOauthController.java index e243940..1b30793 100644 --- a/snow-admin/src/main/java/com/snow/web/controller/dingtalk/ThirdOauthController.java +++ b/snow-admin/src/main/java/com/snow/web/controller/dingtalk/ThirdOauthController.java @@ -1,36 +1,25 @@ package com.snow.web.controller.dingtalk; -import com.alibaba.fastjson.JSONObject; -import com.dingtalk.api.response.OapiSnsGetuserinfoBycodeResponse; -import com.dingtalk.api.response.OapiUserGetbyunionidResponse; -import com.dingtalk.api.response.OapiV2UserGetResponse; import com.snow.common.core.controller.BaseController; import com.snow.common.core.domain.AjaxResult; -import com.snow.common.utils.AuthUtils; import com.snow.common.utils.ServletUtils; import com.snow.common.utils.StringUtils; -import com.snow.dingtalk.service.UserService; import com.snow.framework.shiro.auth.LoginType; import com.snow.framework.shiro.auth.UserToken; import com.snow.framework.util.ShiroUtils; import com.snow.system.domain.SysAuthUser; -import com.snow.system.domain.SysSocialUser; import com.snow.system.domain.SysUser; import com.snow.system.mapper.SysUserMapper; import com.snow.system.service.ISysConfigService; -import com.snow.system.service.impl.SysSocialUserServiceImpl; -import com.snow.system.service.impl.SysUserServiceImpl; -import me.zhyd.oauth.cache.AuthDefaultStateCache; import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.AuthDingTalkRequest; import me.zhyd.oauth.request.AuthRequest; +import me.zhyd.oauth.request.AuthWeChatEnterpriseRequest; import me.zhyd.oauth.utils.AuthStateUtils; import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.AuthenticationException; -import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -40,8 +29,6 @@ import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; /** * @program: snow @@ -71,19 +58,34 @@ public class ThirdOauthController extends BaseController { @ResponseBody public void renderAuth(@PathVariable("source") String source) throws IOException { - String appId= iSysConfigService.selectConfigByKey("ding.login.appid"); - String appSecret= iSysConfigService.selectConfigByKey("ding.login.appSecret"); - String redirectUri= iSysConfigService.selectConfigByKey("ding.login.redirectUri"); + AuthRequest authRequest =null; + switch (source){ + case "dingtalk": + authRequest= getDingTalkAuthRequest(); + break; + case "weChart": + authRequest=getWeChatAuthRequest(); + break; + } - AuthRequest authRequest = new AuthDingTalkRequest(AuthConfig.builder() - .clientId(appId) - .clientSecret(appSecret) - .redirectUri(redirectUri) - .build()); String authorizeUrl = authRequest.authorize(AuthStateUtils.createState()); ServletUtils.getResponse().sendRedirect(authorizeUrl); } + + /** + * 微信回调登录 + * @param callback + * @param request + * @return + */ + @SuppressWarnings("unchecked") + @GetMapping("/weChartLogin") + public Object weChartLogin(AuthCallback callback, HttpServletRequest request) + { + return thirdLogin("weChart",getWeChatAuthRequest(),callback); + } + /** * 钉钉回调 */ @@ -91,16 +93,73 @@ public class ThirdOauthController extends BaseController { @GetMapping("/dingTalkLogin") public Object callbackAuth(AuthCallback callback, HttpServletRequest request) { + return thirdLogin("dingtalk",getDingTalkAuthRequest(),callback); + } - String source="dingtalk"; + + + /** + * 检查是否授权 + */ + @PostMapping("/checkAuthUser") + @ResponseBody + public AjaxResult checkAuthUser(SysAuthUser authUser) + { + Long userId = ShiroUtils.getUserId(); + String source = authUser.getSource(); + if (userMapper.checkAuthUser(userId, source) > 0) + { + return error(source + "平台账号已经绑定"); + } + return AjaxResult.success(); + } + + /** + * 取消授权 + */ + @PostMapping("/unlock") + @ResponseBody + public AjaxResult unlockAuth(SysAuthUser authUser) + { + return toAjax(userMapper.deleteAuthUser(authUser.getAuthId())); + } + + /** + * 构建钉钉AuthRequest + * @return + */ + private AuthRequest getDingTalkAuthRequest() { String appId= iSysConfigService.selectConfigByKey("ding.login.appid"); String appSecret= iSysConfigService.selectConfigByKey("ding.login.appSecret"); String redirectUri= iSysConfigService.selectConfigByKey("ding.login.redirectUri"); - AuthRequest authRequest = new AuthDingTalkRequest(AuthConfig.builder() + return new AuthDingTalkRequest(AuthConfig.builder() .clientId(appId) .clientSecret(appSecret) .redirectUri(redirectUri) .build()); + } + + /** + * 构建企业微信AuthRequest + * @return + */ + private AuthRequest getWeChatAuthRequest() { + return new AuthWeChatEnterpriseRequest(AuthConfig.builder() + .clientId("ww2354bcd694497bd8") + .clientSecret("EzODWvC9zdPJJS4KnCNVENB3UhSiYCbmr9UrFpOM9dQ") + .redirectUri("http://workflow.vaiwan.com/third/oauth/weChartLogin") + .agentId("1000002") + .build()); + } + + /** + * 构建登录 + * @param source 来源 + * @param authRequest 请求参数 + * @param callback 请求参数 + * @return + */ + private Object thirdLogin(String source, AuthRequest authRequest,AuthCallback callback){ AuthResponse response = authRequest.login(callback); if (response.ok()) { @@ -139,30 +198,4 @@ public class ThirdOauthController extends BaseController { return new ModelAndView("error/404"); } - /** - * 检查是否授权 - */ - @PostMapping("/checkAuthUser") - @ResponseBody - public AjaxResult checkAuthUser(SysAuthUser authUser) - { - Long userId = ShiroUtils.getUserId(); - String source = authUser.getSource(); - if (userMapper.checkAuthUser(userId, source) > 0) - { - return error(source + "平台账号已经绑定"); - } - return AjaxResult.success(); - } - - /** - * 取消授权 - */ - @PostMapping("/unlock") - @ResponseBody - public AjaxResult unlockAuth(SysAuthUser authUser) - { - return toAjax(userMapper.deleteAuthUser(authUser.getAuthId())); - } - } diff --git a/snow-admin/src/main/java/com/snow/web/controller/system/SysIndexController.java b/snow-admin/src/main/java/com/snow/web/controller/system/SysIndexController.java index d2b1bb9..504eb16 100644 --- a/snow-admin/src/main/java/com/snow/web/controller/system/SysIndexController.java +++ b/snow-admin/src/main/java/com/snow/web/controller/system/SysIndexController.java @@ -167,15 +167,15 @@ public class SysIndexController extends BaseController sysNotice.setNoticeType("1"); List sysNotices = sysNoticeService.selectNoticeList(sysNotice); mmap.put("sysNotices",sysNotices); - if(CollectionUtil.isNotEmpty(sysNotices)&&sysNotices.size()>4){ - mmap.put("sysNoticeList",sysNotices.subList(0,4)); + if(CollectionUtil.isNotEmpty(sysNotices)&&sysNotices.size()>5){ + mmap.put("sysNoticeList",sysNotices.subList(0,5)); }else { mmap.put("sysNoticeList",sysNotices); } mmap.put("sysNoticeListSize",sysNotices.size()); HistoricTaskInstanceDTO historicTaskInstanceDTO=new HistoricTaskInstanceDTO(); historicTaskInstanceDTO.setPageNum(1); - historicTaskInstanceDTO.setPageSize(4); + historicTaskInstanceDTO.setPageSize(5); historicTaskInstanceDTO.setUserId(String.valueOf(sysUser.getUserId())); PageModel historicTaskInstance = flowableService.getHistoricTaskInstance(historicTaskInstanceDTO); mmap.put("historicTaskInstanceList",historicTaskInstance.getPagedRecords()); diff --git a/snow-admin/src/main/resources/templates/login.html b/snow-admin/src/main/resources/templates/login.html index b814f8e..d916956 100644 --- a/snow-admin/src/main/resources/templates/login.html +++ b/snow-admin/src/main/resources/templates/login.html @@ -71,8 +71,8 @@ -
- + diff --git a/snow-admin/src/main/resources/templates/main.html b/snow-admin/src/main/resources/templates/main.html index 63ac4a6..af64de5 100644 --- a/snow-admin/src/main/resources/templates/main.html +++ b/snow-admin/src/main/resources/templates/main.html @@ -54,7 +54,7 @@
-

待办数 - [[${flowGeneralSituation.todoTaskNum}]]

+

待办数 - [[${flowGeneralSituation.todoTaskNum}]]

@@ -65,7 +65,7 @@
-

已办数 - [[${flowGeneralSituation.doneTaskNum}]]

+

已办数 - [[${flowGeneralSituation.doneTaskNum}]]

@@ -75,7 +75,7 @@

- 流程数 - [[${flowGeneralSituation.myStartProcessInstanceNum}]] + 流程数 - [[${flowGeneralSituation.myStartProcessInstanceNum}]]

@@ -86,7 +86,7 @@

- 超时数 - [[${flowGeneralSituation.threeTodoTaskNum}]] + 超时数 - [[${flowGeneralSituation.threeTodoTaskNum}]]

@@ -176,7 +176,11 @@ - + @@ -197,7 +201,12 @@ - + @@ -353,6 +362,12 @@ var detailUrl="/system/notice/detail/"+id; $.modal.openTab("公告详情", detailUrl); } + function openMoreNotice(){ + $.modal.openTab("公告管理","/system/notice"); + } + function openMoreHistoricTask(){ + $.modal.openTab("我的已办","/flow/toMyTakePartInProcess"); + } function hisTaskDetail(detailUrl) { $.modal.openTab("我的已办", detailUrl); } diff --git a/snow-admin/src/main/resources/templates/system/user/profile/profile.html b/snow-admin/src/main/resources/templates/system/user/profile/profile.html index 75d127d..00cc27c 100644 --- a/snow-admin/src/main/resources/templates/system/user/profile/profile.html +++ b/snow-admin/src/main/resources/templates/system/user/profile/profile.html @@ -151,7 +151,7 @@ DingTalk - + WeiXin diff --git a/snow-common/pom.xml b/snow-common/pom.xml index 560a244..0e50eea 100644 --- a/snow-common/pom.xml +++ b/snow-common/pom.xml @@ -157,6 +157,12 @@ 2.6 + + com.github.binarywang + weixin-java-cp + 4.1.0 + + \ No newline at end of file