feat: 第三方登录完善
This commit is contained in:
@@ -1,12 +1,8 @@
|
|||||||
package com.schisandra.auth.api;
|
package com.schisandra.auth.api;
|
||||||
|
|
||||||
import com.schisandra.auth.entity.Result;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
@FeignClient("schisandra-cloud-storage-auth")
|
@FeignClient("schisandra-cloud-storage-auth")
|
||||||
public interface SchisandraAuthFeignService {
|
public interface SchisandraAuthFeignService {
|
||||||
@PostMapping("/auth/user/wechatLogin")
|
|
||||||
Result wechatLogin(@RequestParam(value = "openId") String openId);
|
|
||||||
}
|
}
|
||||||
|
@@ -298,25 +298,4 @@ public class SchisandraAuthUserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 微信登录
|
|
||||||
* @param: [authUser]
|
|
||||||
* @return: com.schisandra.auth.common.entity.Result
|
|
||||||
* @author: landaiqing
|
|
||||||
* @date: 2024/6/20 下午9:27
|
|
||||||
*/
|
|
||||||
@PostMapping("wechatLogin")
|
|
||||||
public Result wechatLogin(@RequestParam(value = "openId") String openId) {
|
|
||||||
log.info("UserController.wechatLogin.openId:{}", openId);
|
|
||||||
Preconditions.checkNotNull(openId, "openId 不能为空");
|
|
||||||
Boolean result = schisandraAuthUserDomainService.wechatLogin(openId);
|
|
||||||
if (result) {
|
|
||||||
return Result.ok("登录成功");
|
|
||||||
} else {
|
|
||||||
return Result.fail("登录失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.schisandra.auth.application.convert;
|
||||||
|
|
||||||
|
import com.schisandra.auth.application.dto.SchisandraSocialUserAuthDTO;
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserAuthBO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dto转换器
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SchisandraSocialUserAuthDTOConverter {
|
||||||
|
|
||||||
|
SchisandraSocialUserAuthDTOConverter INSTANCE = Mappers.getMapper(SchisandraSocialUserAuthDTOConverter.class);
|
||||||
|
|
||||||
|
SchisandraSocialUserAuthBO convertDTOToBO(SchisandraSocialUserAuthDTO schisandraSocialUserAuthDTO);
|
||||||
|
SchisandraSocialUserAuthDTO convertBOToDTO(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO);
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.schisandra.auth.application.convert;
|
||||||
|
|
||||||
|
import com.schisandra.auth.application.dto.SchisandraSocialUserDTO;
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserBO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dto转换器
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SchisandraSocialUserDTOConverter {
|
||||||
|
|
||||||
|
SchisandraSocialUserDTOConverter INSTANCE = Mappers.getMapper(SchisandraSocialUserDTOConverter.class);
|
||||||
|
|
||||||
|
SchisandraSocialUserBO convertDTOToBO(SchisandraSocialUserDTO schisandraSocialUserDTO);
|
||||||
|
SchisandraSocialUserDTO convertBOToDTO(SchisandraSocialUserBO schisandraSocialUserBO);
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.schisandra.auth.application.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dto
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SchisandraSocialUserAuthDTO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long socialUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,143 @@
|
|||||||
|
package com.schisandra.auth.application.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dto
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SchisandraSocialUserDTO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方系统的唯一ID
|
||||||
|
*/
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户来源
|
||||||
|
*/
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的授权令牌
|
||||||
|
*/
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的授权令牌的有效期
|
||||||
|
*/
|
||||||
|
private Integer expireIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新令牌
|
||||||
|
*/
|
||||||
|
private String refreshToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 open id
|
||||||
|
*/
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 ID
|
||||||
|
*/
|
||||||
|
private String uid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个别平台的授权信息
|
||||||
|
*/
|
||||||
|
private String accessCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 union id
|
||||||
|
*/
|
||||||
|
private String unionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户授予的权限
|
||||||
|
*/
|
||||||
|
private String scope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个别平台的授权信息
|
||||||
|
*/
|
||||||
|
private String tokenType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id token
|
||||||
|
*/
|
||||||
|
private String idToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小米平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String macAlgorithm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小米平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String macKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的授权code
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Twitter平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String oauthToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Twitter平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String oauthTokenSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String extJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -1,110 +0,0 @@
|
|||||||
package com.schisandra.auth.common.utils;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName AESUtils 一定要选择16位密钥长度,也就是KEY_LENGTH=16*8,36的话就需要修改环境的jar包。
|
|
||||||
* @Description TODO
|
|
||||||
* @Author L
|
|
||||||
* @Date 2024/1/26 17:27
|
|
||||||
*/
|
|
||||||
public class AESUtils {
|
|
||||||
/**
|
|
||||||
* 加密算法AES
|
|
||||||
*/
|
|
||||||
private static final String KEY_ALGORITHM = "AES";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* key的长度,Wrong key size: must be equal to 128, 192 or 256
|
|
||||||
* 传入时需要16、24、36
|
|
||||||
*/
|
|
||||||
private static final int KEY_LENGTH = 16 * 8;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 算法名称/加密模式/数据填充方式
|
|
||||||
* 默认:AES/ECB/PKCS5Padding
|
|
||||||
*/
|
|
||||||
private static final String ALGORITHMS = "AES/ECB/PKCS5Padding";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 后端AES的key,由静态代码块赋值
|
|
||||||
*/
|
|
||||||
public static String key;
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
key = getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取key
|
|
||||||
*/
|
|
||||||
public static String getKey() {
|
|
||||||
int length = KEY_LENGTH / 8;
|
|
||||||
StringBuilder uid = new StringBuilder(length);
|
|
||||||
//产生32位的强随机数
|
|
||||||
Random rd = new SecureRandom();
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
//产生0-2的3位随机数
|
|
||||||
switch (rd.nextInt(3)) {
|
|
||||||
case 0:
|
|
||||||
//0-9的随机数
|
|
||||||
uid.append(rd.nextInt(10));
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
//ASCII在65-90之间为大写,获取大写随机
|
|
||||||
uid.append((char) (rd.nextInt(26) + 65));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
//ASCII在97-122之间为小写,获取小写随机
|
|
||||||
uid.append((char) (rd.nextInt(26) + 97));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uid.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 加密
|
|
||||||
*
|
|
||||||
* @param content 加密的字符串
|
|
||||||
* @param encryptKey key值
|
|
||||||
*/
|
|
||||||
public static String encrypt(String content, String encryptKey) throws Exception {
|
|
||||||
//设置Cipher对象
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), KEY_ALGORITHM));
|
|
||||||
|
|
||||||
//调用doFinal
|
|
||||||
// 转base64
|
|
||||||
return Base64.encodeBase64String(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 解密
|
|
||||||
*
|
|
||||||
* @param encryptStr 解密的字符串
|
|
||||||
* @param decryptKey 解密的key值
|
|
||||||
*/
|
|
||||||
public static String decrypt(String encryptStr, String decryptKey) throws Exception {
|
|
||||||
//base64格式的key字符串转byte
|
|
||||||
byte[] decodeBase64 = Base64.decodeBase64(encryptStr);
|
|
||||||
|
|
||||||
|
|
||||||
//设置Cipher对象
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), KEY_ALGORITHM));
|
|
||||||
//调用doFinal解密
|
|
||||||
return new String(cipher.doFinal(decodeBase64));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,61 +0,0 @@
|
|||||||
package com.schisandra.auth.common.utils;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
public class MD5Util {
|
|
||||||
//十六进制下数字到字符的映射数组
|
|
||||||
private final static String[] hexDigits = {"0", "1", "2", "3", "4",
|
|
||||||
"5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 把inputString加密
|
|
||||||
*/
|
|
||||||
public static String md5(String inputString) {
|
|
||||||
return encodeByMD5(inputString);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 对字符串进行MD5加密
|
|
||||||
*/
|
|
||||||
private static String encodeByMD5(String originString) {
|
|
||||||
if (originString != null) {
|
|
||||||
try {
|
|
||||||
//创建具有指定算法名称的信息摘要
|
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
//使用指定的字节数组对摘要进行最后更新,然后完成摘要计算
|
|
||||||
byte[] results = md.digest(originString.getBytes("utf-8"));
|
|
||||||
//将得到的字节数组变成字符串返回
|
|
||||||
String resultString = byteArrayToHexString(results);
|
|
||||||
return resultString.toUpperCase();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 转换字节数组为十六进制字符串
|
|
||||||
*
|
|
||||||
* @param
|
|
||||||
* @return 十六进制字符串
|
|
||||||
*/
|
|
||||||
private static String byteArrayToHexString(byte[] b) {
|
|
||||||
StringBuffer resultSb = new StringBuffer();
|
|
||||||
for (int i = 0; i < b.length; i++) {
|
|
||||||
resultSb.append(byteToHexString(b[i]));
|
|
||||||
}
|
|
||||||
return resultSb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String byteToHexString(byte b) {
|
|
||||||
int n = b;
|
|
||||||
if (n < 0) {
|
|
||||||
n += 256;
|
|
||||||
}
|
|
||||||
int d1 = n / 16;
|
|
||||||
int d2 = n % 16;
|
|
||||||
return hexDigits[d1] + hexDigits[d2];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@@ -1,171 +0,0 @@
|
|||||||
package com.schisandra.auth.common.utils;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.security.Key;
|
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.KeyPairGenerator;
|
|
||||||
import java.security.interfaces.RSAPrivateKey;
|
|
||||||
import java.security.interfaces.RSAPublicKey;
|
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName RSAUtils
|
|
||||||
* @Description TODO
|
|
||||||
* @Author L
|
|
||||||
* @Date 2024/1/26 17:28
|
|
||||||
*/
|
|
||||||
public class RSAUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加密算法RSA
|
|
||||||
*/
|
|
||||||
private static final String KEY_ALGORITHM = "RSA";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 算法名称/加密模式/数据填充方式
|
|
||||||
* 默认:RSA/ECB/PKCS1Padding
|
|
||||||
*/
|
|
||||||
private static final String ALGORITHMS = "RSA/ECB/PKCS1Padding";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA最大加密明文大小
|
|
||||||
*/
|
|
||||||
private static final int MAX_ENCRYPT_BLOCK = 245;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA最大解密密文大小
|
|
||||||
*/
|
|
||||||
private static final int MAX_DECRYPT_BLOCK = 256;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA 位数 如果采用2048 上面最大加密和最大解密则须填写: 245 256
|
|
||||||
*/
|
|
||||||
private static final int INITIALIZE_LENGTH = 2048;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 后端RSA的密钥对(公钥和私钥)Map,由静态代码块赋值
|
|
||||||
*/
|
|
||||||
private static final Map<String, String> map = new LinkedHashMap<>(2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成密钥对(公钥和私钥)
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static Map<String,String> genKeyPair() throws Exception {
|
|
||||||
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
|
|
||||||
keyPairGen.initialize(INITIALIZE_LENGTH);
|
|
||||||
KeyPair keyPair = keyPairGen.generateKeyPair();
|
|
||||||
// 获取公钥
|
|
||||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
|
||||||
// 获取私钥
|
|
||||||
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
|
|
||||||
// 得到公钥字符串
|
|
||||||
String publicKeyString = Base64.encodeBase64String(publicKey.getEncoded());
|
|
||||||
// 得到私钥字符串
|
|
||||||
String privateKeyString = Base64.encodeBase64String((privateKey.getEncoded()));
|
|
||||||
map.put("publicKey",publicKeyString);
|
|
||||||
map.put("privateKey",privateKeyString);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
public static String getPrivateKey(){
|
|
||||||
return map.get("privateKey");
|
|
||||||
}
|
|
||||||
public static String getPublicKey(){
|
|
||||||
return map.get("publicKey");
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* RSA私钥解密
|
|
||||||
* @param data BASE64编码过的密文
|
|
||||||
* @param privateKey 私钥(BASE64编码)
|
|
||||||
* @return utf-8编码的明文
|
|
||||||
*/
|
|
||||||
public static byte[] decryptByPrivateKey(byte[] data, String privateKey) throws Exception {
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateK);
|
|
||||||
|
|
||||||
//分段进行解密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA公钥加密
|
|
||||||
* @param data BASE64编码过的密文
|
|
||||||
* @param publicKey 公钥(BASE64编码)
|
|
||||||
* @return utf-8编码的明文
|
|
||||||
*/
|
|
||||||
public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception {
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicK);
|
|
||||||
//分段进行加密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA公钥解密
|
|
||||||
* @param data BASE64编码过的密文
|
|
||||||
* @param publicKey RSA公钥
|
|
||||||
* @return utf-8编码的明文
|
|
||||||
*/
|
|
||||||
public static byte[] pubKeyDec(byte[] data, String publicKey) throws Exception {
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateK);
|
|
||||||
|
|
||||||
//分段进行解密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA私钥加密
|
|
||||||
* @param data 待加密的明文
|
|
||||||
* @param privateKey RSA私钥
|
|
||||||
* @return 经BASE64编码后的密文
|
|
||||||
*/
|
|
||||||
public static byte[] privKeyEnc(byte[] data, String privateKey) throws Exception {
|
|
||||||
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicK);
|
|
||||||
|
|
||||||
//分段进行加密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分段进行加密、解密操作
|
|
||||||
*/
|
|
||||||
private static byte[] encryptAndDecryptOfSubsection(byte[] data, Cipher cipher, int encryptBlock) throws Exception {
|
|
||||||
int inputLen = data.length;
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
int offSet = 0;
|
|
||||||
byte[] cache;
|
|
||||||
int i = 0;
|
|
||||||
// 对数据分段加密
|
|
||||||
while (inputLen - offSet > 0) {
|
|
||||||
if (inputLen - offSet > encryptBlock) {
|
|
||||||
cache = cipher.doFinal(data, offSet, encryptBlock);
|
|
||||||
} else {
|
|
||||||
cache = cipher.doFinal(data, offSet, inputLen - offSet);
|
|
||||||
}
|
|
||||||
out.write(cache, 0, cache.length);
|
|
||||||
i++;
|
|
||||||
offSet = i * encryptBlock;
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
return out.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,32 +0,0 @@
|
|||||||
package com.schisandra.auth.common.utils;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class SmsCodeUtils {
|
|
||||||
public static Integer generateValidateCode(int length){
|
|
||||||
Integer code =null;
|
|
||||||
|
|
||||||
//长度为4
|
|
||||||
if(length == 4){
|
|
||||||
//生成随机数,最大为9999
|
|
||||||
code = new Random().nextInt(9999);
|
|
||||||
if(code < 1000){
|
|
||||||
//保证随机数为4位数字
|
|
||||||
code = code + 1000;
|
|
||||||
}
|
|
||||||
//长度为6
|
|
||||||
}else if(length == 6){
|
|
||||||
//生成随机数,最大为999999
|
|
||||||
code = new Random().nextInt(999999);
|
|
||||||
if(code < 100000){
|
|
||||||
//保证随机数为6位数字
|
|
||||||
code = code + 100000;
|
|
||||||
}
|
|
||||||
//其他情况
|
|
||||||
}else{
|
|
||||||
throw new RuntimeException("只能生成4位或6位数字验证码");
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,57 @@
|
|||||||
|
package com.schisandra.auth.domain.bo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
/**
|
||||||
|
* bo
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SchisandraSocialUserAuthBO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long socialUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,142 @@
|
|||||||
|
package com.schisandra.auth.domain.bo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
/**
|
||||||
|
* bo
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SchisandraSocialUserBO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方系统的唯一ID
|
||||||
|
*/
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户来源
|
||||||
|
*/
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的授权令牌
|
||||||
|
*/
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的授权令牌的有效期
|
||||||
|
*/
|
||||||
|
private Integer expireIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新令牌
|
||||||
|
*/
|
||||||
|
private String refreshToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 open id
|
||||||
|
*/
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 ID
|
||||||
|
*/
|
||||||
|
private String uid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个别平台的授权信息
|
||||||
|
*/
|
||||||
|
private String accessCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 union id
|
||||||
|
*/
|
||||||
|
private String unionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户授予的权限
|
||||||
|
*/
|
||||||
|
private String scope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个别平台的授权信息
|
||||||
|
*/
|
||||||
|
private String tokenType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id token
|
||||||
|
*/
|
||||||
|
private String idToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小米平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String macAlgorithm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小米平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String macKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的授权code
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Twitter平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String oauthToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Twitter平台用户的附带属性
|
||||||
|
*/
|
||||||
|
private String oauthTokenSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String extJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.schisandra.auth.domain.convert;
|
||||||
|
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserAuthBO;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bo转换器
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SchisandraSocialUserAuthBOConverter {
|
||||||
|
|
||||||
|
SchisandraSocialUserAuthBOConverter INSTANCE = Mappers.getMapper(SchisandraSocialUserAuthBOConverter.class);
|
||||||
|
|
||||||
|
SchisandraSocialUserAuth convertBOToEntity(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO);
|
||||||
|
SchisandraSocialUserAuthBO convertEntityToBO(SchisandraSocialUserAuth schisandraSocialUserAuth);
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.schisandra.auth.domain.convert;
|
||||||
|
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserBO;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUser;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bo转换器
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SchisandraSocialUserBOConverter {
|
||||||
|
|
||||||
|
SchisandraSocialUserBOConverter INSTANCE = Mappers.getMapper(SchisandraSocialUserBOConverter.class);
|
||||||
|
|
||||||
|
SchisandraSocialUser convertBOToEntity(SchisandraSocialUserBO schisandraSocialUserBO);
|
||||||
|
SchisandraSocialUserBO convertEntityToBO(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
|
||||||
|
}
|
@@ -93,7 +93,5 @@ public interface SchisandraAuthUserDomainService {
|
|||||||
Object deleteById(Long id);
|
Object deleteById(Long id);
|
||||||
|
|
||||||
SchisandraAuthUser queryByPhone(String phone);
|
SchisandraAuthUser queryByPhone(String phone);
|
||||||
|
|
||||||
Boolean wechatLogin(String openId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
package com.schisandra.auth.domain.service;
|
||||||
|
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserAuthBO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领域service
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
public interface SchisandraSocialUserAuthDomainService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加 信息
|
||||||
|
*/
|
||||||
|
Boolean add(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新 信息
|
||||||
|
*/
|
||||||
|
Boolean update(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 信息
|
||||||
|
*/
|
||||||
|
Boolean delete(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO);
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
package com.schisandra.auth.domain.service;
|
||||||
|
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserBO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领域service
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
public interface SchisandraSocialUserDomainService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加 信息
|
||||||
|
*/
|
||||||
|
Boolean add(SchisandraSocialUserBO schisandraSocialUserBO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新 信息
|
||||||
|
*/
|
||||||
|
Boolean update(SchisandraSocialUserBO schisandraSocialUserBO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 信息
|
||||||
|
*/
|
||||||
|
Boolean delete(SchisandraSocialUserBO schisandraSocialUserBO);
|
||||||
|
|
||||||
|
}
|
@@ -9,12 +9,15 @@ import com.schisandra.auth.common.entity.Result;
|
|||||||
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
|
||||||
import com.schisandra.auth.common.enums.OauthType;
|
import com.schisandra.auth.common.enums.OauthType;
|
||||||
import com.schisandra.auth.common.enums.UserRoleEnum;
|
import com.schisandra.auth.common.enums.UserRoleEnum;
|
||||||
import com.schisandra.auth.common.enums.UserStatusEnum;
|
|
||||||
import com.schisandra.auth.common.redis.RedisUtil;
|
import com.schisandra.auth.common.redis.RedisUtil;
|
||||||
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
|
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
|
||||||
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
|
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserAuthBO;
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserBO;
|
||||||
import com.schisandra.auth.domain.convert.SchisandraAuthUserBOConverter;
|
import com.schisandra.auth.domain.convert.SchisandraAuthUserBOConverter;
|
||||||
import com.schisandra.auth.domain.convert.SchisandraAuthUserRoleBOConverter;
|
import com.schisandra.auth.domain.convert.SchisandraAuthUserRoleBOConverter;
|
||||||
|
import com.schisandra.auth.domain.convert.SchisandraSocialUserAuthBOConverter;
|
||||||
|
import com.schisandra.auth.domain.convert.SchisandraSocialUserBOConverter;
|
||||||
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
|
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
|
||||||
import com.schisandra.auth.infra.basic.entity.*;
|
import com.schisandra.auth.infra.basic.entity.*;
|
||||||
import com.schisandra.auth.infra.basic.service.*;
|
import com.schisandra.auth.infra.basic.service.*;
|
||||||
@@ -48,6 +51,11 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SchisandraAuthRoleService schisandraAuthRoleService;
|
private SchisandraAuthRoleService schisandraAuthRoleService;
|
||||||
|
@Resource
|
||||||
|
private SchisandraSocialUserService schisandraSocialUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraSocialUserAuthService schisandraSocialUserAuthService;
|
||||||
|
|
||||||
|
|
||||||
private final String AUTH_PERMISSION_PREFIX = "auth.permission";
|
private final String AUTH_PERMISSION_PREFIX = "auth.permission";
|
||||||
@@ -210,60 +218,9 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
return schisandraAuthUserService.queryByPhone(phone);
|
return schisandraAuthUserService.queryByPhone(phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 微信登陆
|
|
||||||
* @param: [schisandraAuthUserBO]
|
|
||||||
* @return: java.lang.Boolean
|
|
||||||
* @author: landaiqing
|
|
||||||
* @date: 2024/6/20 下午9:32
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Boolean wechatLogin(String openId) {
|
|
||||||
SchisandraAuthUser schisandraAuthUser = schisandraAuthUserService.selectByUuidAndType(openId, OauthType.WECHAT.getType());
|
|
||||||
if (ObjectUtils.isNotEmpty(schisandraAuthUser)) {
|
|
||||||
Long userId = schisandraAuthUser.getId();
|
|
||||||
// redis存储用户角色与权限信息
|
|
||||||
userInfoPersistence(userId);
|
|
||||||
StpUtil.login(userId);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// 插入用户信息表
|
|
||||||
SchisandraAuthUserBO schisandraAuthUserBO = new SchisandraAuthUserBO();
|
|
||||||
schisandraAuthUserBO.setUuid(openId);
|
|
||||||
schisandraAuthUserBO.setSource(OauthType.WECHAT.getType());
|
|
||||||
schisandraAuthUserBO.setStatus(UserStatusEnum.NORMAL.getCode());
|
|
||||||
schisandraAuthUserBO.setUserName(openId);
|
|
||||||
SchisandraAuthUser AuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
|
|
||||||
int result = schisandraAuthUserService.insertAuthUserByOauth(AuthUser);
|
|
||||||
if (result <= 0) {
|
|
||||||
if (log.isInfoEnabled()) {
|
|
||||||
log.error("insertAuthUserByOauth fail, param:{}", JSONObject.toJSONString(AuthUser));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Long authUserId = AuthUser.getId();
|
|
||||||
// 建立用户与角色映射关系
|
|
||||||
SchisandraAuthUserRoleBO schisandraAuthUserRoleBO = new SchisandraAuthUserRoleBO();
|
|
||||||
schisandraAuthUserRoleBO.setUserId(authUserId);
|
|
||||||
schisandraAuthUserRoleBO.setRoleId(UserRoleEnum.NORMAL_USER.getCode());
|
|
||||||
schisandraAuthUserRoleBO.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
|
||||||
SchisandraAuthUserRole schisandraAuthUserRole = SchisandraAuthUserRoleBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserRoleBO);
|
|
||||||
int insert = schisandraAuthUserRoleService.insert(schisandraAuthUserRole);
|
|
||||||
if (insert <= 0) {
|
|
||||||
if (log.isInfoEnabled()) {
|
|
||||||
log.error("insertUserRole fail, param:{}", JSONObject.toJSONString(schisandraAuthUserRole));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// redis存储用户角色与权限信息
|
|
||||||
userInfoPersistence(authUserId);
|
|
||||||
StpUtil.login(authUserId);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 根据第三方用户信息添加用户信息
|
* @description: 根据第三方用户信息添加用户
|
||||||
* @param: [data, type]
|
* @param: [data, type]
|
||||||
* @return: void
|
* @return: void
|
||||||
* @author: landaiqing
|
* @author: landaiqing
|
||||||
@@ -274,39 +231,98 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
public Result insertAuthUserByOauth(AuthUser data, String type) {
|
public Result insertAuthUserByOauth(AuthUser data, String type) {
|
||||||
String uuid = data.getUuid();
|
String uuid = data.getUuid();
|
||||||
AuthToken token = data.getToken();
|
AuthToken token = data.getToken();
|
||||||
SchisandraAuthUser AuthUser = schisandraAuthUserService.selectByUuidAndType(uuid, type);
|
SchisandraSocialUser socialUser = schisandraSocialUserService.selectByUuidAndType(uuid, type);
|
||||||
if (ObjectUtils.isNotEmpty(AuthUser)) {
|
if (ObjectUtils.isNotEmpty(socialUser)) {
|
||||||
Long userId = AuthUser.getId();
|
// 更新用户信息
|
||||||
|
SchisandraSocialUserBO socialUserBO = new SchisandraSocialUserBO();
|
||||||
|
socialUserBO.setAccessToken(token.getAccessToken());
|
||||||
|
socialUserBO.setSource(data.getSource());
|
||||||
|
socialUserBO.setUid(token.getUid());
|
||||||
|
socialUserBO.setOpenId(token.getOpenId());
|
||||||
|
socialUserBO.setCode(token.getCode());
|
||||||
|
socialUserBO.setAccessCode(token.getAccessCode());
|
||||||
|
socialUserBO.setExpireIn(token.getExpireIn());
|
||||||
|
socialUserBO.setIdToken(token.getIdToken());
|
||||||
|
socialUserBO.setMacAlgorithm(token.getMacAlgorithm());
|
||||||
|
socialUserBO.setMacKey(token.getMacKey());
|
||||||
|
socialUserBO.setOauthToken(token.getOauthToken());
|
||||||
|
socialUserBO.setOauthTokenSecret(token.getOauthTokenSecret());
|
||||||
|
socialUserBO.setRefreshToken(token.getRefreshToken());
|
||||||
|
socialUserBO.setId(socialUser.getId());
|
||||||
|
SchisandraSocialUser schisandraSocialUser = SchisandraSocialUserBOConverter.INSTANCE.convertBOToEntity(socialUserBO);
|
||||||
|
int update = schisandraSocialUserService.updateById(schisandraSocialUser);
|
||||||
|
if (update <= 0) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.error("schisandraAuthSocialUserService.update fail, param:{}", JSONObject.toJSONString(schisandraSocialUser));
|
||||||
|
}
|
||||||
|
return Result.fail("Social User update fail");
|
||||||
|
}
|
||||||
|
Long userId = socialUser.getId();
|
||||||
// redis存储用户角色与权限信息
|
// redis存储用户角色与权限信息
|
||||||
userInfoPersistence(userId);
|
userInfoPersistence(userId);
|
||||||
StpUtil.login(userId, SaLoginConfig.setToken(token.getAccessToken()));
|
StpUtil.login(userId, SaLoginConfig.setToken(token.getAccessToken()));
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
} else {
|
} else {
|
||||||
// 插入用户信息表
|
// 插入社会用户信息表
|
||||||
SchisandraAuthUserBO schisandraAuthUserBO = new SchisandraAuthUserBO();
|
SchisandraSocialUserBO socialUserBO = new SchisandraSocialUserBO();
|
||||||
schisandraAuthUserBO.setUuid(data.getUuid());
|
socialUserBO.setAccessToken(token.getAccessToken());
|
||||||
schisandraAuthUserBO.setSource(data.getSource());
|
socialUserBO.setSource(data.getSource());
|
||||||
schisandraAuthUserBO.setAvatar(data.getAvatar());
|
socialUserBO.setUuid(uuid);
|
||||||
schisandraAuthUserBO.setBlog(data.getBlog());
|
socialUserBO.setUid(token.getUid());
|
||||||
schisandraAuthUserBO.setEmail(data.getEmail());
|
socialUserBO.setOpenId(token.getOpenId());
|
||||||
schisandraAuthUserBO.setCompany(data.getCompany());
|
socialUserBO.setCode(token.getCode());
|
||||||
schisandraAuthUserBO.setGender(String.valueOf(data.getGender()));
|
socialUserBO.setAccessCode(token.getAccessCode());
|
||||||
schisandraAuthUserBO.setIntroduce(data.getRemark());
|
socialUserBO.setExpireIn(token.getExpireIn());
|
||||||
schisandraAuthUserBO.setLocation(data.getLocation());
|
socialUserBO.setIdToken(token.getIdToken());
|
||||||
schisandraAuthUserBO.setNickName(data.getNickname());
|
socialUserBO.setMacAlgorithm(token.getMacAlgorithm());
|
||||||
schisandraAuthUserBO.setUserName(data.getUsername());
|
socialUserBO.setMacKey(token.getMacKey());
|
||||||
schisandraAuthUserBO.setStatus(UserStatusEnum.NORMAL.getCode());
|
socialUserBO.setOauthToken(token.getOauthToken());
|
||||||
schisandraAuthUserBO.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
socialUserBO.setOauthTokenSecret(token.getOauthTokenSecret());
|
||||||
SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
|
socialUserBO.setRefreshToken(token.getRefreshToken());
|
||||||
int result = schisandraAuthUserService.insertAuthUserByOauth(schisandraAuthUser);
|
SchisandraSocialUser schisandraSocialUser = SchisandraSocialUserBOConverter.INSTANCE.convertBOToEntity(socialUserBO);
|
||||||
|
int result = schisandraSocialUserService.insertSocialUser(schisandraSocialUser);
|
||||||
if (result <= 0) {
|
if (result <= 0) {
|
||||||
if (log.isInfoEnabled()) {
|
if (log.isInfoEnabled()) {
|
||||||
log.error("insertAuthUserByOauth fail, param:{}", JSONObject.toJSONString(schisandraAuthUser));
|
log.error("insertSocialUser fail, param:{}", JSONObject.toJSONString(schisandraSocialUser));
|
||||||
}
|
}
|
||||||
return Result.fail("insertAuthUserByOauth.insertAuthUserByOauth fail");
|
return Result.fail("insertSocialUser fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 插入用户信息表
|
||||||
|
SchisandraAuthUserBO authUserBO=new SchisandraAuthUserBO();
|
||||||
|
authUserBO.setUserName(data.getUsername());
|
||||||
|
authUserBO.setNickName(data.getNickname());
|
||||||
|
authUserBO.setAvatar(data.getAvatar());
|
||||||
|
authUserBO.setEmail(data.getEmail());
|
||||||
|
authUserBO.setBlog(data.getBlog());
|
||||||
|
authUserBO.setCompany(data.getCompany());
|
||||||
|
authUserBO.setGender(String.valueOf(data.getGender()));
|
||||||
|
authUserBO.setLocation(data.getLocation());
|
||||||
|
authUserBO.setIntroduce(data.getRemark());
|
||||||
|
SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(authUserBO);
|
||||||
|
int insertAuthUser = schisandraAuthUserService.insertAuthUserByOauth(schisandraAuthUser);
|
||||||
|
if (insertAuthUser <= 0) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.error("insertAuthUser fail, param:{}", JSONObject.toJSONString(schisandraAuthUser));
|
||||||
|
}
|
||||||
|
return Result.fail("insertAuthUser fail");
|
||||||
|
}
|
||||||
Long authUserId = schisandraAuthUser.getId();
|
Long authUserId = schisandraAuthUser.getId();
|
||||||
|
Long socialUserId = schisandraSocialUser.getId();
|
||||||
|
|
||||||
|
// 建立社会用户与用户信息映射
|
||||||
|
SchisandraSocialUserAuthBO socialUserAuthBO = new SchisandraSocialUserAuthBO();
|
||||||
|
socialUserAuthBO.setUserId(authUserId);
|
||||||
|
socialUserAuthBO.setSocialUserId(socialUserId);
|
||||||
|
SchisandraSocialUserAuth schisandraSocialUserAuth = SchisandraSocialUserAuthBOConverter.INSTANCE.convertBOToEntity(socialUserAuthBO);
|
||||||
|
int insertMapper = schisandraSocialUserAuthService.insert(schisandraSocialUserAuth);
|
||||||
|
if (insertMapper <= 0) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.error("insertAuthUserMapper fail, param:{}", JSONObject.toJSONString(schisandraSocialUserAuth));
|
||||||
|
}
|
||||||
|
return Result.fail("insertAuthUserMapper fail");
|
||||||
|
}
|
||||||
|
|
||||||
// 建立用户与角色映射关系
|
// 建立用户与角色映射关系
|
||||||
SchisandraAuthUserRoleBO schisandraAuthUserRoleBO = new SchisandraAuthUserRoleBO();
|
SchisandraAuthUserRoleBO schisandraAuthUserRoleBO = new SchisandraAuthUserRoleBO();
|
||||||
schisandraAuthUserRoleBO.setUserId(authUserId);
|
schisandraAuthUserRoleBO.setUserId(authUserId);
|
||||||
|
@@ -0,0 +1,48 @@
|
|||||||
|
package com.schisandra.auth.domain.service.impl;
|
||||||
|
|
||||||
|
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
|
||||||
|
import com.schisandra.auth.domain.convert.SchisandraSocialUserAuthBOConverter;
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserAuthBO;
|
||||||
|
import com.schisandra.auth.domain.service.SchisandraSocialUserAuthDomainService;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth;
|
||||||
|
import com.schisandra.auth.infra.basic.service.SchisandraSocialUserAuthService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领域service实现了
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SchisandraSocialUserAuthDomainServiceImpl implements SchisandraSocialUserAuthDomainService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraSocialUserAuthService schisandraSocialUserAuthService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean add(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO) {
|
||||||
|
SchisandraSocialUserAuth schisandraSocialUserAuth = SchisandraSocialUserAuthBOConverter.INSTANCE.convertBOToEntity(schisandraSocialUserAuthBO);
|
||||||
|
schisandraSocialUserAuth.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||||
|
return schisandraSocialUserAuthService.insert(schisandraSocialUserAuth) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean update(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO) {
|
||||||
|
SchisandraSocialUserAuth schisandraSocialUserAuth = SchisandraSocialUserAuthBOConverter.INSTANCE.convertBOToEntity(schisandraSocialUserAuthBO);
|
||||||
|
return schisandraSocialUserAuthService.update(schisandraSocialUserAuth) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean delete(SchisandraSocialUserAuthBO schisandraSocialUserAuthBO) {
|
||||||
|
SchisandraSocialUserAuth schisandraSocialUserAuth = new SchisandraSocialUserAuth();
|
||||||
|
schisandraSocialUserAuth.setId(schisandraSocialUserAuthBO.getId());
|
||||||
|
schisandraSocialUserAuth.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
|
||||||
|
return schisandraSocialUserAuthService.update(schisandraSocialUserAuth) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
package com.schisandra.auth.domain.service.impl;
|
||||||
|
|
||||||
|
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
|
||||||
|
import com.schisandra.auth.domain.convert.SchisandraSocialUserBOConverter;
|
||||||
|
import com.schisandra.auth.domain.bo.SchisandraSocialUserBO;
|
||||||
|
import com.schisandra.auth.domain.service.SchisandraSocialUserDomainService;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUser;
|
||||||
|
import com.schisandra.auth.infra.basic.service.SchisandraSocialUserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领域service实现了
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SchisandraSocialUserDomainServiceImpl implements SchisandraSocialUserDomainService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraSocialUserService schisandraSocialUserService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean add(SchisandraSocialUserBO schisandraSocialUserBO) {
|
||||||
|
SchisandraSocialUser schisandraSocialUser = SchisandraSocialUserBOConverter.INSTANCE.convertBOToEntity(schisandraSocialUserBO);
|
||||||
|
schisandraSocialUser.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||||
|
return schisandraSocialUserService.insert(schisandraSocialUser) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean update(SchisandraSocialUserBO schisandraSocialUserBO) {
|
||||||
|
SchisandraSocialUser schisandraSocialUser = SchisandraSocialUserBOConverter.INSTANCE.convertBOToEntity(schisandraSocialUserBO);
|
||||||
|
return schisandraSocialUserService.update(schisandraSocialUser) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean delete(SchisandraSocialUserBO schisandraSocialUserBO) {
|
||||||
|
SchisandraSocialUser schisandraSocialUser = new SchisandraSocialUser();
|
||||||
|
schisandraSocialUser.setId(schisandraSocialUserBO.getId());
|
||||||
|
schisandraSocialUser.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
|
||||||
|
return schisandraSocialUserService.update(schisandraSocialUser) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.dao;
|
||||||
|
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表数据库访问层
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface SchisandraSocialUserAuthDao extends BaseMapper<SchisandraSocialUserAuth> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,17 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.dao;
|
||||||
|
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUser;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表数据库访问层
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface SchisandraSocialUserDao extends BaseMapper<SchisandraSocialUser> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,173 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体类
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table("schisandra_social_user")
|
||||||
|
public class SchisandraSocialUser implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Id(value = "id", keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方系统的唯一ID
|
||||||
|
*/
|
||||||
|
@Column("uuid")
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户来源
|
||||||
|
*/
|
||||||
|
@Column("source")
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的授权令牌
|
||||||
|
*/
|
||||||
|
@Column("access_token")
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的授权令牌的有效期
|
||||||
|
*/
|
||||||
|
@Column("expire_in")
|
||||||
|
private Integer expireIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新令牌
|
||||||
|
*/
|
||||||
|
@Column("refresh_token")
|
||||||
|
private String refreshToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 open id
|
||||||
|
*/
|
||||||
|
@Column("open_id")
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 ID
|
||||||
|
*/
|
||||||
|
@Column("uid")
|
||||||
|
private String uid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个别平台的授权信息
|
||||||
|
*/
|
||||||
|
@Column("access_code")
|
||||||
|
private String accessCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户的 union id
|
||||||
|
*/
|
||||||
|
@Column("union_id")
|
||||||
|
private String unionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方用户授予的权限
|
||||||
|
*/
|
||||||
|
@Column("scope")
|
||||||
|
private String scope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个别平台的授权信息
|
||||||
|
*/
|
||||||
|
@Column("token_type")
|
||||||
|
private String tokenType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id token
|
||||||
|
*/
|
||||||
|
@Column("id_token")
|
||||||
|
private String idToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小米平台用户的附带属性
|
||||||
|
*/
|
||||||
|
@Column("mac_algorithm")
|
||||||
|
private String macAlgorithm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小米平台用户的附带属性
|
||||||
|
*/
|
||||||
|
@Column("mac_key")
|
||||||
|
private String macKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的授权code
|
||||||
|
*/
|
||||||
|
@Column("code")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Twitter平台用户的附带属性
|
||||||
|
*/
|
||||||
|
@Column("oauth_token")
|
||||||
|
private String oauthToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Twitter平台用户的附带属性
|
||||||
|
*/
|
||||||
|
@Column("oauth_token_secret")
|
||||||
|
private String oauthTokenSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@Column("status")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Column("ext_json")
|
||||||
|
private String extJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
@Column("created_by")
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column("created_time")
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
@Column("update_by")
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@Column("update_time")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Column(value = "is_deleted",isLogicDelete = true)
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,71 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体类
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table("schisandra_social_user_auth")
|
||||||
|
public class SchisandraSocialUserAuth implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Id(value = "id", keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Column("user_id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Column("social_user_id")
|
||||||
|
private Long socialUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
@Column("created_by")
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column("created_time")
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
@Column("update_by")
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@Column("update_time")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Column("is_deleted")
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -53,5 +53,5 @@ public interface SchisandraAuthUserService {
|
|||||||
|
|
||||||
boolean updateUserPasswordByPhone(SchisandraAuthUser schisandraAuthUser);
|
boolean updateUserPasswordByPhone(SchisandraAuthUser schisandraAuthUser);
|
||||||
|
|
||||||
SchisandraAuthUser selectByUuidAndType(String uuid, String type);
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,46 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.service;
|
||||||
|
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表服务接口
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
public interface SchisandraSocialUserAuthService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
SchisandraSocialUserAuth queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUserAuth 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
int insert(SchisandraSocialUserAuth schisandraSocialUserAuth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUserAuth 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
int update(SchisandraSocialUserAuth schisandraSocialUserAuth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean deleteById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,51 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.service;
|
||||||
|
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表服务接口
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
public interface SchisandraSocialUserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
SchisandraSocialUser queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUser 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
int insert(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUser 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
int update(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean deleteById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
SchisandraSocialUser selectByUuidAndType(String uuid, String type);
|
||||||
|
|
||||||
|
int updateById(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
|
||||||
|
int insertSocialUser(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
}
|
@@ -54,7 +54,7 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
|
|||||||
@Override
|
@Override
|
||||||
public Boolean insert(SchisandraAuthUser schisandraAuthUser) {
|
public Boolean insert(SchisandraAuthUser schisandraAuthUser) {
|
||||||
|
|
||||||
return this.schisandraAuthUserDao.insert(schisandraAuthUser,true) > 0;
|
return this.schisandraAuthUserDao.insert(schisandraAuthUser, true) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +82,7 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insertAuthUserByOauth(SchisandraAuthUser schisandraAuthUser) {
|
public int insertAuthUserByOauth(SchisandraAuthUser schisandraAuthUser) {
|
||||||
return schisandraAuthUserDao.insert(schisandraAuthUser);
|
return schisandraAuthUserDao.insertSelective(schisandraAuthUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -94,10 +94,5 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SchisandraAuthUser selectByUuidAndType(String uuid, String type) {
|
|
||||||
return schisandraAuthUserDao.selectOneByCondition(SchisandraAuthUserTableDef.SCHISANDRA_AUTH_USER.UUID.eq(uuid)
|
|
||||||
.and(SchisandraAuthUserTableDef.SCHISANDRA_AUTH_USER.SOURCE.eq(type)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,67 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.service.impl;
|
||||||
|
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth;
|
||||||
|
import com.schisandra.auth.infra.basic.dao.SchisandraSocialUserAuthDao;
|
||||||
|
import com.schisandra.auth.infra.basic.service.SchisandraSocialUserAuthService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表服务实现类
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:10:08
|
||||||
|
*/
|
||||||
|
@Service("SchisandraSocialUserAuthService")
|
||||||
|
public class SchisandraSocialUserAuthServiceImpl implements SchisandraSocialUserAuthService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraSocialUserAuthDao schisandraSocialUserAuthDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchisandraSocialUserAuth queryById(Long id) {
|
||||||
|
return this.schisandraSocialUserAuthDao.selectOneById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUserAuth 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int insert(SchisandraSocialUserAuth schisandraSocialUserAuth) {
|
||||||
|
return this.schisandraSocialUserAuthDao.insertSelective(schisandraSocialUserAuth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUserAuth 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int update(SchisandraSocialUserAuth schisandraSocialUserAuth) {
|
||||||
|
return this.schisandraSocialUserAuthDao.update(schisandraSocialUserAuth,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean deleteById(Long id) {
|
||||||
|
return this.schisandraSocialUserAuthDao.deleteById(id) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,98 @@
|
|||||||
|
package com.schisandra.auth.infra.basic.service.impl;
|
||||||
|
|
||||||
|
import com.schisandra.auth.infra.basic.dao.SchisandraSocialUserDao;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.SchisandraSocialUser;
|
||||||
|
import com.schisandra.auth.infra.basic.entity.table.SchisandraSocialUserTableDef;
|
||||||
|
import com.schisandra.auth.infra.basic.service.SchisandraSocialUserService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表服务实现类
|
||||||
|
*
|
||||||
|
* @author landaiqing
|
||||||
|
* @since 2024-06-24 11:07:49
|
||||||
|
*/
|
||||||
|
@Service("SchisandraSocialUserService")
|
||||||
|
public class SchisandraSocialUserServiceImpl implements SchisandraSocialUserService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraSocialUserDao schisandraSocialUserDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchisandraSocialUser queryById(Long id) {
|
||||||
|
return this.schisandraSocialUserDao.selectOneById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUser 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int insert(SchisandraSocialUser schisandraSocialUser) {
|
||||||
|
return this.schisandraSocialUserDao.insertSelective(schisandraSocialUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param schisandraSocialUser 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int update(SchisandraSocialUser schisandraSocialUser) {
|
||||||
|
return this.schisandraSocialUserDao.update(schisandraSocialUser, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean deleteById(Long id) {
|
||||||
|
return this.schisandraSocialUserDao.deleteById(id) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 根据uuid和type查询用户
|
||||||
|
* @param: [uuid, type]
|
||||||
|
* @return: com.schisandra.auth.infra.basic.entity.SchisandraSocialUser
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/24 上午11:17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchisandraSocialUser selectByUuidAndType(String uuid, String type) {
|
||||||
|
return schisandraSocialUserDao.selectOneByCondition(SchisandraSocialUserTableDef.SCHISANDRA_SOCIAL_USER.UUID.eq(uuid)
|
||||||
|
.and(SchisandraSocialUserTableDef.SCHISANDRA_SOCIAL_USER.SOURCE.eq(type)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 根据id更新社会用户信息
|
||||||
|
* @param: [schisandraSocialUser]
|
||||||
|
* @return: int
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/24 上午11:23
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int updateById(SchisandraSocialUser schisandraSocialUser) {
|
||||||
|
return schisandraSocialUserDao.update(schisandraSocialUser, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertSocialUser(SchisandraSocialUser schisandraSocialUser) {
|
||||||
|
return schisandraSocialUserDao.insertSelective(schisandraSocialUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.schisandra.auth.infra.basic.dao.SchisandraSocialUserAuthDao">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.schisandra.auth.infra.basic.entity.SchisandraSocialUserAuth">
|
||||||
|
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||||
|
<result column="user_id" jdbcType="BIGINT" property="userId"/>
|
||||||
|
<result column="social_user_id" jdbcType="BIGINT" property="socialUserId"/>
|
||||||
|
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
|
||||||
|
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
|
||||||
|
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||||
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||||
|
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
</mapper>
|
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.schisandra.auth.infra.basic.dao.SchisandraSocialUserDao">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.schisandra.auth.infra.basic.entity.SchisandraSocialUser">
|
||||||
|
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||||
|
<result column="uuid" jdbcType="VARCHAR" property="uuid"/>
|
||||||
|
<result column="source" jdbcType="VARCHAR" property="source"/>
|
||||||
|
<result column="access_token" jdbcType="VARCHAR" property="accessToken"/>
|
||||||
|
<result column="expire_in" jdbcType="INTEGER" property="expireIn"/>
|
||||||
|
<result column="refresh_token" jdbcType="VARCHAR" property="refreshToken"/>
|
||||||
|
<result column="open_id" jdbcType="VARCHAR" property="openId"/>
|
||||||
|
<result column="uid" jdbcType="VARCHAR" property="uid"/>
|
||||||
|
<result column="access_code" jdbcType="VARCHAR" property="accessCode"/>
|
||||||
|
<result column="union_id" jdbcType="VARCHAR" property="unionId"/>
|
||||||
|
<result column="scope" jdbcType="VARCHAR" property="scope"/>
|
||||||
|
<result column="token_type" jdbcType="VARCHAR" property="tokenType"/>
|
||||||
|
<result column="id_token" jdbcType="VARCHAR" property="idToken"/>
|
||||||
|
<result column="mac_algorithm" jdbcType="VARCHAR" property="macAlgorithm"/>
|
||||||
|
<result column="mac_key" jdbcType="VARCHAR" property="macKey"/>
|
||||||
|
<result column="code" jdbcType="VARCHAR" property="code"/>
|
||||||
|
<result column="oauth_token" jdbcType="VARCHAR" property="oauthToken"/>
|
||||||
|
<result column="oauth_token_secret" jdbcType="VARCHAR" property="oauthTokenSecret"/>
|
||||||
|
<result column="status" jdbcType="VARCHAR" property="status"/>
|
||||||
|
<result column="ext_json" jdbcType="VARCHAR" property="extJson"/>
|
||||||
|
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
|
||||||
|
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
|
||||||
|
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||||
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||||
|
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
</mapper>
|
@@ -8,7 +8,7 @@
|
|||||||
# 数据库连接信息
|
# 数据库连接信息
|
||||||
jdbc:
|
jdbc:
|
||||||
dbName: schisandra-cloud-storage
|
dbName: schisandra-cloud-storage
|
||||||
tableName: schisandra_sms_config
|
tableName: schisandra_social_user_auth
|
||||||
url: jdbc:mysql://1.95.0.111:3306/
|
url: jdbc:mysql://1.95.0.111:3306/
|
||||||
username: root
|
username: root
|
||||||
password: LDQ20020618xxx
|
password: LDQ20020618xxx
|
||||||
@@ -22,9 +22,9 @@ params:
|
|||||||
# 作者
|
# 作者
|
||||||
author: landaiqing
|
author: landaiqing
|
||||||
# 模块
|
# 模块
|
||||||
module: system
|
module: auth
|
||||||
# controller 通用前缀
|
# controller 通用前缀
|
||||||
api: /system/sms
|
api: /auth/social
|
||||||
# 生成对象是否移除前缀
|
# 生成对象是否移除前缀
|
||||||
removePre: false
|
removePre: false
|
||||||
# 使用内置函数赋值给变量 FunctionUtils 中替换
|
# 使用内置函数赋值给变量 FunctionUtils 中替换
|
||||||
|
@@ -1,110 +0,0 @@
|
|||||||
package com.schisandra.oss.common.utils;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName AESUtils 一定要选择16位密钥长度,也就是KEY_LENGTH=16*8,36的话就需要修改环境的jar包。
|
|
||||||
* @Description TODO
|
|
||||||
* @Author L
|
|
||||||
* @Date 2024/1/26 17:27
|
|
||||||
*/
|
|
||||||
public class AESUtils {
|
|
||||||
/**
|
|
||||||
* 加密算法AES
|
|
||||||
*/
|
|
||||||
private static final String KEY_ALGORITHM = "AES";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* key的长度,Wrong key size: must be equal to 128, 192 or 256
|
|
||||||
* 传入时需要16、24、36
|
|
||||||
*/
|
|
||||||
private static final int KEY_LENGTH = 16 * 8;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 算法名称/加密模式/数据填充方式
|
|
||||||
* 默认:AES/ECB/PKCS5Padding
|
|
||||||
*/
|
|
||||||
private static final String ALGORITHMS = "AES/ECB/PKCS5Padding";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 后端AES的key,由静态代码块赋值
|
|
||||||
*/
|
|
||||||
public static String key;
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
key = getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取key
|
|
||||||
*/
|
|
||||||
public static String getKey() {
|
|
||||||
int length = KEY_LENGTH / 8;
|
|
||||||
StringBuilder uid = new StringBuilder(length);
|
|
||||||
//产生32位的强随机数
|
|
||||||
Random rd = new SecureRandom();
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
//产生0-2的3位随机数
|
|
||||||
switch (rd.nextInt(3)) {
|
|
||||||
case 0:
|
|
||||||
//0-9的随机数
|
|
||||||
uid.append(rd.nextInt(10));
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
//ASCII在65-90之间为大写,获取大写随机
|
|
||||||
uid.append((char) (rd.nextInt(26) + 65));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
//ASCII在97-122之间为小写,获取小写随机
|
|
||||||
uid.append((char) (rd.nextInt(26) + 97));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uid.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 加密
|
|
||||||
*
|
|
||||||
* @param content 加密的字符串
|
|
||||||
* @param encryptKey key值
|
|
||||||
*/
|
|
||||||
public static String encrypt(String content, String encryptKey) throws Exception {
|
|
||||||
//设置Cipher对象
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), KEY_ALGORITHM));
|
|
||||||
|
|
||||||
//调用doFinal
|
|
||||||
// 转base64
|
|
||||||
return Base64.encodeBase64String(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 解密
|
|
||||||
*
|
|
||||||
* @param encryptStr 解密的字符串
|
|
||||||
* @param decryptKey 解密的key值
|
|
||||||
*/
|
|
||||||
public static String decrypt(String encryptStr, String decryptKey) throws Exception {
|
|
||||||
//base64格式的key字符串转byte
|
|
||||||
byte[] decodeBase64 = Base64.decodeBase64(encryptStr);
|
|
||||||
|
|
||||||
|
|
||||||
//设置Cipher对象
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), KEY_ALGORITHM));
|
|
||||||
//调用doFinal解密
|
|
||||||
return new String(cipher.doFinal(decodeBase64));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,61 +0,0 @@
|
|||||||
package com.schisandra.oss.common.utils;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
public class MD5Util {
|
|
||||||
//十六进制下数字到字符的映射数组
|
|
||||||
private final static String[] hexDigits = {"0", "1", "2", "3", "4",
|
|
||||||
"5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 把inputString加密
|
|
||||||
*/
|
|
||||||
public static String md5(String inputString) {
|
|
||||||
return encodeByMD5(inputString);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 对字符串进行MD5加密
|
|
||||||
*/
|
|
||||||
private static String encodeByMD5(String originString) {
|
|
||||||
if (originString != null) {
|
|
||||||
try {
|
|
||||||
//创建具有指定算法名称的信息摘要
|
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
//使用指定的字节数组对摘要进行最后更新,然后完成摘要计算
|
|
||||||
byte[] results = md.digest(originString.getBytes("utf-8"));
|
|
||||||
//将得到的字节数组变成字符串返回
|
|
||||||
String resultString = byteArrayToHexString(results);
|
|
||||||
return resultString.toUpperCase();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 转换字节数组为十六进制字符串
|
|
||||||
*
|
|
||||||
* @param
|
|
||||||
* @return 十六进制字符串
|
|
||||||
*/
|
|
||||||
private static String byteArrayToHexString(byte[] b) {
|
|
||||||
StringBuffer resultSb = new StringBuffer();
|
|
||||||
for (int i = 0; i < b.length; i++) {
|
|
||||||
resultSb.append(byteToHexString(b[i]));
|
|
||||||
}
|
|
||||||
return resultSb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String byteToHexString(byte b) {
|
|
||||||
int n = b;
|
|
||||||
if (n < 0) {
|
|
||||||
n += 256;
|
|
||||||
}
|
|
||||||
int d1 = n / 16;
|
|
||||||
int d2 = n % 16;
|
|
||||||
return hexDigits[d1] + hexDigits[d2];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@@ -1,85 +0,0 @@
|
|||||||
package com.schisandra.oss.common.utils;
|
|
||||||
|
|
||||||
import cn.hutool.crypto.SecureUtil;
|
|
||||||
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
|
||||||
import cn.hutool.crypto.asymmetric.KeyType;
|
|
||||||
import cn.hutool.crypto.asymmetric.RSA;
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName RSAUtils
|
|
||||||
* @Description TODO
|
|
||||||
* @Author L
|
|
||||||
* @Date 2024/1/26 17:28
|
|
||||||
*/
|
|
||||||
public class RSAUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 公钥加密(解密就要用到对应的私钥)
|
|
||||||
*
|
|
||||||
* @param msg 明文信息
|
|
||||||
* @param pubKey 公钥,用来加密明文
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String encryptByPublic(String msg, String pubKey) {
|
|
||||||
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), null, pubKey);
|
|
||||||
return rsa.encryptBase64(msg, KeyType.PublicKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 私钥解密
|
|
||||||
*
|
|
||||||
* @param encryptMsg 公钥加密的密文
|
|
||||||
* @param priKey 私钥,用来解密密文
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String decryptByPrivate(String encryptMsg, String priKey) {
|
|
||||||
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), priKey, null);
|
|
||||||
return rsa.decryptStr(encryptMsg, KeyType.PrivateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 私钥加密(解密就要用到对应的公钥)
|
|
||||||
*
|
|
||||||
* @param msg 明文信息
|
|
||||||
* @param priKey 私钥,用来加密明文
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String encryptByPrivate(String msg, String priKey) {
|
|
||||||
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), priKey, null);
|
|
||||||
return rsa.encryptBase64(msg, KeyType.PrivateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 公钥解密
|
|
||||||
*
|
|
||||||
* @param encryptMsg 密文
|
|
||||||
* @param pubKey 公钥,用来解密
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String decryptByPublic(String encryptMsg, String pubKey) {
|
|
||||||
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), null, pubKey);
|
|
||||||
return rsa.decryptStr(encryptMsg, KeyType.PublicKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取公私钥集合
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static HashMap<String,String> getPriKeyAndPubKey() {
|
|
||||||
KeyPair pair = SecureUtil.generateKeyPair("RSA");
|
|
||||||
String privateKey = Base64.encodeBase64String(pair.getPrivate().getEncoded());
|
|
||||||
String publicKey = Base64.encodeBase64String(pair.getPublic().getEncoded());
|
|
||||||
HashMap<String,String> keys = new HashMap<>();
|
|
||||||
keys.put("privateKey",privateKey);
|
|
||||||
keys.put("publicKey",publicKey);
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -1,110 +0,0 @@
|
|||||||
package com.schisandra.system.common.utils;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName AESUtils 一定要选择16位密钥长度,也就是KEY_LENGTH=16*8,36的话就需要修改环境的jar包。
|
|
||||||
* @Description TODO
|
|
||||||
* @Author L
|
|
||||||
* @Date 2024/1/26 17:27
|
|
||||||
*/
|
|
||||||
public class AESUtils {
|
|
||||||
/**
|
|
||||||
* 加密算法AES
|
|
||||||
*/
|
|
||||||
private static final String KEY_ALGORITHM = "AES";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* key的长度,Wrong key size: must be equal to 128, 192 or 256
|
|
||||||
* 传入时需要16、24、36
|
|
||||||
*/
|
|
||||||
private static final int KEY_LENGTH = 16 * 8;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 算法名称/加密模式/数据填充方式
|
|
||||||
* 默认:AES/ECB/PKCS5Padding
|
|
||||||
*/
|
|
||||||
private static final String ALGORITHMS = "AES/ECB/PKCS5Padding";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 后端AES的key,由静态代码块赋值
|
|
||||||
*/
|
|
||||||
public static String key;
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
key = getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取key
|
|
||||||
*/
|
|
||||||
public static String getKey() {
|
|
||||||
int length = KEY_LENGTH / 8;
|
|
||||||
StringBuilder uid = new StringBuilder(length);
|
|
||||||
//产生32位的强随机数
|
|
||||||
Random rd = new SecureRandom();
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
//产生0-2的3位随机数
|
|
||||||
switch (rd.nextInt(3)) {
|
|
||||||
case 0:
|
|
||||||
//0-9的随机数
|
|
||||||
uid.append(rd.nextInt(10));
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
//ASCII在65-90之间为大写,获取大写随机
|
|
||||||
uid.append((char) (rd.nextInt(26) + 65));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
//ASCII在97-122之间为小写,获取小写随机
|
|
||||||
uid.append((char) (rd.nextInt(26) + 97));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uid.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 加密
|
|
||||||
*
|
|
||||||
* @param content 加密的字符串
|
|
||||||
* @param encryptKey key值
|
|
||||||
*/
|
|
||||||
public static String encrypt(String content, String encryptKey) throws Exception {
|
|
||||||
//设置Cipher对象
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), KEY_ALGORITHM));
|
|
||||||
|
|
||||||
//调用doFinal
|
|
||||||
// 转base64
|
|
||||||
return Base64.encodeBase64String(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 解密
|
|
||||||
*
|
|
||||||
* @param encryptStr 解密的字符串
|
|
||||||
* @param decryptKey 解密的key值
|
|
||||||
*/
|
|
||||||
public static String decrypt(String encryptStr, String decryptKey) throws Exception {
|
|
||||||
//base64格式的key字符串转byte
|
|
||||||
byte[] decodeBase64 = Base64.decodeBase64(encryptStr);
|
|
||||||
|
|
||||||
|
|
||||||
//设置Cipher对象
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), KEY_ALGORITHM));
|
|
||||||
//调用doFinal解密
|
|
||||||
return new String(cipher.doFinal(decodeBase64));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,61 +0,0 @@
|
|||||||
package com.schisandra.system.common.utils;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
public class MD5Util {
|
|
||||||
//十六进制下数字到字符的映射数组
|
|
||||||
private final static String[] hexDigits = {"0", "1", "2", "3", "4",
|
|
||||||
"5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 把inputString加密
|
|
||||||
*/
|
|
||||||
public static String md5(String inputString) {
|
|
||||||
return encodeByMD5(inputString);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 对字符串进行MD5加密
|
|
||||||
*/
|
|
||||||
private static String encodeByMD5(String originString) {
|
|
||||||
if (originString != null) {
|
|
||||||
try {
|
|
||||||
//创建具有指定算法名称的信息摘要
|
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
//使用指定的字节数组对摘要进行最后更新,然后完成摘要计算
|
|
||||||
byte[] results = md.digest(originString.getBytes("utf-8"));
|
|
||||||
//将得到的字节数组变成字符串返回
|
|
||||||
String resultString = byteArrayToHexString(results);
|
|
||||||
return resultString.toUpperCase();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 转换字节数组为十六进制字符串
|
|
||||||
*
|
|
||||||
* @param
|
|
||||||
* @return 十六进制字符串
|
|
||||||
*/
|
|
||||||
private static String byteArrayToHexString(byte[] b) {
|
|
||||||
StringBuffer resultSb = new StringBuffer();
|
|
||||||
for (int i = 0; i < b.length; i++) {
|
|
||||||
resultSb.append(byteToHexString(b[i]));
|
|
||||||
}
|
|
||||||
return resultSb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String byteToHexString(byte b) {
|
|
||||||
int n = b;
|
|
||||||
if (n < 0) {
|
|
||||||
n += 256;
|
|
||||||
}
|
|
||||||
int d1 = n / 16;
|
|
||||||
int d2 = n % 16;
|
|
||||||
return hexDigits[d1] + hexDigits[d2];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@@ -1,172 +0,0 @@
|
|||||||
package com.schisandra.system.common.utils;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.security.Key;
|
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.KeyPairGenerator;
|
|
||||||
import java.security.interfaces.RSAPrivateKey;
|
|
||||||
import java.security.interfaces.RSAPublicKey;
|
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName RSAUtils
|
|
||||||
* @Description TODO
|
|
||||||
* @Author L
|
|
||||||
* @Date 2024/1/26 17:28
|
|
||||||
*/
|
|
||||||
public class RSAUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加密算法RSA
|
|
||||||
*/
|
|
||||||
private static final String KEY_ALGORITHM = "RSA";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 算法名称/加密模式/数据填充方式
|
|
||||||
* 默认:RSA/ECB/PKCS1Padding
|
|
||||||
*/
|
|
||||||
private static final String ALGORITHMS = "RSA/ECB/PKCS1Padding";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA最大加密明文大小
|
|
||||||
*/
|
|
||||||
private static final int MAX_ENCRYPT_BLOCK = 245;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA最大解密密文大小
|
|
||||||
*/
|
|
||||||
private static final int MAX_DECRYPT_BLOCK = 256;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA 位数 如果采用2048 上面最大加密和最大解密则须填写: 245 256
|
|
||||||
*/
|
|
||||||
private static final int INITIALIZE_LENGTH = 2048;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 后端RSA的密钥对(公钥和私钥)Map,由静态代码块赋值
|
|
||||||
*/
|
|
||||||
private static final Map<String, String> map = new LinkedHashMap<>(2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成密钥对(公钥和私钥)
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static Map<String,String> genKeyPair() throws Exception {
|
|
||||||
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
|
|
||||||
keyPairGen.initialize(INITIALIZE_LENGTH);
|
|
||||||
KeyPair keyPair = keyPairGen.generateKeyPair();
|
|
||||||
// 获取公钥
|
|
||||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
|
||||||
// 获取私钥
|
|
||||||
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
|
|
||||||
// 得到公钥字符串
|
|
||||||
String publicKeyString = Base64.encodeBase64String(publicKey.getEncoded());
|
|
||||||
// 得到私钥字符串
|
|
||||||
String privateKeyString = Base64.encodeBase64String((privateKey.getEncoded()));
|
|
||||||
map.put("publicKey",publicKeyString);
|
|
||||||
map.put("privateKey",privateKeyString);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
public static String getPrivateKey(){
|
|
||||||
return map.get("privateKey");
|
|
||||||
}
|
|
||||||
public static String getPublicKey(){
|
|
||||||
return map.get("publicKey");
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* RSA私钥解密
|
|
||||||
* @param data BASE64编码过的密文
|
|
||||||
* @param privateKey 私钥(BASE64编码)
|
|
||||||
* @return utf-8编码的明文
|
|
||||||
*/
|
|
||||||
public static byte[] decryptByPrivateKey(byte[] data, String privateKey) throws Exception {
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateK);
|
|
||||||
|
|
||||||
//分段进行解密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA公钥加密
|
|
||||||
* @param data BASE64编码过的密文
|
|
||||||
* @param publicKey 公钥(BASE64编码)
|
|
||||||
* @return utf-8编码的明文
|
|
||||||
*/
|
|
||||||
public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception {
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicK);
|
|
||||||
//分段进行加密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA公钥解密
|
|
||||||
* @param data BASE64编码过的密文
|
|
||||||
* @param publicKey RSA公钥
|
|
||||||
* @return utf-8编码的明文
|
|
||||||
*/
|
|
||||||
public static byte[] pubKeyDec(byte[] data, String publicKey) throws Exception {
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateK);
|
|
||||||
|
|
||||||
//分段进行解密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RSA私钥加密
|
|
||||||
* @param data 待加密的明文
|
|
||||||
* @param privateKey RSA私钥
|
|
||||||
* @return 经BASE64编码后的密文
|
|
||||||
*/
|
|
||||||
public static byte[] privKeyEnc(byte[] data, String privateKey) throws Exception {
|
|
||||||
|
|
||||||
//base64格式的key字符串转Key对象
|
|
||||||
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
|
|
||||||
Cipher cipher = Cipher.getInstance(ALGORITHMS);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicK);
|
|
||||||
|
|
||||||
//分段进行加密操作
|
|
||||||
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分段进行加密、解密操作
|
|
||||||
*/
|
|
||||||
private static byte[] encryptAndDecryptOfSubsection(byte[] data, Cipher cipher, int encryptBlock) throws Exception {
|
|
||||||
int inputLen = data.length;
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
int offSet = 0;
|
|
||||||
byte[] cache;
|
|
||||||
int i = 0;
|
|
||||||
// 对数据分段加密
|
|
||||||
while (inputLen - offSet > 0) {
|
|
||||||
if (inputLen - offSet > encryptBlock) {
|
|
||||||
cache = cipher.doFinal(data, offSet, encryptBlock);
|
|
||||||
} else {
|
|
||||||
cache = cipher.doFinal(data, offSet, inputLen - offSet);
|
|
||||||
}
|
|
||||||
out.write(cache, 0, cache.length);
|
|
||||||
i++;
|
|
||||||
offSet = i * encryptBlock;
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
return out.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -60,11 +60,11 @@ public class CallBackController {
|
|||||||
@RequestParam("timestamp") String timestamp,
|
@RequestParam("timestamp") String timestamp,
|
||||||
@RequestParam("nonce") String nonce,
|
@RequestParam("nonce") String nonce,
|
||||||
@RequestParam(value = "msg_signature", required = false) String msgSignature) {
|
@RequestParam(value = "msg_signature", required = false) String msgSignature) {
|
||||||
// log.info("接收到微信消息:requestBody:{}", requestBody);
|
log.info("接收到微信消息:requestBody:{}", requestBody);
|
||||||
Map<String, String> messageMap = MessageUtil.parseXml(requestBody);
|
Map<String, String> messageMap = MessageUtil.parseXml(requestBody);
|
||||||
String msgType = messageMap.get("MsgType");
|
String msgType = messageMap.get("MsgType");
|
||||||
String event = messageMap.get("Event") == null ? "" : messageMap.get("Event");
|
String event = messageMap.get("Event") == null ? "" : messageMap.get("Event");
|
||||||
// log.info("msgType:{},event:{}", msgType, event);
|
log.info("msgType:{},event:{}", msgType, event);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(msgType);
|
sb.append(msgType);
|
||||||
@@ -78,7 +78,7 @@ public class CallBackController {
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
String replyContent = weChatMsgHandler.dealMsg(messageMap);
|
String replyContent = weChatMsgHandler.dealMsg(messageMap);
|
||||||
// log.info("replyContent:{}", replyContent);
|
log.info("replyContent:{}", replyContent);
|
||||||
return replyContent;
|
return replyContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package com.schisandra.wechat.handler;
|
package com.schisandra.wechat.handler;
|
||||||
|
|
||||||
import com.schisandra.wechat.redis.RedisUtil;
|
import com.schisandra.wechat.redis.RedisUtil;
|
||||||
import com.schisandra.wechat.rpc.AuthRpc;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -22,9 +21,6 @@ public class ReceiveTextMsgHandler implements WeChatMsgHandler {
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private AuthRpc authRpc;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WeChatMsgTypeEnum getMsgType() {
|
public WeChatMsgTypeEnum getMsgType() {
|
||||||
return WeChatMsgTypeEnum.TEXT_MSG;
|
return WeChatMsgTypeEnum.TEXT_MSG;
|
||||||
@@ -53,29 +49,6 @@ public class ReceiveTextMsgHandler implements WeChatMsgHandler {
|
|||||||
"</xml>";
|
"</xml>";
|
||||||
|
|
||||||
return replyContent;
|
return replyContent;
|
||||||
}else if (LOGIN_KEY_WORD.equals(content)) {
|
|
||||||
Boolean result = authRpc.wechatLogin(toUserName);
|
|
||||||
if (result) {
|
|
||||||
String replyContent = "<xml>\n" +
|
|
||||||
" <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
|
|
||||||
" <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
|
|
||||||
" <CreateTime>12345678</CreateTime>\n" +
|
|
||||||
" <MsgType><![CDATA[text]]></MsgType>\n" +
|
|
||||||
" <Content><![CDATA[" + "登录成功" + "]]></Content>\n" +
|
|
||||||
"</xml>";
|
|
||||||
return replyContent;
|
|
||||||
} else {
|
|
||||||
String replyContent = "<xml>\n" +
|
|
||||||
" <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
|
|
||||||
" <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
|
|
||||||
" <CreateTime>12345678</CreateTime>\n" +
|
|
||||||
" <MsgType><![CDATA[text]]></MsgType>\n" +
|
|
||||||
" <Content><![CDATA[" + "登录失败" + "]]></Content>\n" +
|
|
||||||
"</xml>";
|
|
||||||
return replyContent;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@@ -1,31 +0,0 @@
|
|||||||
package com.schisandra.wechat.rpc;
|
|
||||||
|
|
||||||
import com.schisandra.auth.api.SchisandraAuthFeignService;
|
|
||||||
import com.schisandra.auth.entity.Result;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Classname AuthRpc
|
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
|
||||||
* @BelongsPackage: com.schisandra.wechat.rpc
|
|
||||||
* @Author: landaiqing
|
|
||||||
* @CreateTime: 2024-06-20 22:59
|
|
||||||
* @Description: TODO
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class AuthRpc {
|
|
||||||
@Resource
|
|
||||||
private SchisandraAuthFeignService schisandraAuthFeignService;
|
|
||||||
|
|
||||||
public Boolean wechatLogin(String openId) {
|
|
||||||
Result result = schisandraAuthFeignService.wechatLogin(openId);
|
|
||||||
if (result.getSuccess()) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user