提交代码

yy_dev
胡锐 2 years ago
parent ce74870900
commit ef962770cb
  1. 135
      bweb/src/main/java/com/bweb/controller/BsPayQrCodeController.java
  2. 77
      bweb/src/main/java/com/bweb/controller/BsTradeOrderController.java
  3. 4
      cweb/src/main/java/com/cweb/controller/TestController.java
  4. 28
      service/src/main/java/com/hfkj/common/utils/EasyExcelUtil.java
  5. 3
      service/src/main/java/com/hfkj/config/CommonSysConfig.java
  6. 53
      service/src/main/java/com/hfkj/config/TextMessage.java
  7. 358
      service/src/main/java/com/hfkj/config/WeChatQrcodeUtils.java
  8. 51
      service/src/main/java/com/hfkj/config/WxMpConfig.java
  9. 25
      service/src/main/java/com/hfkj/dao/BsPayQrCodeMapper.java
  10. 14
      service/src/main/java/com/hfkj/dao/BsPayQrCodeSqlProvider.java
  11. 16
      service/src/main/java/com/hfkj/entity/BsPayQrCode.java
  12. 70
      service/src/main/java/com/hfkj/entity/BsPayQrCodeExample.java
  13. 2
      service/src/main/java/com/hfkj/service/BsPayQrCodeService.java
  14. 42
      service/src/main/java/com/hfkj/service/impl/BsPayQrCodeServiceImpl.java
  15. 11
      service/src/main/java/com/hfkj/sysenum/PayQrCodeStatusEnum.java
  16. 48
      service/src/main/java/com/hfkj/sysenum/WeChatQrCodeActionNameEnum.java
  17. 3
      service/src/main/resources/dev/commonConfig.properties

