Merge branch 'refs/heads/master' into 支付优化测试

This commit is contained in:
seesaw
2024-10-23 10:38:51 +08:00
2 changed files with 24 additions and 10 deletions

View File

@ -911,17 +911,17 @@ public class MemberUserServiceImpl implements MemberUserService {
@Override @Override
public String getQRCode() { public String getQRCode() {
Long userId = getLoginUserId(); Long userId = getLoginUserId();
String redisKey = QRCodeWithJWTUtil.QR_PREFIX+userId; // String redisKey = QRCodeWithJWTUtil.QR_PREFIX+userId;
String url = memberUserRedisTemplate.opsForValue().get(redisKey); // String url = memberUserRedisTemplate.opsForValue().get(redisKey);
if(StrUtil.isNotEmpty(url)){ // if(StrUtil.isNotEmpty(url)){
return url; // return url;
} // }
String encode = DigestUtil.md5Hex(userId.toString()+System.currentTimeMillis()); String encode = DigestUtil.md5Hex(userId.toString()+System.currentTimeMillis());
String fileName = "QRCode_" + userId + ".png"; String fileName = "QRCode_" + userId + ".png";
String path = QRCodeWithJWTUtil.BASE_PATH+fileName; String path = QRCodeWithJWTUtil.BASE_PATH+fileName;
QRCodeWithJWTUtil.generateQRCode(encode, 350, 350, path); // 生 String s = QRCodeWithJWTUtil.generateQRCode(encode, 350, 350, path);// 生
memberUserRedisTemplate.opsForValue().set(redisKey,path,180, TimeUnit.SECONDS); // memberUserRedisTemplate.opsForValue().set(redisKey,path,180, TimeUnit.SECONDS);
memberUserRedisTemplate.opsForValue().set(encode,userId.toString(),180, TimeUnit.SECONDS); memberUserRedisTemplate.opsForValue().set(encode,userId.toString(),180, TimeUnit.SECONDS);
return path; return s;
} }
} }

View File

@ -9,9 +9,13 @@ import cn.hutool.json.JSONUtil;
import cn.hutool.jwt.JWTUtil; import cn.hutool.jwt.JWTUtil;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -47,8 +51,18 @@ public class QRCodeWithJWTUtil {
} }
// 生成二维码图片 // 生成二维码图片
public static void generateQRCode(String data, int width, int height, String filePath) { public static String generateQRCode(String data, int width, int height, String filePath) {
QrCodeUtil.generate(data, width, height, new File(filePath)); BufferedImage generate = QrCodeUtil.generate(data, width, height);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(generate, "png", baos);
byte[] imageBytes = baos.toByteArray();
return "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes);
} catch (Exception e) {
e.printStackTrace();
return null;
}
} }
// 验证JWT是否有效和未过期 // 验证JWT是否有效和未过期