Commit ca63cdaf authored by 高宇's avatar 高宇

会员码接口

parent 864c7391
package com.emall.flash.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.UnsupportedEncodingException;
public class CyQrCodeUtil {
private static final Logger log = LoggerFactory.getLogger(CyQrCodeUtil.class);
private static final Integer QC_CODE_WIDTH = 235;
private static final Integer QC_CODE_HEIGHT = 235;
public CyQrCodeUtil() {
}
public static BufferedImage qRCodeCommon(String content) throws UnsupportedEncodingException {
Qrcode qrcode = new Qrcode();
qrcode.setQrcodeEncodeMode('B');
qrcode.setQrcodeVersion(15);
qrcode.setQrcodeErrorCorrect('M');
BufferedImage image = new BufferedImage(QC_CODE_WIDTH, QC_CODE_HEIGHT, 1);
Graphics2D gs = image.createGraphics();
gs.setBackground(Color.white);
gs.setColor(Color.black);
gs.clearRect(0, 0, QC_CODE_WIDTH, QC_CODE_HEIGHT);
Object var4 = null;
try {
byte[] codeOut = content.getBytes("utf-8");
boolean[][] code = qrcode.calQrcode(codeOut);
for(int i = 0; i < code.length; ++i) {
for(int j = 0; j < code.length; ++j) {
if (code[j][i]) {
gs.fillRect(j * 3 + 2, i * 3 + 2, 3, 3);
}
}
}
return image;
} catch (Exception var8) {
log.error(var8.getMessage());
throw var8;
}
}
}
This diff is collapsed.
...@@ -57,6 +57,12 @@ ...@@ -57,6 +57,12 @@
<artifactId>geodesy</artifactId> <artifactId>geodesy</artifactId>
<version>1.1.3</version> <version>1.1.3</version>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.8</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.emall.flash.mobile.controller; package com.emall.flash.mobile.controller;
import cn.hutool.core.codec.Base64Encoder;
import com.emall.flash.bean.entity.shop.ShopUser; import com.emall.flash.bean.entity.shop.ShopUser;
import com.emall.flash.bean.entity.system.FileInfo; import com.emall.flash.bean.entity.system.FileInfo;
import com.emall.flash.bean.vo.UserInfo; import com.emall.flash.bean.vo.UserInfo;
...@@ -10,15 +11,21 @@ import com.emall.flash.security.JwtUtil; ...@@ -10,15 +11,21 @@ import com.emall.flash.security.JwtUtil;
import com.emall.flash.service.api.WeixinService; import com.emall.flash.service.api.WeixinService;
import com.emall.flash.service.shop.ShopUserService; import com.emall.flash.service.shop.ShopUserService;
import com.emall.flash.service.system.FileService; import com.emall.flash.service.system.FileService;
import com.emall.flash.utils.CyQrCodeUtil;
import com.emall.flash.utils.MD5; import com.emall.flash.utils.MD5;
import com.emall.flash.utils.StringUtil; import com.emall.flash.utils.StringUtil;
import com.emall.flash.web.controller.BaseController; import com.emall.flash.web.controller.BaseController;
import com.google.protobuf.ServiceException;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.Map; import java.util.Map;
/** /**
...@@ -49,6 +56,11 @@ public class UserController extends BaseController { ...@@ -49,6 +56,11 @@ public class UserController extends BaseController {
} }
return Rets.success(userInfo); return Rets.success(userInfo);
} }
@RequestMapping(value = "/update",method = RequestMethod.POST)
public Object update(ShopUser shopUser){
shopUserService.update(shopUser);
return Rets.success(shopUser);
}
@RequestMapping(value = "/updateUserName/{userName}",method = RequestMethod.POST) @RequestMapping(value = "/updateUserName/{userName}",method = RequestMethod.POST)
public Object updateUserName(@PathVariable("userName") String userName){ public Object updateUserName(@PathVariable("userName") String userName){
ShopUser user = shopUserService.getCurrentUser(); ShopUser user = shopUserService.getCurrentUser();
...@@ -138,4 +150,25 @@ public class UserController extends BaseController { ...@@ -138,4 +150,25 @@ public class UserController extends BaseController {
shopUserService.update(shopUser); shopUserService.update(shopUser);
return Rets.success(shopUser); return Rets.success(shopUser);
} }
// 生成会员二维码
@RequestMapping(value = "/setTenantId",method = RequestMethod.GET)
public Object getTradeScan(String id) throws ServiceException {
String png_base64 = null;
//返回二维码 并且构造支付包web支付对象
ByteArrayOutputStream baOp = new ByteArrayOutputStream();
try {
BufferedImage bufImg = CyQrCodeUtil.qRCodeCommon(id);
// 生成二维码QRCode图片
ImageIO.write(bufImg, "png", baOp);
byte[] bytes = baOp.toByteArray();//转换成字节
/**
* jdk 17 替代方案
*/
png_base64 = Base64Encoder.encode(bytes).trim();
png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n
} catch (Exception e) {
throw new ServiceException("系统错误");
}
return Rets.success(png_base64);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment