Compare commits

..

No commits in common. "58308c741f527a04003ff3687c846b3163e1f0d5" and "5463c1e60c6ac8a471f6cdb636bc0539e383eb0b" have entirely different histories.

4 changed files with 8 additions and 63 deletions

View File

@ -80,7 +80,7 @@
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId> <artifactId>bcprov-jdk15on</artifactId>
<version>1.69</version> <version>1.57</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.dev33</groupId> <groupId>cn.dev33</groupId>

View File

@ -135,7 +135,6 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
final CodeSessionData data = gson.fromJson(content, CodeSessionData.class); final CodeSessionData data = gson.fromJson(content, CodeSessionData.class);
if (!StringUtils.hasLength(data.getOpenid()) || !StringUtils.hasLength(data.getSessionKey()) if (!StringUtils.hasLength(data.getOpenid()) || !StringUtils.hasLength(data.getSessionKey())
|| (data.getErrcode() != null && data.getErrcode() != 0)) { || (data.getErrcode() != null && data.getErrcode() != 0)) {
System.out.println(content);
throw BizException.create(1101, "换取session失败"); throw BizException.create(1101, "换取session失败");
} }
return data; return data;

View File

@ -13,7 +13,7 @@ create table userinfo
first_login_time datetime default current_timestamp, first_login_time datetime default current_timestamp,
update_time datetime null on update current_timestamp, update_time datetime null on update current_timestamp,
status tinyint(2) default 1 status tinyint(2) default 1
) engine = innodb collate = 'utf8mb4_general_ci' comment '用户表'; ) engine = innodb comment '用户表';
create table point create table point
( (
@ -23,7 +23,7 @@ create table point
expire_point int(10) null default 0, expire_point int(10) null default 0,
expire_time datetime null, expire_time datetime null,
update_time datetime null on update current_timestamp update_time datetime null on update current_timestamp
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分表'; ) engine = innodb comment '积分表';
create table point_record create table point_record
( (
id bigint(15) primary key auto_increment, id bigint(15) primary key auto_increment,
@ -31,9 +31,9 @@ create table point_record
point int(10) not null, point int(10) not null,
current_total_point int(10) not null, current_total_point int(10) not null,
reason varchar(100) not null, reason varchar(100) not null,
valid_time datetime null, valid_time datetime default current_timestamp,
expire_time datetime null expire_time datetime null
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分记录表'; ) engine = innodb comment '积分记录表';
create table sign_record create table sign_record
( (
@ -41,8 +41,6 @@ create table sign_record
uid int(10) not null, uid int(10) not null,
point int(10) not null, point int(10) not null,
ip varchar(50) 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 create_time datetime default current_timestamp
) engine = innodb comment '打卡记录表'; ) engine = innodb comment '打卡记录表';

View File

@ -1,20 +1,10 @@
package me.xiaoyan.point.api; package me.xiaoyan.point.api;
import lombok.SneakyThrows;
import me.xiaoyan.point.api.pojo.dto.WechatUserInfo; import me.xiaoyan.point.api.pojo.dto.WechatUserInfo;
import me.xiaoyan.point.api.util.WechatDecryptDataUtil; 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.DisplayName;
import org.junit.jupiter.api.Test; 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 { public class WechatTests {
@ -26,11 +16,9 @@ public class WechatTests {
String sessionKey= "091WPNkl23zoha4xbpnl2cev9l4WPNk7"; String sessionKey= "091WPNkl23zoha4xbpnl2cev9l4WPNk7";
String encryptedData = "3mmRZjsqy3Tpgw78jm7HNB3n6/pb8nX9jS1GgngV4tHGSe+yhKIXy7u7kxXz7nKS5lwNqt+UQCXF3EHHd1PQJowtpYWNhLBjNZcGjEdIi6a5pxntmwmFsjTX+SjPNmq5Th4iKSwSyMjLIByZqJt7N3hB5OyT5YAo54lsJrln8DJoPE1m6kddHcLqnJy+g12QQTP1u3tFvCEostrCpb109Bhe889wAxm55ekPHTQ+JWYCsPy0TsjmyvqZCQZyB+RNtlW/ohCpLe4oCOF0Nz9Id6N+Kj6bXvgDcEMBf3vwMXSnbWHuqJAuLUWwbsspB/2T"; String encryptedData = "3mmRZjsqy3Tpgw78jm7HNB3n6/pb8nX9jS1GgngV4tHGSe+yhKIXy7u7kxXz7nKS5lwNqt+UQCXF3EHHd1PQJowtpYWNhLBjNZcGjEdIi6a5pxntmwmFsjTX+SjPNmq5Th4iKSwSyMjLIByZqJt7N3hB5OyT5YAo54lsJrln8DJoPE1m6kddHcLqnJy+g12QQTP1u3tFvCEostrCpb109Bhe889wAxm55ekPHTQ+JWYCsPy0TsjmyvqZCQZyB+RNtlW/ohCpLe4oCOF0Nz9Id6N+Kj6bXvgDcEMBf3vwMXSnbWHuqJAuLUWwbsspB/2T";
String iv = "qfrpHwHjjqPQVlzzxE9D1A=="; String iv = "qfrpHwHjjqPQVlzzxE9D1A==";
// sessionKey= "PKX9EeH6y+pzz8qYrga2jQ==";
// encryptedData = "SCK0Ik7THl+USkwTRqTQ9BYGe6rWlXosQ8fWA3I3AsFHTCuPnjbsjFooIEZVcS6mq911XeP5BJJBpPU6A1O3aNuC9L7ebXqTMQX83bVBtaDQySvCIlyyq26xhm8AbWWexl5994NJDpKkNml9ilbYia99bF8bXzXvLCksQQkz82EpZTqztzmCrTdFBZOIrJ+lDnl7rSBWJvVVtoagzgSq2Ux59LcJtxCukIUoZ8fz54//Hm4GhrLucO4zPKTi087f77Pd9K9Rz3LLJ79NMQHHQLtZ38Ws79IKoHBZ7xHXbl3O8xPeTBrrWeHbNfNs1CbOyoe0RwXVjs/fMR9451PeLVM5jg4fj3IDyTFjpx5aUzQRaIrSY/BjVFJoxU/viwQC6LsCBOyXl5uV5h+qIPC5suFbmhl5Q56eU07wbOjNxktEIJsIgbrT+GWRZVPba3dUo+6RoZySxCMA16TRKfuTwjXceV3oNueFdTNyw05s9N43OkrLeKcz1dFeNnpA9DHEVngB1J7MY4RkazdKaWzrld1DjxW6+rk01GgtAr3+H88=";
sessionKey= "mu1qLLcPuMVfahKOyAdbvQ=="; // iv = "Ql/m+Ksll5ziCCZj+07J6g==";
encryptedData = "ld6dARTybGQ2qCBxUBahqsj7SEm5rschi5u+B2c373dwPf/scWDxPcrOevbzyRLIt3e/K5SVHakl992Uq1KsjBSFI+3A6UV3g5mqgoWePt2xwgUwacfpe7XLYw96qTXxGBAoPH306hRkfpo1zjN34tGVhjTj8LIyCH1llbefqlD+deSXvpRgrwhL2GDUAVs++9U3Mz9wSiSImYOUIZuguvSw0SWtqf5SsRDFI9yfGPzB9KubNX8kzRRvV5Aei8pUuhpgeIs9xKlNFVI5syKRQwprYDK9RLO5dq2G0h3CSrNzPfrI62h7vfb/72aUVu+a";
iv = "Spu1dAS7ieC/RQ1BYFb0Lw==";
WechatUserInfo wechatUserInfo = WechatDecryptDataUtil.decryptData( WechatUserInfo wechatUserInfo = WechatDecryptDataUtil.decryptData(
encryptedData, encryptedData,
@ -40,44 +28,4 @@ public class WechatTests {
); );
// System.out.println(wechatUserInfo); // 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;
}
} }