@ -1,16 +1,21 @@
package com.bweb.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.bweb.config.SysConst;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.EasyExcelUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsPayQrCode;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserInfoModel;
import com.hfkj.service.BsPayQrCodeService;
import com.hfkj.sysenum.PayQrCodeStatusEnum;
import com.hfkj.sysenum.SecUserTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -20,6 +25,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -336,4 +342,133 @@ public class BsPayQrCodeController {
}
@RequestMapping(value="/exportQrCodeList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "导出二维码列表")
public ResponseData exportQrCodeList(@RequestParam(name = "companyId", required = false) Long companyId,
@RequestParam(name = "agentId", required = false) Long agentId,
@RequestParam(name = "agentName", required = false) String agentName,
@RequestParam(name = "salesmanId", required = false) Long salesmanId,
@RequestParam(name = "salesmanName", required = false) String salesmanName,
@RequestParam(name = "merId", required = false) Long merId,
@RequestParam(name = "merName", required = false) String merName,
@RequestParam(name = "storeId", required = false) Long storeId,
@RequestParam(name = "storeName", required = false) String storeName,
@RequestParam(name = "serialNumber", required = false) String serialNumber,
@RequestParam(name = "isAssignCompany", required = false) Boolean isAssignCompany,
@RequestParam(name = "isAssignAgent", required = false) Boolean isAssignAgent,
@RequestParam(name = "isAssignSalesman", required = false) Boolean isAssignSalesman,
@RequestParam(name = "isAssignStore", required = false) Boolean isAssignStore) {
try {
UserInfoModel userModel = userCenter.getSessionModel(UserInfoModel.class);
if (userModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, "");
}
Map<String, Object> param = new HashMap<>();
param.put("serialNumber", serialNumber);
param.put("isAssignCompany", isAssignCompany);
param.put("isAssignAgent", isAssignAgent);
param.put("isAssignSalesman", isAssignSalesman);
param.put("isAssignStore", isAssignStore);
if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type0.getNumber())) {
param.put("companyId", companyId);
param.put("agentId", agentId);
param.put("agentName", agentName);
param.put("salesmanId", salesmanId);
param.put("salesmanName", salesmanName);
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type1.getNumber())) {
param.put("companyId", userModel.getBsCompany().getId());
param.put("agentId", agentId);
param.put("agentName", agentName);
param.put("salesmanId", salesmanId);
param.put("salesmanName", salesmanName);
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type2.getNumber())) {
param.put("agentId", userModel.getAgent().getId());
param.put("salesmanId", salesmanId);
param.put("salesmanName", salesmanName);
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type3.getNumber())) {
param.put("salesmanId", userModel.getSalesman().getId());
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type4.getNumber())) {
param.put("merId", userModel.getMer().getId());
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type5.getNumber())) {
param.put("storeId", userModel.getStore().getId());
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, "");
}
List<List<Object>> dataList = new ArrayList<>();
List<Object> data;
List<BsPayQrCode> qrCodeList = payQrCodeService.getQrCodeList(param);
for (BsPayQrCode payQrCode : qrCodeList) {
data = new ArrayList<>();
data.add(payQrCode.getSerialNumber());
data.add(payQrCode.getQrCodeUrl());
data.add(payQrCode.getQrCodeData());
data.add(payQrCode.getWechatQrCodeUrl());
data.add(payQrCode.getCompanyName());
data.add(payQrCode.getAgentName());
data.add(payQrCode.getSalesmanName());
data.add(payQrCode.getMerName());
data.add(payQrCode.getStoreName());
data.add(PayQrCodeStatusEnum.getDataByNumber(payQrCode.getStatus()).getName());
dataList.add(data);
}
List<String> headList = new ArrayList<>();;
headList.add("序列号");
headList.add("二维码图片地址");
headList.add("二维码访问地址");
headList.add("微信公众号访问地址");
headList.add("公司");
headList.add("代理商");
headList.add("业务员");
headList.add("商户");
headList.add("门店");
headList.add("状态");
String fileUrl = SysConst.getSysConfig().getFileUrl() + "/temporary/";
String pathName = System.currentTimeMillis()+".xlsx";
File file = new File(fileUrl);
if (!file.exists()) {
file.mkdirs();
}
EasyExcel.write(fileUrl+pathName).head(EasyExcelUtil.generationHead(headList)).sheet("支付码").doWrite(dataList);
return ResponseMsgUtil.success(pathName);
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@ -117,6 +118,82 @@ public class BsTradeOrderController {
}
}
@RequestMapping(value="/exportOrderList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询订单列表")
public ResponseData exportOrderList(@RequestParam(value = "salesmanId" , required = false) Long salesmanId,
@RequestParam(value = "merId" , required = false) Long merId,
@RequestParam(value = "merName" , required = false) String merName,
@RequestParam(value = "companyId" , required = false) Long companyId,
@RequestParam(value = "agentId" , required = false) Long agentId,
@RequestParam(value = "storeId" , required = false) Long storeId,
@RequestParam(value = "storeName" , required = false) String storeName,
@RequestParam(value = "payMode" , required = false) String payMode,
@RequestParam(value = "outTradeNo" , required = false) String outTradeNo,
@RequestParam(value = "accTradeNo" , required = false) String accTradeNo,
@RequestParam(value = "payTimeS" , required = false) Long payTimeS,
@RequestParam(value = "payTimeE" , required = false) Long payTimeE,
@RequestParam(value = "status" , required = false) Integer status) {
try {
Map<String, Object> param = new HashMap<>();
UserInfoModel userModel = userCenter.getSessionModel(UserInfoModel.class);
if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type0.getNumber())) {
param.put("companyId", companyId);
param.put("agentId", agentId);
param.put("salesmanId", salesmanId);
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type1.getNumber())) {
param.put("companyId", userModel.getBsCompany().getId());
param.put("agentId", agentId);
param.put("salesmanId", salesmanId);
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type2.getNumber())) {
param.put("agentId", userModel.getAgent().getId());
param.put("salesmanId", salesmanId);
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type3.getNumber())) {
param.put("salesmanId", userModel.getSalesman().getId());
param.put("merId", merId);
param.put("merName", merName);
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type4.getNumber())) {
param.put("merId", userModel.getMer().getId());
param.put("storeId", storeId);
param.put("storeName", storeName);
} else if (userModel.getSecUser().getObjectType().equals(SecUserTypeEnum.type5.getNumber())) {
param.put("storeId", userModel.getStore().getId());
}
param.put("payMode", payMode);
param.put("outTradeNo", outTradeNo);
param.put("accTradeNo", accTradeNo);
param.put("payTimeS", payTimeS);
param.put("payTimeE", payTimeE);
param.put("status", status);
List<BsTradeOrder> tradeOrderList = tradeOrderService.getTradeOrderList(param);
return ResponseMsgUtil.success("");
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getOrderByOutTradeOrder",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据交易订单号 查询订单信息")

@ -7,6 +7,7 @@ import com.hfkj.channel.weixin.WeiXinMerService;
import com.hfkj.channel.weixin.utils.HttpClientBuilder;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.WeChatQrcodeUtils;
import com.hfkj.config.device.SoundService;
import com.hfkj.config.mqtt.MqttProviderService;
import com.hfkj.model.ResponseData;
@ -69,6 +70,9 @@ public class TestController {
}
}
@Resource
private WeChatQrcodeUtils weChatQrcodeUtils;
@RequestMapping(value="/soundSendMsg",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "音响发送消息")

