Commit 9c2bc2b2 by caiyt

修改二维码尺寸生成逻辑、修复扫码后金额为哦的问题

parent c10e3e67
...@@ -74,7 +74,11 @@ public class ApplicationController { ...@@ -74,7 +74,11 @@ public class ApplicationController {
Integer screenNo = redisJson.getInteger("screenNo"); Integer screenNo = redisJson.getInteger("screenNo");
Machine machine = machineService.selectMachineByCode(machineCode); Machine machine = machineService.selectMachineByCode(machineCode);
Shop shop = shopService.selectShopById(machine.getShopId()); Shop shop = shopService.selectShopById(machine.getShopId());
shop.setDistance(DistanceUtil.getDistanceDesc(Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()), Double.parseDouble(location.getString("lng")), Double.parseDouble(location.getString("lat")))); try {
shop.setDistance(DistanceUtil.getDistanceDesc(Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()), Double.parseDouble(location.getString("lng")), Double.parseDouble(location.getString("lat"))));
} catch (NumberFormatException e) {
shop.setDistance("-1");
}
redisJson.put("shop", shop); redisJson.put("shop", shop);
//推送数据给安卓 //推送数据给安卓
JSONObject jgBody = new JSONObject(); JSONObject jgBody = new JSONObject();
......
...@@ -12,16 +12,13 @@ import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult; ...@@ -12,16 +12,13 @@ import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.service.WxPayService;
import com.github.wxpay.sdk.WXPayUtil; import com.github.wxpay.sdk.WXPayUtil;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.soss.common.core.domain.entity.SysUser; import com.soss.common.core.domain.entity.SysUser;
import com.soss.common.core.domain.model.LoginUser; import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.enums.RefundState; import com.soss.common.enums.RefundState;
import com.soss.common.enums.ShopState; import com.soss.common.enums.ShopState;
import com.soss.common.exception.ServiceException; import com.soss.common.exception.ServiceException;
import com.soss.common.utils.QRCodeUtil;
import com.soss.common.utils.StringUtils; import com.soss.common.utils.StringUtils;
import com.soss.common.utils.ip.IpUtils; import com.soss.common.utils.ip.IpUtils;
import com.soss.common.utils.sign.Base64; import com.soss.common.utils.sign.Base64;
...@@ -57,6 +54,8 @@ import javax.crypto.Cipher; ...@@ -57,6 +54,8 @@ import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -65,6 +64,7 @@ import java.math.BigDecimal; ...@@ -65,6 +64,7 @@ import java.math.BigDecimal;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.List;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
...@@ -390,17 +390,6 @@ public class WeixinServiceImpl { ...@@ -390,17 +390,6 @@ public class WeixinServiceImpl {
//获取商户订单号 //获取商户订单号
String orderNo = notifyMap.get("out_trade_no"); String orderNo = notifyMap.get("out_trade_no");
Order order = new Order();
order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order);
if(orders.isEmpty()){
returnMap.put("return_code", "FAIL");
returnMap.put("return_msg", "没有该订单");
String returnXml = WXPayUtil.mapToXml(returnMap);
return returnXml;
}
order = orders.get(0);
//并校验返回的订单金额是否与商户侧的订单金额一致 //并校验返回的订单金额是否与商户侧的订单金额一致
// if (order1 != null && order1.get() != Long.parseLong(notifyMap.get("total_fee"))) { // if (order1 != null && order1.get() != Long.parseLong(notifyMap.get("total_fee"))) {
// log.error("金额校验失败"); // log.error("金额校验失败");
...@@ -412,11 +401,21 @@ public class WeixinServiceImpl { ...@@ -412,11 +401,21 @@ public class WeixinServiceImpl {
// } // }
//处理订单 //处理订单
if(lock.tryLock()){ if(lock.tryLock()) {
Order order = new Order();
order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order);
if (orders.isEmpty()) {
returnMap.put("return_code", "FAIL");
returnMap.put("return_msg", "没有该订单");
return WXPayUtil.mapToXml(returnMap);
}
order = orders.get(0);
try { try {
//处理重复的通知 //处理重复的通知
//接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。 //接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。
String orderStatus =order.getState(); String orderStatus = order.getState();
log.info("order current status: {}", orderStatus);
if (OrderStatusConstant.Unpaid.equals(orderStatus)) { if (OrderStatusConstant.Unpaid.equals(orderStatus)) {
//更新订单状态 //更新订单状态
order.setPayTime(new Date()); order.setPayTime(new Date());
...@@ -801,20 +800,15 @@ public class WeixinServiceImpl { ...@@ -801,20 +800,15 @@ public class WeixinServiceImpl {
} }
public String generateMiniQr(String content) { public String generateMiniQr(String content) {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
// 解决中文乱码
HashMap<EncodeHintType, Object> hints = new HashMap<>(16);
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
String fileName = System.currentTimeMillis() + ".png"; String fileName = System.currentTimeMillis() + ".png";
try { try {
String[] qrSizeArr = qrSize.split("\\*"); String[] qrSizeArr = qrSize.split("\\*");
int width = Integer.parseInt(qrSizeArr[0]); int width = Integer.parseInt(qrSizeArr[0]);
int height = Integer.parseInt(qrSizeArr[1]); int height = Integer.parseInt(qrSizeArr[1]);
log.info("qr with: {} height: {}", width, height); log.info("qr with: {} height: {}", width, height);
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
bitMatrix = deleteWhite(bitMatrix);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", byteArrayOutputStream); QRCodeUtil.generateQRImage(content, "PNG", byteArrayOutputStream, width, height);
// MatrixToImageWriter.writeToStream(bitMatrix, "PNG", byteArrayOutputStream);
return ossFileService.uploadFile(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), fileName); return ossFileService.uploadFile(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), fileName);
} catch (Exception e) { } catch (Exception e) {
log.error("生成二维码失败:{}", e.getMessage(), e); log.error("生成二维码失败:{}", e.getMessage(), e);
...@@ -823,6 +817,17 @@ public class WeixinServiceImpl { ...@@ -823,6 +817,17 @@ public class WeixinServiceImpl {
} }
/** /**
* 图片放大缩小
*/
public static BufferedImage zoomInImage(BufferedImage originalImage, int width, int height) {
BufferedImage newImage = new BufferedImage(width, height, originalImage.getType());
Graphics g = newImage.getGraphics();
g.drawImage(originalImage, 0, 0, width, height, null);
g.dispose();
return newImage;
}
/**
* 删除白边 * 删除白边
*/ */
private BitMatrix deleteWhite(BitMatrix matrix) { private BitMatrix deleteWhite(BitMatrix matrix) {
......
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