修改第三方登录 修改企业微信小程序登录
This commit is contained in:
+7
-5
@@ -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);
|
||||
|
||||
|
||||
+1
-1
@@ -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()
|
||||
|
||||
+15
-11
@@ -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<AuthLoginRespVO> loginByMxApp(String code) throws WxErrorException {
|
||||
public CommonResult<AuthLoginRespVO> 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()
|
||||
|
||||
+15
@@ -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;
|
||||
|
||||
}
|
||||
+3
@@ -51,4 +51,7 @@ public class UserBaseVO {
|
||||
@ApiModelProperty(value = "用户头像", example = "https://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
@ApiModelProperty("企业微信userid")
|
||||
private String cpUserId;
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -28,4 +28,6 @@ public class UserRespVO extends UserBaseVO {
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty("企业微信userid")
|
||||
private String cpUserId;
|
||||
}
|
||||
|
||||
+2
@@ -23,6 +23,8 @@ public interface UserConvert {
|
||||
|
||||
UserPageItemRespVO convert(AdminUserDO bean);
|
||||
|
||||
UserUpdateReqVO convertFromEntity(AdminUserDO bean);
|
||||
|
||||
UserPageItemRespVO.Dept convert(DeptDO bean);
|
||||
|
||||
AdminUserDO convert(UserCreateReqVO bean);
|
||||
|
||||
+5
@@ -91,4 +91,9 @@ public class AdminUserDO extends TenantBaseDO {
|
||||
*/
|
||||
private Date loginDate;
|
||||
|
||||
/**
|
||||
* 企业微信用户ID
|
||||
*/
|
||||
private String cpUserId;
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -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();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+2
-1
@@ -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 "企业微信同步完成...";
|
||||
}
|
||||
|
||||
+12
-5
@@ -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<CpUserMapper,CpUserDO> implem
|
||||
}
|
||||
|
||||
public void cpUserSync() throws WxErrorException {
|
||||
List<WxCpUser> userList = wxCpService.getUserService().listByDepartment(1L, true, 0);
|
||||
WxCpConfigStorage config = wxCpService.getWxCpConfigStorage();
|
||||
List<WxCpDepart> departList = wxCpService.getDepartmentService().list(null);
|
||||
List<WxCpUser> userList = wxCpService.getUserService().listByDepartment(35L, true, 0);
|
||||
|
||||
List<CpUserDO> rs = CpUserConvert.INSTANCE.convertListFromWxApi(userList);
|
||||
|
||||
@@ -117,10 +122,12 @@ public class CpUserServiceImpl extends ServiceImpl<CpUserMapper,CpUserDO> implem
|
||||
List<String> leaveUserIds = userList.stream().filter(wxCpUser -> wxCpUser.getStatus() == 0)
|
||||
.map(WxCpUser::getUserId).collect(Collectors.toList());
|
||||
|
||||
List<CpUserDO> leaveUsers = this.list(Wrappers.<CpUserDO>lambdaQuery()
|
||||
.in(CpUserDO::getUserId, leaveUserIds));
|
||||
leaveUsers.forEach(cpUserDO -> cpUserDO.setDeleted(true));
|
||||
this.updateBatchById(leaveUsers);
|
||||
if (ObjectUtil.isNotEmpty(leaveUserIds)) {
|
||||
List<CpUserDO> leaveUsers = this.list(Wrappers.<CpUserDO>lambdaQuery()
|
||||
.in(CpUserDO::getUserId, leaveUserIds));
|
||||
leaveUsers.forEach(cpUserDO -> cpUserDO.setDeleted(true));
|
||||
this.updateBatchById(leaveUsers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+3
-2
@@ -16,7 +16,7 @@
|
||||
<properties>
|
||||
<jjwt.version>0.10.6</jjwt.version>
|
||||
<mail.version>1.4.7</mail.version>
|
||||
<qiniu.version>7.9.5</qiniu.version>
|
||||
<qiniu.version>7.10.3</qiniu.version>
|
||||
<jjwt.version>0.10.6</jjwt.version>
|
||||
</properties>
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
<version>2.5.10</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--jwt-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
@@ -118,7 +119,7 @@
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>${qiniu.version}</version>
|
||||
<version>7.10.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user