@ -0,0 +1,28 @@
package com.hfkj.common.utils;
import java.util.ArrayList;
import java.util.List;
/**
* @className: EasyExcelUtil
* @author: HuRui
* @date: 2023/3/10
**/
public class EasyExcelUtil {
/**
* 生成头部
* @param headList
* @return
*/
public static List<List<String>> generationHead(List<String> headList) {
List<List<String>> list = new ArrayList<>();
List<String> head;
for (String headStr : headList) {
head = new ArrayList<>();
head.add(headStr);
list.add(head);
}
return list;
}
}

@ -11,6 +11,9 @@ import org.springframework.stereotype.Component;
@Data
public class CommonSysConfig {
private String wechat_mp_appid;
private String wechat_mp_secret;
/**
* 华为云OBS桶名称
*/

@ -0,0 +1,53 @@
package com.hfkj.config;
/**
* @author sum1dream
*/
public class TextMessage {
private String toUserName;
private String fromUserName;
private String msgType;
private String content;
private Long createTime;
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public String getMsgType() {
return msgType;
}
public void setMsgType(String msgType) {
this.msgType = msgType;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
}

@ -0,0 +1,358 @@
package com.hfkj.config;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.sysenum.WeChatQrCodeActionNameEnum;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import static org.apache.catalina.manager.Constants.CHARSET;
/**
* @serviceName WeChatQrcodeUtils.java
* @author Sum1Dream
* @version 1.0.0
* @Description // 生成带参数的二维码
* @createTime 16:11 2022/9/2
**/
@Slf4j
@Component
public class WeChatQrcodeUtils {
@Autowired
private WxMpService wxMpService;
@Resource
private RedisUtil redisUtil;
/**
* <pre>
* 创建临时二维码ticket
* @param sceneId 场景值ID临时二维码时为32位非0整型
* @param expireSeconds 该二维码有效时间以秒为单位 最大不超过2592000即30天此字段如果不填则默认有效期为30秒
* @auther: cao_wencao
* @date: 2019/2/18 16:58
* </pre>
*/
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException {
WxMpQrCodeTicket wxMpQrCodeTicket = wxMpService.getQrcodeService().qrCodeCreateTmpTicket(sceneId, expireSeconds);
return wxMpQrCodeTicket;
}
/**
* <pre>
* 创建临时二维码ticket
* @param sceneStr 场景值ID字符串形式的ID字符串类型长度限制为1到64
* @param expireSeconds 该二维码有效时间以秒为单位 最大不超过2592000即30天此字段如果不填则默认有效期为30秒
* @auther: cao_wencao
* @date: 2019/2/18 17:01
* </pre>
*/
public WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException {
WxMpQrCodeTicket wxMpQrCodeTicket = wxMpService.getQrcodeService().qrCodeCreateTmpTicket(sceneStr, expireSeconds);
return wxMpQrCodeTicket;
}
/**
* <pre>
* 创建永久二维码ticket
* @param sceneId 场景值ID最大值为100000目前参数只支持1--100000
* @auther: cao_wencao
* @date: 2019/2/18 17:03
* </pre>
*/
public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException {
return wxMpService.getQrcodeService().qrCodeCreateLastTicket(sceneId);
}
/**
* <pre>
* 创建永久字符串二维码ticket
* @param sceneStr 参数字符串类型长度现在为1到64
* @auther: cao_wencao
* @date: 2019/2/18 17:05
* </pre>
*/
public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException {
return wxMpService.getQrcodeService().qrCodeCreateLastTicket(sceneStr);
}
// 创建微信二维码
public JSONObject createWxQrCode(String token,String sceneStr , String actionName) {
JSONObject object = new JSONObject();
JSONObject objectScene = new JSONObject();
JSONObject objectActionInfo = new JSONObject();
objectScene.put("scene_str" , sceneStr);
objectActionInfo.put("scene" , objectScene);
object.put("action_name" , actionName);
object.put("expire_seconds" , 2592000);
object.put("action_info" , objectActionInfo);
return HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token, object);
}
// 获取微信Token存入redis
public String getWxToken() {
Object token = redisUtil.get("WxToken");
if (null != token) {
return token.toString();
};
// 获取access_token
Map<String, Object> params = new HashMap<>();
params.put("appid", CommonSysConst.getSysConfig().getWechat_mp_appid());
params.put("secret", CommonSysConst.getSysConfig().getWechat_mp_secret());
params.put("grant_type", "client_credential");
JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params);
redisUtil.set("WxToken" , accessTokenObject.getString("access_token") , 7000);
return accessTokenObject.getString("access_token");
}
/**
* <pre>
* 换取二维码图片文件jpg格式
* @param ticket 二维码ticket
* @auther: cao_wencao
* @date: 2019/2/18 17:07
* </pre>
*/
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException {
return wxMpService.getQrcodeService().qrCodePicture(ticket);
}
/**
* <pre>
* 换取二维码图片url地址可以选择是否生成压缩的网址
* @param ticket 二维码ticket
* @param needShortUrl 是否需要压缩的二维码地址
* @auther: cao_wencao
* @date: 2019/2/18 17:10
* </pre>
*/
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException {
String qrCodeUrl = wxMpService.getQrcodeService().qrCodePictureUrl(ticket, needShortUrl);
return qrCodeUrl;
}
/**
* <pre>
* 换取二维码图片url地址
* @param ticket 二维码ticket
* @auther: cao_wencao
* @date: 2019/2/18 17:11
* </pre>
*/
public String qrCodePictureUrl(String ticket) throws WxErrorException {
String url = wxMpService.getQrcodeService().qrCodePictureUrl(ticket);
return url;
}
/**
* 处理 subscribe 类型的event
*
* @param map
* @return
*/
public String handleEventSubscribe(Map<String, String> map) {
String resXmlStr = getReturnMsgSubscribe(map);
return resXmlStr;
}
/**
* @Author Sum1Dream
* @Name getReturnMsgSubscribe
* @Description // 处理文本
* @Date 16:34 2022/9/21
* @Param [decryptMap]
* @Return java.lang.String
*/
public String getReturnMsgSubscribe(Map<String, String> decryptMap) {
TextMessage textMessage = new TextMessage();
textMessage.setToUserName(decryptMap.get("FromUserName"));
textMessage.setFromUserName(decryptMap.get("ToUserName"));
textMessage.setCreateTime(System.currentTimeMillis());
textMessage.setMsgType("text");
textMessage.setContent(decryptMap.get("content"));
return getXmlString(textMessage);
}
/**
* @Author Sum1Dream
* @Name getXmlString
* @Description // 处理xml文件
* @Date 16:34 2022/9/21
* @Param [textMessage]
* @Return java.lang.String
*/
public String getXmlString(TextMessage textMessage) {
String xml = "";
if (textMessage != null) {
xml = "<xml>";
xml += "<ToUserName><![CDATA[";
xml += textMessage.getToUserName();
xml += "]]></ToUserName>";
xml += "<FromUserName><![CDATA[";
xml += textMessage.getFromUserName();
xml += "]]></FromUserName>";
xml += "<CreateTime>";
xml += textMessage.getCreateTime();
xml += "</CreateTime>";
xml += "<MsgType><![CDATA[";
xml += textMessage.getMsgType();
xml += "]]></MsgType>";
xml += "<Content><![CDATA[";
xml += textMessage.getContent();
xml += "]]></Content>";
xml += "</xml>";
}
return xml;
}
/**
* @Author Sum1Dream
* @Name paramPars
* @Description // 微信二维码参数解析
* @Date 13:50 2022/9/22
* @Param [param]
* @Return com.alibaba.fastjson.JSONObject
*/
public JSONObject paramPars(String param) {
String[] paramArray = param.split("&");
JSONObject object = new JSONObject();
for (String s : paramArray) {
String[] array = s.split("=");
object.put(array[0] , array[1]);
}
return object;
}
/**
* @Author Sum1Dream
* @Name downloadQrCode
* @Description // 下载微信二维码到本地
* @Date 15:03 2023/3/8
* @Param [wxQrUrl]
* @Return java.lang.String
*/
public String downloadQrCode(String wxQrUrl) throws Exception {
//定义一个URL对象,就是你想下载的图片的URL地址
URL urld = new URL(wxQrUrl);
//打开连接
HttpURLConnection conn = (HttpURLConnection) urld.openConnection();
//设置请求方式为"GET"
conn.setRequestMethod("GET");
//超时响应时间为10秒
conn.setConnectTimeout(10 * 1000);
//通过输入流获取图片数据
InputStream is = conn.getInputStream();
//得到图片的二进制数据,以二进制封装得到数据,具有通用性
byte[] data = readInputStream(is);
//创建一个文件对象用来保存图片,默认保存当前工程根目录
String downloadQrCodeImgUrl = CommonSysConst.getSysConfig().getFile_url() + "/downloadQrCodeImg.jpg";
File imageFile = new File(downloadQrCodeImgUrl);
//创建输出流
FileOutputStream outStream = new FileOutputStream(imageFile);
//写入数据
outStream.write(data);
//关闭输出流,释放资源
outStream.close();
return downloadQrCodeImgUrl;
}
/**
* @Author Sum1Dream
* @Name decoderQRCode
* @Description // 解析二维码内容
* @Date 15:06 2023/3/8
* @Param [downloadQrCodeImgUrl]
* @Return java.lang.String
*/
public String decoderQRCode(String downloadQrCodeImgUrl) throws Exception {
BufferedImage image;
image = ImageIO.read(new File(downloadQrCodeImgUrl));
if (image == null) {
return null;
}
BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
Hashtable hints = new Hashtable();
hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
QRCodeReader reader = new QRCodeReader();
result = reader.decode(bitmap, hints);
return result.getText();
}
/**
* @Author Sum1Dream
* @Name readInputStream
* @Description // 读取插入内容
* @Date 15:03 2023/3/8
* @Param [inStream]
* @Return byte[]
*/
public static byte[] readInputStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
//创建一个Buffer字符串
byte[] buffer = new byte[6024];
//每次读取的字符串长度,如果为-1,代表全部读取完毕
int len;
//使用一个输入流从buffer里把数据读取出来
while ((len = inStream.read(buffer)) != -1) {
//用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
outStream.write(buffer, 0, len);
}
//关闭输入流
inStream.close();
//把outStream里的数据写入内存
return outStream.toByteArray();
}
/**
* 生成微信二维码链接
* @param code 参数
* @return
*/
public String generateQrCodeImgUrl(String token,String code) {
// 组装 二维码参数
String sceneId = "type=4&codeType=paymentCode&code=" + code;
// 获取二维码参数
JSONObject response = createWxQrCode(token, sceneId , WeChatQrCodeActionNameEnum.actionName3.getName());
if (StringUtils.isBlank(response.getString("url"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "生成失败");
}
return response.getString("url");
}
}

