1.公众号订阅新增type类型

This commit is contained in:
SongZhang 2024-08-02 10:59:53 +08:00
parent ad5cd56596
commit 567a5a0e23
7 changed files with 33 additions and 18 deletions

View File

@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
@ -38,6 +40,7 @@ import java.util.List;
@RequiredArgsConstructor
public class CommonController {
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
private final ValidateCodeUtil validateCodeUtil;
@Autowired
@ -213,10 +216,11 @@ public class CommonController {
*/
@PostMapping("/subMsg")
public Result subscribeWxAccount(@RequestBody WxMsgSubDTO wxMsgSubDTO) {
log.info("接收到订阅消息接口调用,携带数据: {}", wxMsgSubDTO);
if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) {
return Result.fail("shopId或openId缺失");
}
loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId());
loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId(), wxMsgSubDTO.getType());
return Result.success(CodeEnum.SUCCESS);
}
}

View File

@ -26,8 +26,7 @@ public interface TbShopOpenIdMapper {
int updateByPrimaryKey(TbShopOpenId record);
@Select("select * from tb_shop_open_id where open_id=#{openId} and shop_id=#{shopId} limit 1")
TbShopOpenId countByOpenId(@Param("openId") String openId, @Param("shopId") Integer shopId);
TbShopOpenId countByOpenId(@Param("openId") String openId, @Param("shopId") Integer shopId, @Param("type") Integer type);
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1")
List<TbShopOpenId> selectByShopId(@Param("shopId") Integer shopId);

View File

@ -6,4 +6,5 @@ import lombok.Data;
public class WxMsgSubDTO {
private String shopId;
private String openId;
private Integer type;
}

View File

@ -4,7 +4,6 @@ import cn.hutool.core.date.DateUtil;
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.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
@ -20,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.*;
@ -64,7 +62,7 @@ public class LoginService {
this.shopOpenIdMapper = shopOpenIdMapper;
}
public void addShopId(String openId,String shopId) {
public void addShopId(String openId, String shopId, Integer type) {
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
if(Objects.isNull(shopMsg)){
shopMsg=new TbUserShopMsg();
@ -76,13 +74,17 @@ public class LoginService {
}
// 为商家绑定openid
if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId)) == null) {
TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), type);
if ( tbShopOpenId == null) {
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(1);
shopOpenIdMapper.insert(shopOpenId);
}else {
tbShopOpenId.setUpdateTime(DateUtil.date());
shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId);
}
}
@ -95,17 +97,17 @@ public class LoginService {
shopMsg.setOpenId(openId);
shopMsg.setCreateTime(new Date());
shopMsg.setStatus("1");
tbUserShopMsgMapper.insert(shopMsg);
// tbUserShopMsgMapper.insert(shopMsg);
}
// 为商家绑定openid
if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId)) == null) {
if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), null) == null) {
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(1);
shopOpenIdMapper.insert(shopOpenId);
// shopOpenIdMapper.insert(shopOpenId);
}
return Result.success(CodeEnum.SUCCESS,shopMsg);

View File

@ -264,7 +264,7 @@ public class UserService {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg");
InputStream inputStream = resource.getInputStream();
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId)), new QrConfig(500, 500).
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1), new QrConfig(500, 500).
setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream);

View File

@ -47,13 +47,13 @@ public class WxAccountUtil {
// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
}
public static String getRadarQrCode(Integer shopId) {
public static String getRadarQrCode(Integer shopId, Integer type) {
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);
scene.put("scene_str", "msg" + shopId + ":" + type);
actionInfo.put("scene", scene);
req.put("action_info", actionInfo);
log.info("开始获取公众号二维码, 请求数据: {}", req);

View File

@ -22,12 +22,21 @@
select
<include refid="Base_Column_List" />
from tb_shop_open_id
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</select>
<select id="countByOpenId" resultType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId">
select * from tb_shop_open_id
where open_id=#{openId}
and shop_id=#{shopId}
<if test="type != null">and type=#{type}</if>
limit 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from tb_shop_open_id
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId" useGeneratedKeys="true">
insert into tb_shop_open_id
@ -76,16 +85,16 @@
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId">
update tb_shop_open_id
set
set
shop_id = #{shopId,jdbcType=INTEGER},
open_id = #{openId,jdbcType=VARCHAR},
status = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>