医生微信登录接口

master
heminjian502 2 years ago
parent 6c2e378717
commit 6be23a4a1e

@ -125,6 +125,12 @@
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.3</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -5,10 +5,13 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Base64; import java.util.*;
import java.util.Objects;
import java.util.UUID;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -272,4 +275,27 @@ public class FileUploadUtils
return null; return null;
} }
} }
public static String code(String content,String path) {
String picPath = "";
try {
String codeName = UUID.randomUUID().toString();// 二维码的图片名
String imageType = "jpg";// 图片类型
picPath = codeName + "." + imageType;
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 400, 400, hints);
File file1 = new File(path, picPath);
MatrixToImageWriter.writeToFile(bitMatrix, imageType, file1);
} catch (WriterException e) {
logger.error("code WriterException:", e);
e.printStackTrace();
} catch (IOException e) {
logger.error("code IOException:", e);
e.printStackTrace();
}
return picPath;
}
} }

@ -0,0 +1,43 @@
package com.ruoyi.common.utils.file;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.google.zxing.common.BitMatrix;
/**
*
*
* @author 18316
*
*/
public class MatrixToImageWriter {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private MatrixToImageWriter() {
}
public static BufferedImage toBufferedImage(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
}
}
return image;
}
public static void writeToFile(BitMatrix matrix, String format, File file) throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, file)) {
throw new IOException("Could not write an image of format " + format + " to " + file);
}
}
}

@ -2,6 +2,7 @@ package com.ruoyi.framework.web.service;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.UserStatus; import com.ruoyi.common.enums.UserStatus;
import com.ruoyi.common.utils.*; import com.ruoyi.common.utils.*;
@ -34,6 +35,7 @@ import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -204,6 +206,13 @@ public class SysLoginService
tDoctor.setUserId(sysUser.getUserId()); tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.insertTDoctor(tDoctor); tDoctorMapper.insertTDoctor(tDoctor);
tDoctor.setIdentifier("10000000" + tDoctor.getId()); tDoctor.setIdentifier("10000000" + tDoctor.getId());
Map map = new HashMap();
map.put("id", tDoctor.getId());
map.put("from", "yinuo");
String content = JSONObject.toJSONString(map);
String qrCode = FileUploadUtils.code(content, uploadFilePath);
tDoctor.setQrCode(qrCode);
log.info("update doctor :{}", tDoctor);
tDoctorMapper.updateTDoctor(tDoctor); tDoctorMapper.updateTDoctor(tDoctor);
} }
LoginUser loginUser = new LoginUser(); LoginUser loginUser = new LoginUser();

@ -32,6 +32,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
@Service @Service
@ -183,6 +185,14 @@ public class WechatServiceImpl implements IWechatService {
tDoctor.setUserId(sysUser.getUserId()); tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.insertTDoctor(tDoctor); tDoctorMapper.insertTDoctor(tDoctor);
tDoctor.setIdentifier("10000000" + tDoctor.getId()); tDoctor.setIdentifier("10000000" + tDoctor.getId());
Map map = new HashMap();
map.put("id", tDoctor.getId());
map.put("from", "yinuo");
String content = JSONObject.toJSONString(map);
String qrCode = FileUploadUtils.code(content, uploadFilePath);
tDoctor.setQrCode(qrCode);
logger.info("update doctor :{}", tDoctor);
tDoctorMapper.updateTDoctor(tDoctor); tDoctorMapper.updateTDoctor(tDoctor);
wechatUser.setUserId(tDoctor.getId()); wechatUser.setUserId(tDoctor.getId());

Loading…
Cancel
Save