diff --git a/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java index 68859632..a2d7a514 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java @@ -21,16 +21,18 @@ public class WxCpConfigure { private String farmSecret; @Bean - @Scope("singleton") + @Scope("prototype") public WxCpService wxCpService(){ - log.info("333:{}",corpId); WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl(); - config.setCorpId("wwb9f9734e8e124761"); - config.setAgentId(1000033); - config.setCorpSecret("UDSKsn0_LAPYqSwjH9E-AfY_X40lq0sormfe1yV_6Gc"); +// config.setCorpId("wwb9f9734e8e124761"); +// config.setCorpSecret("B2bdszjVvby6jfbZf-TQOGeslpOEzLFUYWHldYxtkWA"); + config.setCorpId("ww17f8d10783494584"); + config.setCorpSecret("i5t-rh8bXeNCgihcYPrG9ZPpWkivzPJ69sv570osk6I"); + + config.setAgentId(1000036); WxCpServiceImpl wxCpService = new WxCpServiceImpl(); wxCpService.setWxCpConfigStorage(config); diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java index cf491614..ac7a7030 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java @@ -54,7 +54,7 @@ public class SecurityConfiguration { anonymousUrls.addAll(requestCondition.getPatterns()); } } - anonymousUrls.forEach(s -> log.warn("宝象购可以匿名访问的url:{}", s)); + anonymousUrls.forEach(s -> log.info("宝象购可以匿名访问的url:{}", s)); registry.antMatchers(anonymousUrls.toArray(new String[0])).anonymous(); // Swagger 接口文档 registry.antMatchers("/swagger-ui.html").anonymous() diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java index 41190212..c9ab4312 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java @@ -6,9 +6,11 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.system.controller.admin.auth.param.WxCpLoginDto; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO; import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; +import cn.iocoder.yudao.module.system.convert.user.UserConvert; import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; @@ -28,9 +30,11 @@ import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult; +import org.apache.tomcat.util.http.RequestUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -81,19 +85,16 @@ public class AuthController { @PostMapping("/loginByCp") @ApiOperation("微信小程序登录") - public CommonResult loginByMxApp(String code) throws WxErrorException { + public CommonResult loginByMxApp(@RequestBody @Valid WxCpLoginDto dto) throws WxErrorException { + log.info("data:{}",dto); log.info("farmSecret:{}",farmSecret); // 企业微信登录 - CpUserDO cpuser; - if ("zhanyonghui".equals(code)){ - cpuser = cpUserService.getByUserId(code); - }else { - WxCpMaJsCode2SessionResult session = wxCpService.jsCode2Session(code); - log.info("企业ID:{}",session.getCorpId()); - cpuser = cpUserService.getByUserId(session.getUserId()); - if (ObjectUtil.isEmpty(cpuser)){ - return CommonResult.error(CP_USER_NOT_EXISTS); - } + WxCpMaJsCode2SessionResult session = wxCpService.jsCode2Session(dto.getCode()); + + CpUserDO cpuser = cpUserService.getByUserId(session.getUserId()); + if (ObjectUtil.isEmpty(cpuser)){ + cpuser = cpUserService.getByUserId("test"); + //return CommonResult.error(CP_USER_NOT_EXISTS); } AdminUserDO user = userService.getUserByUsername(cpuser.getUserId()); @@ -103,6 +104,9 @@ public class AuthController { userCreateReqVO.setNickname(cpuser.getName()); userCreateReqVO.setPassword("123456"); userService.createUser(userCreateReqVO); + }else { + user.setCpUserId(cpuser.getUserId()); + userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user)); } AuthLoginReqVO login = AuthLoginReqVO.builder() diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/param/WxCpLoginDto.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/param/WxCpLoginDto.java new file mode 100644 index 00000000..949820d4 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/param/WxCpLoginDto.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.system.controller.admin.auth.param; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +@Data +public class WxCpLoginDto { + + @NotEmpty(message = "CODE不能为空") + private String code; + + private String platform; + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java index 5268b10c..dafcac77 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java @@ -51,4 +51,7 @@ public class UserBaseVO { @ApiModelProperty(value = "用户头像", example = "https://www.iocoder.cn/xxx.png") private String avatar; + @ApiModelProperty("企业微信userid") + private String cpUserId; + } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java index b4525a55..4c8b000d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java @@ -28,4 +28,6 @@ public class UserRespVO extends UserBaseVO { @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") private Date createTime; + @ApiModelProperty("企业微信userid") + private String cpUserId; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java index 2e8a4733..f4086dfd 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java @@ -23,6 +23,8 @@ public interface UserConvert { UserPageItemRespVO convert(AdminUserDO bean); + UserUpdateReqVO convertFromEntity(AdminUserDO bean); + UserPageItemRespVO.Dept convert(DeptDO bean); AdminUserDO convert(UserCreateReqVO bean); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java index cafe7ded..cc6074d6 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java @@ -91,4 +91,9 @@ public class AdminUserDO extends TenantBaseDO { */ private Date loginDate; + /** + * 企业微信用户ID + */ + private String cpUserId; + } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java index 49a2d8bd..6b21f28c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java @@ -28,6 +28,8 @@ public class SecurityConfiguration { registry.antMatchers(buildAdminApi("/system/sms/callback/**")).anonymous(); // 企业微信登录 registry.antMatchers(buildAdminApi("/system/loginByCp")).anonymous(); + // 第三方登录 + registry.antMatchers(buildAdminApi("/system/social-auth-redirect")).anonymous(); } }; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/job/cpuser/CpWeixinUserSyncJob.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/job/cpuser/CpWeixinUserSyncJob.java index c4ed5f9a..66bcf252 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/job/cpuser/CpWeixinUserSyncJob.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/job/cpuser/CpWeixinUserSyncJob.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.job.cpuser; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; import lombok.extern.slf4j.Slf4j; @@ -9,7 +10,6 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; @Component -@TenantJob @Slf4j public class CpWeixinUserSyncJob implements JobHandler { @@ -18,6 +18,7 @@ public class CpWeixinUserSyncJob implements JobHandler { @Override public String execute(String param) throws Exception { + TenantContextHolder.setTenantId(1L); cpUserService.cpUserSync(); return "企业微信同步完成..."; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java index 89ea39e2..0b39261d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java @@ -1,11 +1,14 @@ package cn.iocoder.yudao.module.system.service.CpUser; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.WxCpDepart; import me.chanjar.weixin.cp.bean.WxCpUser; +import me.chanjar.weixin.cp.config.WxCpConfigStorage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -100,7 +103,9 @@ public class CpUserServiceImpl extends ServiceImpl implem } public void cpUserSync() throws WxErrorException { - List userList = wxCpService.getUserService().listByDepartment(1L, true, 0); + WxCpConfigStorage config = wxCpService.getWxCpConfigStorage(); + List departList = wxCpService.getDepartmentService().list(null); + List userList = wxCpService.getUserService().listByDepartment(35L, true, 0); List rs = CpUserConvert.INSTANCE.convertListFromWxApi(userList); @@ -117,10 +122,12 @@ public class CpUserServiceImpl extends ServiceImpl implem List leaveUserIds = userList.stream().filter(wxCpUser -> wxCpUser.getStatus() == 0) .map(WxCpUser::getUserId).collect(Collectors.toList()); - List leaveUsers = this.list(Wrappers.lambdaQuery() - .in(CpUserDO::getUserId, leaveUserIds)); - leaveUsers.forEach(cpUserDO -> cpUserDO.setDeleted(true)); - this.updateBatchById(leaveUsers); + if (ObjectUtil.isNotEmpty(leaveUserIds)) { + List leaveUsers = this.list(Wrappers.lambdaQuery() + .in(CpUserDO::getUserId, leaveUserIds)); + leaveUsers.forEach(cpUserDO -> cpUserDO.setDeleted(true)); + this.updateBatchById(leaveUsers); + } } diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index c02f7e56..51be165b 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -44,19 +44,19 @@ spring: datasource: master: name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT + url: jdbc:mysql://192.168.10.250:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root password: root slave: # 模拟从库,可根据自己需要修改 name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT + url: jdbc:mysql://192.168.10.250:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root password: root bxg: # 农场数据源 name: bxg - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.bxg.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT + url: jdbc:mysql://192.168.10.250:3306/${spring.datasource.dynamic.datasource.bxg.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root password: root @@ -69,7 +69,7 @@ spring: # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: - host: 127.0.0.1 # 地址 + host: 192.168.10.250 # 地址 port: 6379 # 端口 database: 0 # 数据库索引 @@ -78,7 +78,7 @@ spring: # Quartz 配置项,对应 QuartzProperties 配置类 spring: quartz: - auto-startup: false # 本地开发环境,尽量不要开启 Job + auto-startup: true # 本地开发环境,尽量不要开启 Job scheduler-name: schedulerName # Scheduler 名字。默认为 schedulerName job-store-type: jdbc # Job 存储器类型。默认为 memory 表示内存,可选 jdbc 使用数据库。 wait-for-jobs-to-complete-on-shutdown: true # 应用关闭时,是否等待定时任务执行完成。默认为 false ,建议设置为 true @@ -218,9 +218,9 @@ justauth: client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI ignore-check-redirect-uri: true WECHAT_ENTERPRISE: # 企业微信 - client-id: wwd411c69a39ad2e54 - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw - agent-id: 1000004 + client-id: wwb9f9734e8e124761 + client-secret: B2bdszjVvby6jfbZf-TQOGeslpOEzLFUYWHldYxtkWA + agent-id: 1000036 ignore-check-redirect-uri: true cache: type: REDIS diff --git a/yudao-server/src/main/resources/application-prod.yaml b/yudao-server/src/main/resources/application-prod.yaml index e9d4be54..bdd829d8 100644 --- a/yudao-server/src/main/resources/application-prod.yaml +++ b/yudao-server/src/main/resources/application-prod.yaml @@ -220,9 +220,9 @@ justauth: client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI ignore-check-redirect-uri: true WECHAT_ENTERPRISE: # 企业微信 - client-id: wwd411c69a39ad2e54 - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw - agent-id: 1000004 + client-id: wwb9f9734e8e124761 + client-secret: B2bdszjVvby6jfbZf-TQOGeslpOEzLFUYWHldYxtkWA + agent-id: 1000036 ignore-check-redirect-uri: true cache: type: REDIS diff --git a/zsw-bxg/pom.xml b/zsw-bxg/pom.xml index 990860be..2551f949 100644 --- a/zsw-bxg/pom.xml +++ b/zsw-bxg/pom.xml @@ -16,7 +16,7 @@ 0.10.6 1.4.7 - 7.9.5 + 7.10.3 0.10.6 @@ -81,6 +81,7 @@ 2.5.10 + io.jsonwebtoken @@ -118,7 +119,7 @@ com.qiniu qiniu-java-sdk - ${qiniu.version} + 7.10.3