| | |
| | | package org.springblade.modules.qrcode; |
| | | |
| | | import com.google.zxing.WriterException; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.utils.QRCodeUtil; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springblade.modules.system.vo.UserVO; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.Base64; |
| | | |
| | | /** |
| | | * @author zhongrj |
| | |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/qrCode") |
| | | @AllArgsConstructor |
| | | public class QrCodeController { |
| | | |
| | | private final IUserService userService; |
| | | |
| | | /** |
| | | * 二维码生成-字节流 |
| | | * @param securityNumber 保安证编号 |
| | | * @return |
| | | */ |
| | | @GetMapping("/getQrCode") |
| | | public R getQrCode(String content){ |
| | | //获取二维码 |
| | | String qrCode = QRCodeUtil.getBase64QRCode(content); |
| | | return R.data(qrCode); |
| | | public ResponseEntity<byte[]> getQrCode(String securityNumber){ |
| | | // String url = "http://s16s652780.51mypc.cn/securityInfo/securityInfo.html"; |
| | | String url = "http://223.82.109.183:2080/securityInfo.html"; |
| | | if (null!=securityNumber) { |
| | | String content = url + "?securityNumber=" + securityNumber; |
| | | // "&realName=" + one.getRealName() + |
| | | // "&age=" + one.getAge() + |
| | | // "&sex=" + one.getSex() + |
| | | // "&avatar=" + one.getAvatar() + |
| | | // "&deptName=" + one.getDeptName(); |
| | | |
| | | |
| | | ResponseEntity<byte[]> aEntity = null; |
| | | try { |
| | | URLEncoder.encode(content,"utf-8"); |
| | | byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350); |
| | | // Set headers |
| | | final HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.IMAGE_PNG); |
| | | aEntity = new ResponseEntity<byte[]>(qrCodeImage, headers, HttpStatus.CREATED); |
| | | } catch (WriterException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return aEntity; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 二维码生成base64 |
| | | * @param securityNumber 保安证编号 |
| | | * @return |
| | | */ |
| | | @GetMapping("/getQrCodeBase64") |
| | | public String getQrCodeBase64(String securityNumber) throws Exception{ |
| | | // String url = "http://s16s652780.51mypc.cn/securityInfo/securityInfo.html"; |
| | | String url = "http://223.82.109.183:2080/securityInfo.html"; |
| | | if (null!=securityNumber) { |
| | | String encoded = URLEncoder.encode(securityNumber,"UTF-8"); |
| | | |
| | | String content = url + "?securityNumber=" + encoded; |
| | | |
| | | byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350); |
| | | String encode = new BASE64Encoder().encode(qrCodeImage); |
| | | return "data:image/png;base64,"+encode; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据保安员编码查询保安员信息 |
| | | * @param securityNumber |
| | | * @return |
| | | */ |
| | | @GetMapping("/getUserInfo") |
| | | public UserVO getUserInfo(String securityNumber){ |
| | | //根据保安员编码查询保安员信息 |
| | | return userService.getUserInfoBySecurityNumber(securityNumber); |
| | | } |
| | | |
| | | } |