|
@@ -6,6 +6,11 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.google.zxing.BarcodeFormat;
|
|
|
+import com.google.zxing.WriterException;
|
|
|
+import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
|
+import com.google.zxing.common.BitMatrix;
|
|
|
+import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
@@ -33,6 +38,8 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -103,11 +110,29 @@ public class WxLoginService
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- public String pcLoginUrl() {
|
|
|
+ public Map<String,Object> pcLoginUrl(){
|
|
|
String scanCode = ToolsUtils.getCharAndNumr(6);
|
|
|
String key = "SCAN_LOGIN_"+scanCode;
|
|
|
+ String code_url = scanLoginHost+"pc/login/"+scanCode;
|
|
|
+ String urlBase64 = null;
|
|
|
+ try {
|
|
|
+ QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
|
|
+ BitMatrix bitMatrix = qrCodeWriter.encode(code_url, BarcodeFormat.QR_CODE, 120, 120);
|
|
|
+ // 写到输出流
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ MatrixToImageWriter.writeToStream(bitMatrix, "jpg", outputStream);
|
|
|
+ //转换为base64
|
|
|
+ java.util.Base64.Encoder encoder1 = java.util.Base64.getEncoder();
|
|
|
+ urlBase64 = "data:image/jpeg;base64,"
|
|
|
+ + encoder1.encodeToString(outputStream.toByteArray());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
redisCache.setCacheObject(key, -1,30, TimeUnit.SECONDS);//30秒锁定
|
|
|
- return scanLoginHost+"pc/login/"+scanCode;
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("scanCode",scanCode);
|
|
|
+ map.put("urlBase64",urlBase64);
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
/**
|