Merge remote-tracking branch 'origin/dev'
This commit is contained in:
commit
63c97b781e
|
|
@ -61,8 +61,11 @@ public class LoginFilter implements Filter {
|
|||
"/cashierService/song/detail",
|
||||
"/cashierService/song/record",
|
||||
"/cashierService/song",
|
||||
"/cashierService/song/**",
|
||||
"/cashierService/song/singing",
|
||||
"/cashierService/login/test"
|
||||
"/cashierService/login/test",
|
||||
"cashierService/subMsg",
|
||||
"cashierService/user/subQrCode"
|
||||
);
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@ package com.chaozhanggui.system.cashierservice.controller;
|
|||
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.WxMsgSubDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.DistrictVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
import com.chaozhanggui.system.cashierservice.service.FileService;
|
||||
import com.chaozhanggui.system.cashierservice.service.LoginService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.LocationUtils;
|
||||
|
|
@ -44,6 +46,10 @@ public class CommonController {
|
|||
private TbPlatformDictMapper platformDictMapper;
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
private final LoginService loginService;;
|
||||
|
||||
|
||||
/**
|
||||
* 一分钟
|
||||
*/
|
||||
|
|
@ -198,4 +204,19 @@ public class CommonController {
|
|||
// 将手机号码的请求次数加1
|
||||
redisUtil.getIncrNum(key, "2");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订阅消息
|
||||
* @param wxMsgSubDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/subMsg")
|
||||
public Result subscribeWxAccount(@RequestBody WxMsgSubDTO wxMsgSubDTO) {
|
||||
if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) {
|
||||
return Result.fail("shopId或openId缺失");
|
||||
}
|
||||
loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId());
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,28 @@
|
|||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
|
||||
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbUserInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo;
|
||||
import com.chaozhanggui.system.cashierservice.service.LoginService;
|
||||
import com.chaozhanggui.system.cashierservice.service.OnlineUserService;
|
||||
import com.chaozhanggui.system.cashierservice.service.UserService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.MD5Utils;
|
||||
import com.chaozhanggui.system.cashierservice.util.StringUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
|
||||
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@CrossOrigin(origins = "*")
|
||||
@RestController
|
||||
|
|
@ -142,7 +122,7 @@ public class UserContoller {
|
|||
return userService.modityIntegral(integralVo, userSign);
|
||||
}
|
||||
|
||||
@PostMapping("/userIntegral")
|
||||
@PostMapping("/userIntegral")
|
||||
public JSONObject userIntegral(@RequestHeader String token, @RequestBody IntegralFlowVo integralFlowVo) throws Exception {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userSign = jsonObject.getString("userSign");
|
||||
|
|
@ -164,4 +144,17 @@ public class UserContoller {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取订阅当前用户店库存预警消息的二维码
|
||||
*
|
||||
* @param shopId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/subQrCode")
|
||||
public Result getSubQrCode(String shopId) throws Exception {
|
||||
String url = userService.getSubQrCode(shopId);
|
||||
return Result.successWithData(url);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WxMsgSubDTO {
|
||||
private String shopId;
|
||||
private String openId;
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
|||
import com.chaozhanggui.system.cashierservice.util.LockUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.N;
|
||||
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
|
||||
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -62,6 +63,8 @@ public class CartService {
|
|||
private final TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||
private final WechatUtil wechatUtil;
|
||||
|
||||
private final WxAccountUtil wxAccountUtil;
|
||||
|
||||
private final TbShopOpenIdMapper shopOpenIdMapper;
|
||||
|
||||
@Autowired
|
||||
|
|
@ -77,9 +80,10 @@ public class CartService {
|
|||
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate) {
|
||||
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate) {
|
||||
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
||||
this.wechatUtil = wechatUtil;
|
||||
this.wxAccountUtil = wxAccountUtil;
|
||||
this.shopOpenIdMapper = shopOpenIdMapper;
|
||||
this.productService = productService;
|
||||
this.tbProductMapper = tbProductMapper;
|
||||
|
|
@ -478,9 +482,9 @@ public class CartService {
|
|||
shopOpenIds.forEach(item -> {
|
||||
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
|
||||
if (message == null) {
|
||||
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
|
||||
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber() - num) : String.valueOf(productSku.getStockNumber() - num),
|
||||
"商品库存不足,请及时补充。", item.getOpenId());
|
||||
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
|
||||
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)
|
||||
, item.getOpenId());
|
||||
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
|
||||
}else {
|
||||
log.info("{}已在30分钟内推送过消息,跳过发送", item.getOpenId());
|
||||
|
|
@ -639,11 +643,6 @@ public class CartService {
|
|||
return;
|
||||
}
|
||||
|
||||
// 发送判断耗材是否耗尽消息
|
||||
JSONObject objectMsg = new JSONObject();
|
||||
objectMsg.put("skuId", Integer.valueOf(cashierCart.getSkuId()));
|
||||
objectMsg.put("shopId", Integer.valueOf(cashierCart.getShopId()));
|
||||
producer.con_msg(objectMsg.toString());
|
||||
|
||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||
|
|
@ -845,6 +844,17 @@ public class CartService {
|
|||
log.info("开始发送mq消息,消耗耗材,消息内容:{}", jsonObject2);
|
||||
producer.cons(jsonObject2.toString());
|
||||
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
// 发送判断耗材是否耗尽消息
|
||||
JSONObject objectMsg = new JSONObject();
|
||||
objectMsg.put("skuId", Integer.valueOf(cashierCart.getSkuId()));
|
||||
objectMsg.put("shopId", Integer.valueOf(cashierCart.getShopId()));
|
||||
producer.con_msg(objectMsg.toString());
|
||||
}
|
||||
|
||||
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
|
||||
orderInfo.setDetailList(orderDetails);
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
|
|
@ -51,6 +52,19 @@ public class FileService {
|
|||
return "https://" + bucketName + "." + endpoint + "/" + path;
|
||||
}
|
||||
|
||||
public String uploadFileByInputStream(String suffix, InputStream inputStream) throws Exception {
|
||||
String path = getPath("upload", suffix);
|
||||
OSS client = new OSSClientBuilder().build(endpoint, credentialsProvider);
|
||||
try {
|
||||
client.putObject(bucketName, path, inputStream);
|
||||
client.shutdown();
|
||||
} catch (Exception e) {
|
||||
throw new Exception("上传异常");
|
||||
}
|
||||
|
||||
return "https://" + bucketName + "." + endpoint + "/" + path;
|
||||
}
|
||||
|
||||
public String getPath(String prefix, String suffix) {
|
||||
//生成uuid
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
|
|
|||
|
|
@ -64,6 +64,28 @@ public class LoginService {
|
|||
this.shopOpenIdMapper = shopOpenIdMapper;
|
||||
}
|
||||
|
||||
public void addShopId(String openId,String shopId) {
|
||||
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
|
||||
if(Objects.isNull(shopMsg)){
|
||||
shopMsg=new TbUserShopMsg();
|
||||
shopMsg.setShopId(Integer.valueOf(shopId));
|
||||
shopMsg.setOpenId(openId);
|
||||
shopMsg.setCreateTime(new Date());
|
||||
shopMsg.setStatus("1");
|
||||
tbUserShopMsgMapper.insert(shopMsg);
|
||||
}
|
||||
|
||||
// 为商家绑定openid
|
||||
if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId)) == null) {
|
||||
TbShopOpenId shopOpenId = new TbShopOpenId();
|
||||
shopOpenId.setOpenId(openId);
|
||||
shopOpenId.setCreateTime(DateUtil.date());
|
||||
shopOpenId.setShopId(Integer.valueOf(shopId));
|
||||
shopOpenId.setStatus(1);
|
||||
shopOpenIdMapper.insert(shopOpenId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Result wxBusinessLogin(String openId,String shopId){
|
||||
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
|
||||
|
|
@ -414,28 +436,20 @@ public class LoginService {
|
|||
@Transactional
|
||||
public Result upPhone(String openId, String phone, String shopId) {
|
||||
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
|
||||
boolean isup = false;
|
||||
if(StringUtils.isNotBlank(userInfo.getTelephone())){
|
||||
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(userInfo.getTelephone());
|
||||
for (TbShopUser tbShopUser : tbShopUsers) {
|
||||
if (tbShopUser.getShopId().equals(shopId)) {
|
||||
isup = true;
|
||||
}
|
||||
tbShopUser.setTelephone(phone);
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKey(tbShopUser);
|
||||
}
|
||||
if(!isup){
|
||||
registerShopUser(userInfo,shopId);
|
||||
}
|
||||
// 同一个手机号 同一个店 userId 不为空
|
||||
TbShopUser tbShopUserPC = tbShopUserMapper.selectPCByPhoneAndShopId(userInfo.getTelephone(),shopId);
|
||||
if (tbShopUserPC != null) {
|
||||
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
|
||||
tbShopUserMapper.deleteByPrimaryKey(tbShopUserSM.getId());
|
||||
tbShopUserPC.setUserId(userInfo.getId().toString());
|
||||
tbShopUserMapper.updateByPrimaryKey(tbShopUserPC);
|
||||
}else {
|
||||
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), shopId);
|
||||
if (shopUser != null) {
|
||||
shopUser.setTelephone(phone);
|
||||
shopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKey(shopUser);
|
||||
}else {
|
||||
registerShopUser(userInfo,shopId);
|
||||
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
|
||||
if (tbShopUserSM != null) {
|
||||
tbShopUserSM.setIsVip(Byte.parseByte("1"));
|
||||
tbShopUserSM.setTelephone(phone);
|
||||
tbShopUserSM.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKey(tbShopUserSM);
|
||||
}
|
||||
}
|
||||
userInfo.setTelephone(phone);
|
||||
|
|
@ -454,7 +468,7 @@ public class LoginService {
|
|||
shopUser.setCode(dynamicCode);
|
||||
shopUser.setTelephone(userInfo.getTelephone());
|
||||
shopUser.setAmount(BigDecimal.ZERO);
|
||||
shopUser.setIsVip(Byte.parseByte("0"));
|
||||
shopUser.setIsVip(Byte.parseByte("1"));
|
||||
shopUser.setCreditAmount(BigDecimal.ZERO);
|
||||
shopUser.setConsumeAmount(BigDecimal.ZERO);
|
||||
shopUser.setConsumeNumber(0);
|
||||
|
|
|
|||
|
|
@ -405,6 +405,12 @@ public class PayService {
|
|||
|
||||
producer.printMechine(orderId);
|
||||
sendOrderToClient(orderInfo);
|
||||
|
||||
// 发送mq消息并保存库存记录
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("orderId", orderInfo.getId());
|
||||
data.put("plat", "miniApp");
|
||||
mQUtils.sendStockSaleMsg(data);
|
||||
return Result.success(CodeEnum.SUCCESS, "1");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,24 +149,39 @@ public class ProductService {
|
|||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
tbProductSkus.forEach(item -> {
|
||||
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
||||
String specSnap = item.getSpecSnap();
|
||||
if (specSnap != null) {
|
||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
it.setLowPrice(lowerPrice);
|
||||
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
JSONObject snapJSON;
|
||||
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
String finalValues = "";
|
||||
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
String finalValues = "";
|
||||
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import cn.hutool.extra.qrcode.QrConfig;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
|
|
@ -14,13 +17,18 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
|||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.*;
|
||||
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -41,6 +49,17 @@ public class UserService {
|
|||
private TbSystemCouponsMapper systemCouponsMapper;
|
||||
@Autowired
|
||||
RedisUtils redisUtils;
|
||||
@Qualifier("tbShopInfoMapper")
|
||||
@Autowired
|
||||
private TbShopInfoMapper tbShopInfoMapper;
|
||||
private final FileService fileService;
|
||||
|
||||
private final WxAccountUtil wxAccountUtil;
|
||||
|
||||
public UserService(FileService fileService, WxAccountUtil wxAccountUtil) {
|
||||
this.fileService = fileService;
|
||||
this.wxAccountUtil = wxAccountUtil;
|
||||
}
|
||||
|
||||
public JSONObject modityIntegral(IntegralVo integralVo, String userSign) {
|
||||
JSONObject object = (JSONObject) JSONObject.toJSON(integralVo);
|
||||
|
|
@ -228,4 +247,15 @@ public class UserService {
|
|||
int sysNum = systemCouponsMapper.selectByAmount(orderNum);
|
||||
return userNum+sysNum;
|
||||
}
|
||||
|
||||
public String getSubQrCode(String shopId) throws Exception {
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
||||
if (shopInfo == null) {
|
||||
throw new MsgException("店铺不存在");
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId)), new QrConfig(100, 100), "png", outputStream);
|
||||
|
||||
return fileService.uploadFileByInputStream(".png", new ByteArrayInputStream(outputStream.toByteArray()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,4 +160,6 @@ public class WechatUtil {
|
|||
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,123 @@
|
|||
package com.chaozhanggui.system.cashierservice.wxUtil;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WxAccountUtil {
|
||||
@Value("${wx.ysk.appId}")
|
||||
private static String appId = "wx212769170d2c6b2a";
|
||||
@Value("${wx.ysk.secrete}")
|
||||
private static String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0";
|
||||
@Value("${wx.ysk.warnMsgTmpId}")
|
||||
private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0";
|
||||
|
||||
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
|
||||
linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口");
|
||||
linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID");
|
||||
linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口");
|
||||
linkedHashMap.put("40037","不合法的 template_id");
|
||||
linkedHashMap.put("43101","用户未订阅消息");
|
||||
linkedHashMap.put("43107","订阅消息能力封禁");
|
||||
linkedHashMap.put("43108","并发下发消息给同一个粉丝");
|
||||
linkedHashMap.put("45168","命中敏感词");
|
||||
linkedHashMap.put("47003","参数错误");
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
|
||||
}
|
||||
|
||||
public static String getRadarQrCode(Integer shopId) {
|
||||
HashMap<String, Object> req = new HashMap<>();
|
||||
req.put("expire_seconds", 300);
|
||||
req.put("action_name", "QR_STR_SCENE");
|
||||
HashMap<Object, Object> actionInfo = new HashMap<>();
|
||||
HashMap<String, Object> scene = new HashMap<>();
|
||||
scene.put("scene_str", "msg" + shopId);
|
||||
actionInfo.put("scene", scene);
|
||||
req.put("action_info", actionInfo);
|
||||
log.info("开始获取公众号二维码, 请求数据: {}", req);
|
||||
String resp = HttpUtil.post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getAccessToken(), JSONObject.toJSONString(req));
|
||||
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||
log.warn("获取微信公众号二维码结束,响应: {}", resp);
|
||||
if (!respInfo.containsKey("url")) {
|
||||
log.warn("获取微信公众号二维码失败,响应: {}", resp);
|
||||
throw new MsgException(resp);
|
||||
}
|
||||
return respInfo.getString("url");
|
||||
}
|
||||
|
||||
|
||||
public static String getAccessToken() {
|
||||
String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete));
|
||||
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||
if (!respInfo.containsKey("access_token")) {
|
||||
log.warn("公众号获取token失败, 响应内容: {}", resp);
|
||||
throw new MsgException(resp);
|
||||
}
|
||||
return respInfo.getString("access_token");
|
||||
}
|
||||
|
||||
public static JSONObject sendTemplateMsg(String templateId, String toUserOpenId, Map<String, Object> data) {
|
||||
log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||
String accessToken = getAccessToken();
|
||||
|
||||
JSONObject object1=new JSONObject();
|
||||
|
||||
object1.put("template_id", templateId);
|
||||
object1.put("touser", toUserOpenId);
|
||||
object1.put("data",data);
|
||||
|
||||
String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
|
||||
log.info("微信模板消息发送成功,响应内容:{}",response);
|
||||
JSONObject resObj=JSONObject.parseObject(response);
|
||||
if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){
|
||||
return resObj;
|
||||
}
|
||||
|
||||
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||
}
|
||||
|
||||
public static JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId) {
|
||||
stock = stock < 0 ? 0 : stock;
|
||||
Integer finalStock = stock;
|
||||
Map<String, Object> data = new HashMap<String, Object>() {{
|
||||
put("thing22", new HashMap<String, Object>(){{
|
||||
put("value", shopName);
|
||||
}});
|
||||
put("thing4", new HashMap<String, Object>(){{
|
||||
put("value", productName);
|
||||
}});
|
||||
put("number5", new HashMap<String, Object>(){{
|
||||
put("value", finalStock);
|
||||
}});
|
||||
}};
|
||||
log.info("开始发送库存预警消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||
try {
|
||||
return sendTemplateMsg(msgTmpId, toUserOpenId, data);
|
||||
}catch (Exception e) {
|
||||
log.error("发送失败: {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,12 @@ wx:
|
|||
appId: wxcf0fe8cdba153fd6
|
||||
secrete: c33e06467c6879a62af633d50ed6b720
|
||||
warnMsgTmpId: IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY
|
||||
|
||||
ysk:
|
||||
appId: wx212769170d2c6b2a
|
||||
secrete: 8492a7e8d55bbb1b57f5c8276ea1add0
|
||||
warnMsgTmpId: C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0
|
||||
|
||||
#
|
||||
spring:
|
||||
profiles:
|
||||
|
|
|
|||
Loading…
Reference in New Issue