Compare commits
2 Commits
5463c1e60c
...
58308c741f
Author | SHA1 | Date | |
---|---|---|---|
58308c741f | |||
c67d62c8af |
@ -80,7 +80,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.57</version>
|
||||
<version>1.69</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
|
@ -135,6 +135,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
final CodeSessionData data = gson.fromJson(content, CodeSessionData.class);
|
||||
if (!StringUtils.hasLength(data.getOpenid()) || !StringUtils.hasLength(data.getSessionKey())
|
||||
|| (data.getErrcode() != null && data.getErrcode() != 0)) {
|
||||
System.out.println(content);
|
||||
throw BizException.create(1101, "换取session失败");
|
||||
}
|
||||
return data;
|
||||
|
@ -13,7 +13,7 @@ create table userinfo
|
||||
first_login_time datetime default current_timestamp,
|
||||
update_time datetime null on update current_timestamp,
|
||||
status tinyint(2) default 1
|
||||
) engine = innodb comment '用户表';
|
||||
) engine = innodb collate = 'utf8mb4_general_ci' comment '用户表';
|
||||
|
||||
create table point
|
||||
(
|
||||
@ -23,7 +23,7 @@ create table point
|
||||
expire_point int(10) null default 0,
|
||||
expire_time datetime null,
|
||||
update_time datetime null on update current_timestamp
|
||||
) engine = innodb comment '积分表';
|
||||
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分表';
|
||||
create table point_record
|
||||
(
|
||||
id bigint(15) primary key auto_increment,
|
||||
@ -31,9 +31,9 @@ create table point_record
|
||||
point int(10) not null,
|
||||
current_total_point int(10) not null,
|
||||
reason varchar(100) not null,
|
||||
valid_time datetime default current_timestamp,
|
||||
valid_time datetime null,
|
||||
expire_time datetime null
|
||||
) engine = innodb comment '积分记录表';
|
||||
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分记录表';
|
||||
|
||||
create table sign_record
|
||||
(
|
||||
@ -41,6 +41,8 @@ create table sign_record
|
||||
uid int(10) not null,
|
||||
point int(10) not null,
|
||||
ip varchar(50) not null,
|
||||
create_time datetime default current_timestamp
|
||||
) engine = innodb collate = 'utf8mb4_general_ci' comment '打卡记录表';
|
||||
create_time datetime default current_timestamp
|
||||
) engine = innodb comment '打卡记录表';
|
||||
|
||||
|
@ -1,10 +1,20 @@
|
||||
package me.xiaoyan.point.api;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import me.xiaoyan.point.api.pojo.dto.WechatUserInfo;
|
||||
import me.xiaoyan.point.api.util.WechatDecryptDataUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.Key;
|
||||
import java.security.Security;
|
||||
|
||||
public class WechatTests {
|
||||
|
||||
|
||||
@ -16,9 +26,11 @@ public class WechatTests {
|
||||
String sessionKey= "091WPNkl23zoha4xbpnl2cev9l4WPNk7";
|
||||
String encryptedData = "3mmRZjsqy3Tpgw78jm7HNB3n6/pb8nX9jS1GgngV4tHGSe+yhKIXy7u7kxXz7nKS5lwNqt+UQCXF3EHHd1PQJowtpYWNhLBjNZcGjEdIi6a5pxntmwmFsjTX+SjPNmq5Th4iKSwSyMjLIByZqJt7N3hB5OyT5YAo54lsJrln8DJoPE1m6kddHcLqnJy+g12QQTP1u3tFvCEostrCpb109Bhe889wAxm55ekPHTQ+JWYCsPy0TsjmyvqZCQZyB+RNtlW/ohCpLe4oCOF0Nz9Id6N+Kj6bXvgDcEMBf3vwMXSnbWHuqJAuLUWwbsspB/2T";
|
||||
String iv = "qfrpHwHjjqPQVlzzxE9D1A==";
|
||||
// sessionKey= "PKX9EeH6y+pzz8qYrga2jQ==";
|
||||
// encryptedData = "SCK0Ik7THl+USkwTRqTQ9BYGe6rWlXosQ8fWA3I3AsFHTCuPnjbsjFooIEZVcS6mq911XeP5BJJBpPU6A1O3aNuC9L7ebXqTMQX83bVBtaDQySvCIlyyq26xhm8AbWWexl5994NJDpKkNml9ilbYia99bF8bXzXvLCksQQkz82EpZTqztzmCrTdFBZOIrJ+lDnl7rSBWJvVVtoagzgSq2Ux59LcJtxCukIUoZ8fz54//Hm4GhrLucO4zPKTi087f77Pd9K9Rz3LLJ79NMQHHQLtZ38Ws79IKoHBZ7xHXbl3O8xPeTBrrWeHbNfNs1CbOyoe0RwXVjs/fMR9451PeLVM5jg4fj3IDyTFjpx5aUzQRaIrSY/BjVFJoxU/viwQC6LsCBOyXl5uV5h+qIPC5suFbmhl5Q56eU07wbOjNxktEIJsIgbrT+GWRZVPba3dUo+6RoZySxCMA16TRKfuTwjXceV3oNueFdTNyw05s9N43OkrLeKcz1dFeNnpA9DHEVngB1J7MY4RkazdKaWzrld1DjxW6+rk01GgtAr3+H88=";
|
||||
// iv = "Ql/m+Ksll5ziCCZj+07J6g==";
|
||||
|
||||
|
||||
sessionKey= "mu1qLLcPuMVfahKOyAdbvQ==";
|
||||
encryptedData = "ld6dARTybGQ2qCBxUBahqsj7SEm5rschi5u+B2c373dwPf/scWDxPcrOevbzyRLIt3e/K5SVHakl992Uq1KsjBSFI+3A6UV3g5mqgoWePt2xwgUwacfpe7XLYw96qTXxGBAoPH306hRkfpo1zjN34tGVhjTj8LIyCH1llbefqlD+deSXvpRgrwhL2GDUAVs++9U3Mz9wSiSImYOUIZuguvSw0SWtqf5SsRDFI9yfGPzB9KubNX8kzRRvV5Aei8pUuhpgeIs9xKlNFVI5syKRQwprYDK9RLO5dq2G0h3CSrNzPfrI62h7vfb/72aUVu+a";
|
||||
iv = "Spu1dAS7ieC/RQ1BYFb0Lw==";
|
||||
|
||||
WechatUserInfo wechatUserInfo = WechatDecryptDataUtil.decryptData(
|
||||
encryptedData,
|
||||
@ -28,4 +40,44 @@ public class WechatTests {
|
||||
);
|
||||
// System.out.println(wechatUserInfo);
|
||||
}
|
||||
//解密手机号
|
||||
private static boolean initialized = false;
|
||||
|
||||
@Test
|
||||
void testAesDecode(){
|
||||
String sessionKey= "mu1qLLcPuMVfahKOyAdbvQ==";
|
||||
String encryptedData = "ld6dARTybGQ2qCBxUBahqsj7SEm5rschi5u+B2c373dwPf/scWDxPcrOevbzyRLIt3e/K5SVHakl992Uq1KsjBSFI+3A6UV3g5mqgoWePt2xwgUwacfpe7XLYw96qTXxGBAoPH306hRkfpo1zjN34tGVhjTj8LIyCH1llbefqlD+deSXvpRgrwhL2GDUAVs++9U3Mz9wSiSImYOUIZuguvSw0SWtqf5SsRDFI9yfGPzB9KubNX8kzRRvV5Aei8pUuhpgeIs9xKlNFVI5syKRQwprYDK9RLO5dq2G0h3CSrNzPfrI62h7vfb/72aUVu+a";
|
||||
String iv = "Spu1dAS7ieC/RQ1BYFb0Lw==";
|
||||
|
||||
byte[] encData = Base64.decodeBase64(encryptedData);
|
||||
byte[] ivData = Base64.decodeBase64(iv);
|
||||
byte[] session = Base64.decodeBase64(sessionKey);
|
||||
String str = decrypt(encData,session,ivData);
|
||||
System.out.println(str);
|
||||
}
|
||||
@SneakyThrows
|
||||
public String decrypt(byte[] encData, byte[] key, byte[] iv) {
|
||||
initialize();
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
|
||||
Key sKeySpec = new SecretKeySpec(key, "AES");
|
||||
|
||||
cipher.init(Cipher.DECRYPT_MODE, sKeySpec, generateIV(iv));// 初始化
|
||||
byte[] result = cipher.doFinal(encData);
|
||||
return new String(result, "UTF-8");
|
||||
}
|
||||
|
||||
|
||||
public static AlgorithmParameters generateIV(byte[] iv) throws Exception {
|
||||
AlgorithmParameters params = AlgorithmParameters.getInstance("AES");
|
||||
params.init(new IvParameterSpec(iv));
|
||||
return params;
|
||||
}
|
||||
|
||||
public static void initialize(){
|
||||
if (initialized){
|
||||
return;
|
||||
}
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user