diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java index 55eff17c5..60b604054 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java @@ -53,7 +53,6 @@ public enum LoginTypeEnum { */ MINI_APP("MINI", "微信小程序"), - WXCP("WXCP", "企业微信登录"), /** * 码云登录 */ diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WxCpLoginHandler.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WxCpLoginHandler.java new file mode 100644 index 000000000..bd27156a9 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WxCpLoginHandler.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.handler; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.service.ConnectService; +import com.pig4cloud.pigx.admin.service.SysUserService; +import lombok.AllArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; +import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2022/7/19 + * + * 企业微信免密登录 + */ +@Slf4j +@Component("WEIXIN_CP") +@AllArgsConstructor +public class WxCpLoginHandler extends AbstractLoginHandler { + + private ConnectService connectService; + + private final SysUserService sysUserService; + + /** + * 微信登录传入code + *
+ * 通过code 调用qq 获取唯一标识
+ * @param code
+ * @return
+ */
+ @Override
+ @SneakyThrows
+ public String identify(String code) {
+ WxCpService wxCpService = new WxCpServiceImpl();
+ wxCpService.setWxCpConfigStorage(connectService.getCpConfig());
+
+ WxCpOauth2UserInfo userInfo = wxCpService.getOauth2Service().getUserInfo(code);
+ log.info("企业微信返回报文:{}", userInfo);
+ return userInfo.getUserId();
+ }
+
+ /**
+ * openId 获取用户信息
+ * @param openId
+ * @return
+ */
+ @Override
+ public UserInfo info(String openId) {
+ SysUser user = sysUserService.getOne(Wrappers.