@ -0,0 +1,51 @@
package com.hfkj.config;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
/**
* @serviceName .java
* @author Sum1Dream
* @version 1.0.0
* @Description //TODO
* @createTime 16:24 2022/9/2
**/
@Configuration
public class WxMpConfig {
/**
* 微信客户端配置存储
*
* @return
*/
@Bean
public WxMpConfigStorage wxMpConfigStorage() {
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
// 公众号appId
configStorage.setAppId(CommonSysConst.getSysConfig().getWechat_mp_appid());
// 公众号appSecret
configStorage.setSecret(CommonSysConst.getSysConfig().getWechat_mp_secret());
return configStorage;
}
/**
* @Author Sum1Dream
* @Name wxMpService
* @Description //TODO
* @Date 16:24 2022/9/2
* @Param []
* @Return WxMpService
*/
@Bean
public WxMpService wxMpService() {
WxMpService wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
return wxMpService;
}
}

@ -45,20 +45,22 @@ public interface BsPayQrCodeMapper extends BsPayQrCodeMapperExt {
"mer_id, mer_name, store_id, ",
"store_name, store_bind_time, ",
"serial_number, qr_code_url, ",
"qr_code_data, `status`, ",
"create_time, update_time, ",
"op_user_id, op_user_name, ",
"ext_1, ext_2, ext_3)",
"qr_code_data, wechat_qr_code_url, ",
"`status`, create_time, ",
"update_time, op_user_id, ",
"op_user_name, ext_1, ",
"ext_2, ext_3)",
"values (#{companyId,jdbcType=BIGINT}, #{companyName,jdbcType=VARCHAR}, ",
"#{agentId,jdbcType=BIGINT}, #{agentName,jdbcType=VARCHAR}, ",
"#{salesmanId,jdbcType=BIGINT}, #{salesmanName,jdbcType=VARCHAR}, ",
"#{merId,jdbcType=BIGINT}, #{merName,jdbcType=VARCHAR}, #{storeId,jdbcType=BIGINT}, ",
"#{storeName,jdbcType=VARCHAR}, #{storeBindTime,jdbcType=TIMESTAMP}, ",
"#{serialNumber,jdbcType=VARCHAR}, #{qrCodeUrl,jdbcType=VARCHAR}, ",
"#{qrCodeData,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
"#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
"#{opUserId,jdbcType=BIGINT}, #{opUserName,jdbcType=VARCHAR}, ",
"#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})"
"#{qrCodeData,jdbcType=VARCHAR}, #{wechatQrCodeUrl,jdbcType=VARCHAR}, ",
"#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ",
"#{updateTime,jdbcType=TIMESTAMP}, #{opUserId,jdbcType=BIGINT}, ",
"#{opUserName,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, ",
"#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})"
})
@Options(useGeneratedKeys=true,keyProperty="id")
int insert(BsPayQrCode record);
@ -84,6 +86,7 @@ public interface BsPayQrCodeMapper extends BsPayQrCodeMapperExt {
@Result(column="serial_number", property="serialNumber", jdbcType=JdbcType.VARCHAR),
@Result(column="qr_code_url", property="qrCodeUrl", jdbcType=JdbcType.VARCHAR),
@Result(column="qr_code_data", property="qrCodeData", jdbcType=JdbcType.VARCHAR),
@Result(column="wechat_qr_code_url", property="wechatQrCodeUrl", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
@ -99,8 +102,8 @@ public interface BsPayQrCodeMapper extends BsPayQrCodeMapperExt {
"select",
"id, company_id, company_name, agent_id, agent_name, salesman_id, salesman_name, ",
"mer_id, mer_name, store_id, store_name, store_bind_time, serial_number, qr_code_url, ",
"qr_code_data, `status`, create_time, update_time, op_user_id, op_user_name, ",
"ext_1, ext_2, ext_3",
"qr_code_data, wechat_qr_code_url, `status`, create_time, update_time, op_user_id, ",
"op_user_name, ext_1, ext_2, ext_3",
"from bs_pay_qr_code",
"where id = #{id,jdbcType=BIGINT}"
})
@ -120,6 +123,7 @@ public interface BsPayQrCodeMapper extends BsPayQrCodeMapperExt {
@Result(column="serial_number", property="serialNumber", jdbcType=JdbcType.VARCHAR),
@Result(column="qr_code_url", property="qrCodeUrl", jdbcType=JdbcType.VARCHAR),
@Result(column="qr_code_data", property="qrCodeData", jdbcType=JdbcType.VARCHAR),
@Result(column="wechat_qr_code_url", property="wechatQrCodeUrl", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
@ -156,6 +160,7 @@ public interface BsPayQrCodeMapper extends BsPayQrCodeMapperExt {
"serial_number = #{serialNumber,jdbcType=VARCHAR},",
"qr_code_url = #{qrCodeUrl,jdbcType=VARCHAR},",
"qr_code_data = #{qrCodeData,jdbcType=VARCHAR},",
"wechat_qr_code_url = #{wechatQrCodeUrl,jdbcType=VARCHAR},",
"`status` = #{status,jdbcType=INTEGER},",
"create_time = #{createTime,jdbcType=TIMESTAMP},",
"update_time = #{updateTime,jdbcType=TIMESTAMP},",

@ -84,6 +84,10 @@ public class BsPayQrCodeSqlProvider {
sql.VALUES("qr_code_data", "#{qrCodeData,jdbcType=VARCHAR}");
}
if (record.getWechatQrCodeUrl() != null) {
sql.VALUES("wechat_qr_code_url", "#{wechatQrCodeUrl,jdbcType=VARCHAR}");
}
if (record.getStatus() != null) {
sql.VALUES("`status`", "#{status,jdbcType=INTEGER}");
}
@ -140,6 +144,7 @@ public class BsPayQrCodeSqlProvider {
sql.SELECT("serial_number");
sql.SELECT("qr_code_url");
sql.SELECT("qr_code_data");
sql.SELECT("wechat_qr_code_url");
sql.SELECT("`status`");
sql.SELECT("create_time");
sql.SELECT("update_time");
@ -225,6 +230,10 @@ public class BsPayQrCodeSqlProvider {
sql.SET("qr_code_data = #{record.qrCodeData,jdbcType=VARCHAR}");
}
if (record.getWechatQrCodeUrl() != null) {
sql.SET("wechat_qr_code_url = #{record.wechatQrCodeUrl,jdbcType=VARCHAR}");
}
if (record.getStatus() != null) {
sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
}
@ -280,6 +289,7 @@ public class BsPayQrCodeSqlProvider {
sql.SET("serial_number = #{record.serialNumber,jdbcType=VARCHAR}");
sql.SET("qr_code_url = #{record.qrCodeUrl,jdbcType=VARCHAR}");
sql.SET("qr_code_data = #{record.qrCodeData,jdbcType=VARCHAR}");
sql.SET("wechat_qr_code_url = #{record.wechatQrCodeUrl,jdbcType=VARCHAR}");
sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}");
@ -354,6 +364,10 @@ public class BsPayQrCodeSqlProvider {
sql.SET("qr_code_data = #{qrCodeData,jdbcType=VARCHAR}");
}
if (record.getWechatQrCodeUrl() != null) {
sql.SET("wechat_qr_code_url = #{wechatQrCodeUrl,jdbcType=VARCHAR}");
}
if (record.getStatus() != null) {
sql.SET("`status` = #{status,jdbcType=INTEGER}");
}

@ -88,6 +88,11 @@ public class BsPayQrCode implements Serializable {
*/
private String qrCodeData;
/**
* 微信公众号地址
*/
private String wechatQrCodeUrl;
/**
* 状态 0删除 1正常 2停用
*/
@ -241,6 +246,14 @@ public class BsPayQrCode implements Serializable {
this.qrCodeData = qrCodeData;
}
public String getWechatQrCodeUrl() {
return wechatQrCodeUrl;
}
public void setWechatQrCodeUrl(String wechatQrCodeUrl) {
this.wechatQrCodeUrl = wechatQrCodeUrl;
}
public Integer getStatus() {
return status;
}
@ -332,6 +345,7 @@ public class BsPayQrCode implements Serializable {
&& (this.getSerialNumber() == null ? other.getSerialNumber() == null : this.getSerialNumber().equals(other.getSerialNumber()))
&& (this.getQrCodeUrl() == null ? other.getQrCodeUrl() == null : this.getQrCodeUrl().equals(other.getQrCodeUrl()))
&& (this.getQrCodeData() == null ? other.getQrCodeData() == null : this.getQrCodeData().equals(other.getQrCodeData()))
&& (this.getWechatQrCodeUrl() == null ? other.getWechatQrCodeUrl() == null : this.getWechatQrCodeUrl().equals(other.getWechatQrCodeUrl()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
@ -361,6 +375,7 @@ public class BsPayQrCode implements Serializable {
result = prime * result + ((getSerialNumber() == null) ? 0 : getSerialNumber().hashCode());
result = prime * result + ((getQrCodeUrl() == null) ? 0 : getQrCodeUrl().hashCode());
result = prime * result + ((getQrCodeData() == null) ? 0 : getQrCodeData().hashCode());
result = prime * result + ((getWechatQrCodeUrl() == null) ? 0 : getWechatQrCodeUrl().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
@ -393,6 +408,7 @@ public class BsPayQrCode implements Serializable {
sb.append(", serialNumber=").append(serialNumber);
sb.append(", qrCodeUrl=").append(qrCodeUrl);
sb.append(", qrCodeData=").append(qrCodeData);
sb.append(", wechatQrCodeUrl=").append(wechatQrCodeUrl);
sb.append(", status=").append(status);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);

@ -1105,6 +1105,76 @@ public class BsPayQrCodeExample {
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlIsNull() {
addCriterion("wechat_qr_code_url is null");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlIsNotNull() {
addCriterion("wechat_qr_code_url is not null");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlEqualTo(String value) {
addCriterion("wechat_qr_code_url =", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlNotEqualTo(String value) {
addCriterion("wechat_qr_code_url <>", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlGreaterThan(String value) {
addCriterion("wechat_qr_code_url >", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlGreaterThanOrEqualTo(String value) {
addCriterion("wechat_qr_code_url >=", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlLessThan(String value) {
addCriterion("wechat_qr_code_url <", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlLessThanOrEqualTo(String value) {
addCriterion("wechat_qr_code_url <=", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlLike(String value) {
addCriterion("wechat_qr_code_url like", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlNotLike(String value) {
addCriterion("wechat_qr_code_url not like", value, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlIn(List<String> values) {
addCriterion("wechat_qr_code_url in", values, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlNotIn(List<String> values) {
addCriterion("wechat_qr_code_url not in", values, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlBetween(String value1, String value2) {
addCriterion("wechat_qr_code_url between", value1, value2, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andWechatQrCodeUrlNotBetween(String value1, String value2) {
addCriterion("wechat_qr_code_url not between", value1, value2, "wechatQrCodeUrl");
return (Criteria) this;
}
public Criteria andStatusIsNull() {
addCriterion("`status` is null");
return (Criteria) this;

@ -15,7 +15,7 @@ public interface BsPayQrCodeService {
* 编辑数据
* @param payQrCode
*/
void editData(BsPayQrCode payQrCode);
void editData(BsPayQrCode payQrCode,String token);
/**
* 生成支付二维码

@ -1,12 +1,16 @@
package com.hfkj.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.WriterException;
import com.hfkj.common.QRCodeGenerator;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.HttpUtils;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.config.CommonSysConst;
import com.hfkj.config.WeChatQrcodeUtils;
import com.hfkj.dao.BsPayQrCodeMapper;
import com.hfkj.entity.*;
import com.hfkj.model.UserInfoModel;
@ -45,15 +49,26 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
@Resource
private BsMerService merService;
@Resource
private WeChatQrcodeUtils weChatQrcodeUtils;
@Resource
private UserCenter userCenter;
@Override
public void editData(BsPayQrCode payQrCode) {
public void editData(BsPayQrCode payQrCode, String wxToken) {
UserInfoModel userModel = userCenter.getSessionModel(UserInfoModel.class);
if (userModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, "");
}
// 微信token 请求生成微信的二维码
if (StringUtils.isBlank(wxToken)) {
JSONObject response = HttpsUtils.doGet(CommonSysConst.getSysConfig().getHsg_domain_name() + "/v1/wxMsg/getWxToken");
if (StringUtils.isBlank(response.getString("return_data"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取token失败");
}
wxToken = response.getString("return_data");
}
try {
if (payQrCode.getId() == null) {
payQrCode.setCreateTime(new Date());
@ -69,13 +84,15 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
payQrCode.setQrCodeData(CommonSysConst.getSysConfig().getQr_code_data_url() + "?sn=" + payQrCode.getSerialNumber());
payQrCode.setQrCodeUrl(CommonSysConst.getSysConfig().getQr_code_url() + payQrCode.getSerialNumber() + ".png");
// 生成二维码
// 生成支付二维码
QRCodeGenerator.generateQRCodeImage(
payQrCode.getQrCodeData(),
350,
350,
CommonSysConst.getSysConfig().getFilesystem() + "/payQrCode/" + payQrCode.getSerialNumber() + ".png"
);
// 生成公众号二维码
payQrCode.setWechatQrCodeUrl(weChatQrcodeUtils.generateQrCodeImgUrl(wxToken, payQrCode.getSerialNumber()));
payQrCodeMapper.updateByPrimaryKey(payQrCode);
} else {
@ -92,10 +109,15 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class})
public void generatePayQrCode(Integer generateNum) {
JSONObject response = HttpsUtils.doGet(CommonSysConst.getSysConfig().getHsg_domain_name() + "/v1/wxMsg/getWxToken");
if (StringUtils.isBlank(response.getString("return_data"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取token失败");
}
String token = response.getString("return_data");
BsPayQrCode payQrCode;
for (int i = 0; i < generateNum;i++) {
payQrCode = new BsPayQrCode();
editData(payQrCode);
editData(payQrCode, token);
}
}
@ -134,7 +156,7 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
}
qrCode.setCompanyId(company.getId());
qrCode.setCompanyName(company.getName());
editData(qrCode);
editData(qrCode, null);
}
@Override
@ -157,7 +179,7 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
}
qrCode.setAgentId(agent.getId());
qrCode.setAgentName(agent.getName());
editData(qrCode);
editData(qrCode, null);
}
@Override
@ -188,7 +210,7 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
}
qrCode.setSalesmanId(salesman.getId());
qrCode.setSalesmanName(salesman.getName());
editData(qrCode);
editData(qrCode, null);
}
@Override
@ -222,7 +244,7 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
qrCode.setStoreBindTime(new Date());
qrCode.setMerId(mer.getId());
qrCode.setMerName(mer.getMerName());
editData(qrCode);
editData(qrCode, null);
}
@Override
@ -241,7 +263,7 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
qrCode.setStoreBindTime(null);
qrCode.setMerId(null);
qrCode.setMerName(null);
editData(qrCode);
editData(qrCode, null);
}
@Override
@ -255,7 +277,7 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态错误");
}
qrCode.setStatus(PayQrCodeStatusEnum.status2.getNumber());
editData(qrCode);
editData(qrCode, null);
}
@Override
@ -269,7 +291,7 @@ public class BsPayQrCodeServiceImpl implements BsPayQrCodeService {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态错误");
}
qrCode.setStatus(PayQrCodeStatusEnum.status1.getNumber());
editData(qrCode);
editData(qrCode, null);
}
@Override

@ -1,5 +1,7 @@
package com.hfkj.sysenum;
import java.util.Objects;
/**
* 支付码状态
* @author hurui
@ -19,6 +21,15 @@ public enum PayQrCodeStatusEnum {
this.name = name;
}
public static PayQrCodeStatusEnum getDataByNumber(Integer number) {
for (PayQrCodeStatusEnum ele : values()) {
if (Objects.equals(number,ele.getNumber())) {
return ele;
}
}
return null;
}
public Integer getNumber() {
return number;
}

@ -0,0 +1,48 @@
package com.hfkj.sysenum;
/**
* 微信创建二维码
*/
public enum WeChatQrCodeActionNameEnum {
actionName0(0, "QR_SCENE" , "临时的整型参数值"),
actionName1(1, "QR_STR_SCENE" , "临时的字符串参数值"),
actionName2(2, "QR_LIMIT_SCENE" , "永久的整型参数值"),
actionName3(3, "QR_LIMIT_STR_SCENE" , "永久的字符串参数值"),
;
private Integer number;
private String name;
private String actionInfo;
WeChatQrCodeActionNameEnum(int number, String name , String actionInfo) {
this.number = number;
this.name = name;
this.actionInfo = actionInfo;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getActionInfo() {
return actionInfo;
}
public void setActionInfo(String actionInfo) {
this.actionInfo = actionInfo;
}
}

@ -1,3 +1,6 @@
wechat_mp_appid=wxa075e8509802f826
wechat_mp_secret=0e606fc1378d35e359fcf3f15570b2c5
obs_bucket_name=gratia-pay-test
obs_end_point=https://obs.cn-east-3.myhuaweicloud.com
obs_url=https://gratia-pay-test.obs.cn-east-3.myhuaweicloud.com

Loading…
Cancel
Save