yanghui
2022-11-01 8f2544f1d0e5e82c0e7ee1d89abc1c916b0b9f9f
#feat 修改获取token
6个文件已修改
159 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxUtil.java 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java 52 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActActivityServiceImpl.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/util/WxMaConfiguration.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/config/WebSocketClient.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxUtil.java
@@ -3,6 +3,7 @@
import java.math.BigDecimal;
import java.util.*;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.common.constants.WxSubscribeConstants;
@@ -524,8 +525,8 @@
        subscribeDTO.setTemplate_id(templateId);
        subscribeDTO.setPage("packageD/pages/washer/order/index");
        List<TemplateParam> paras=new ArrayList<TemplateParam>();
        paras.add(new TemplateParam("thing9", washerName));
        paras.add(new TemplateParam("phone_number10",washerMobile));
        paras.add(new TemplateParam("thing9", StrUtil.isBlank(washerName) ? "":washerName));
        paras.add(new TemplateParam("phone_number10",StrUtil.isBlank(washerMobile) ? "0":washerMobile));
        subscribeDTO.setTemplateParamList(paras);
        try {
            sendSubscribe(accessToken,subscribeDTO);
@@ -549,8 +550,8 @@
        subscribeDTO.setTemplate_id(templateId);
        subscribeDTO.setPage("pages/washer/order/index");
        List<TemplateParam> paras=new ArrayList<TemplateParam>();
        paras.add(new TemplateParam("thing9", washerName));
        paras.add(new TemplateParam("phone_number10",washerMobile));
        paras.add(new TemplateParam("thing9", StrUtil.isBlank(washerName) ? "无":washerName));
        paras.add(new TemplateParam("phone_number10",StrUtil.isBlank(washerMobile) ? "0" :washerMobile));
        subscribeDTO.setTemplateParamList(paras);
        try {
            sendSubscribe(accessToken,subscribeDTO);
@@ -575,8 +576,8 @@
        subscribeDTO.setPage("packageD/pages/washer/order/index");
        List<TemplateParam> paras=new ArrayList<TemplateParam>();
        paras.add(new TemplateParam("thing4", status));
        paras.add(new TemplateParam("thing3", washerName));
        paras.add(new TemplateParam("thing6",washerMobile));
        paras.add(new TemplateParam("thing3", StrUtil.isBlank(washerName) ? "":washerName));
        paras.add(new TemplateParam("thing6",StrUtil.isBlank(washerMobile) ? "":washerMobile));
        subscribeDTO.setTemplateParamList(paras);
        try {
            sendSubscribe(accessToken,subscribeDTO);
@@ -601,8 +602,8 @@
        subscribeDTO.setPage("pages/washer/order/index");
        List<TemplateParam> paras=new ArrayList<TemplateParam>();
        paras.add(new TemplateParam("thing4", status));
        paras.add(new TemplateParam("thing3", washerName));
        paras.add(new TemplateParam("thing6",washerMobile));
        paras.add(new TemplateParam("thing3", StrUtil.isBlank(washerName) ? "":washerName));
        paras.add(new TemplateParam("thing6",StrUtil.isBlank(washerMobile) ? "":washerMobile));
        subscribeDTO.setTemplateParamList(paras);
        try {
            sendSubscribe(accessToken,subscribeDTO);
@@ -627,8 +628,8 @@
        subscribeDTO.setPage("packageD/pages/washer/order/index");
        List<TemplateParam> paras=new ArrayList<TemplateParam>();
        paras.add(new TemplateParam("phrase14", status));
        paras.add(new TemplateParam("name3", washerName));
        paras.add(new TemplateParam("thing5",washerMobile));
        paras.add(new TemplateParam("name3", StrUtil.isBlank(washerName) ? "":washerName));
        paras.add(new TemplateParam("thing5",StrUtil.isBlank(washerMobile) ? "":washerMobile));
        subscribeDTO.setTemplateParamList(paras);
        try {
            sendSubscribe(accessToken,subscribeDTO);
@@ -653,8 +654,8 @@
        subscribeDTO.setPage("pages/washer/order/index");
        List<TemplateParam> paras=new ArrayList<TemplateParam>();
        paras.add(new TemplateParam("phrase14", status));
        paras.add(new TemplateParam("name3", washerName));
        paras.add(new TemplateParam("thing5",washerMobile));
        paras.add(new TemplateParam("name3", StrUtil.isBlank(washerName) ? "":washerName));
        paras.add(new TemplateParam("thing5",StrUtil.isBlank(washerMobile) ? "":washerMobile));
        subscribeDTO.setTemplateParamList(paras);
        try {
            sendSubscribe(accessToken,subscribeDTO);
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java
@@ -1,23 +1,12 @@
package com.panzhihua.service_community.message;
import static java.util.Objects.nonNull;
import java.util.List;
import javax.annotation.Resource;
import cn.binarywang.wx.miniapp.api.WxMaService;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.panzhihua.common.model.vos.community.ComActDynVO;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.SysUserDao;
import com.panzhihua.service_community.model.dos.ComActDO;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONArray;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComActDynVO;
import com.panzhihua.common.model.vos.community.acid.ComActAcidDangerMemberVO;
import com.panzhihua.common.model.vos.community.acid.ComActAcidMemberVO;
import com.panzhihua.common.model.vos.community.acid.ComActAcidRecordVO;
@@ -25,7 +14,18 @@
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.common.utlis.WxUtil;
import com.panzhihua.common.utlis.WxXCXTempSend;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.SysUserDao;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.service.ComActAcidMemberService;
import com.panzhihua.service_community.util.WxMaConfiguration;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import static java.util.Objects.nonNull;
/**
 * @author zzj
@@ -44,42 +44,43 @@
    private ComActDAO comActDAO;
    @Resource
    private SysUserDao sysUserDao;
    @Resource
    private WxMaConfiguration wxMaConfiguration;
    @RabbitListener(queues=DELAYED_QUEUE)
    public void doTemplate(ComActAcidRecordVO comActAcidRecordVO) {
       R<LoginUserInfoVO> loginUserInfoVOR= userService.getUserInfoByUserId(comActAcidRecordVO.getUserId().toString());
       LoginUserInfoVO loginUserInfoVO=loginUserInfoVOR.getData();
        WxMaService maService = wxMaConfiguration.getMaService("wx118de8a734d269f0");
       if(loginUserInfoVO!=null&& StringUtils.isNotEmpty(loginUserInfoVO.getOpenid())){
           WxXCXTempSend util = new WxXCXTempSend();
           String accessToken = null;
           try {
               accessToken = util.getAccessToken();
                WxUtil.sendSubscribeTXTZ(loginUserInfoVO.getOpenid(), maService.getAccessToken(), "pov2BTQ_uILduT5OoVKubeS2dibbZ_p79cy5AMb_BGE");
           } catch (Exception e) {
               e.printStackTrace();
           }
           WxUtil.sendSubscribeTXTZ(loginUserInfoVO.getOpenid(),accessToken,"pov2BTQ_uILduT5OoVKubeS2dibbZ_p79cy5AMb_BGE");
       }
    }
    @RabbitListener(queues=ACID_DANGER_QUEUE)
    public void pushMessage(ComActAcidDangerMemberVO dangerMember) {
        R r = comActAcidMemberService.selectPushList(dangerMember.getRelationName());
        WxMaService maService = wxMaConfiguration.getMaService("wx118de8a734d269f0");
        if (R.isOk(r) && nonNull(r.getData())) {
            List<ComActAcidMemberVO> members = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), ComActAcidMemberVO.class);
            if (nonNull(members) && !members.isEmpty()) {
                members.forEach(member -> {
                    WxXCXTempSend util = new WxXCXTempSend();
                    String accessToken = null;
                    try {
                        accessToken = util.getAccessToken();
                        WxUtil.sendSubscribeDanger(member.getOpenid(), maService.getAccessToken(), dangerMember, "Yr5idSziLRiRo0t07mcz284sMm41Kr2KsA5UmSc0jWU");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    WxUtil.sendSubscribeDanger(member.getOpenid(), accessToken, dangerMember, "Yr5idSziLRiRo0t07mcz284sMm41Kr2KsA5UmSc0jWU");
                });
            }
        }
    }
    @RabbitListener(queues = DIRECT_QUEUE)
    public void updateUserInfo(ComActAcidRecordVO comActAcidRecordVO){
        //防疫登记提交默认绑定用户信息
@@ -98,8 +99,7 @@
                    if(CollectionUtils.isNotEmpty(comActDOS)){
                        if(comActDOS.size()==1){
                            loginUserInfoVO.setCommunityId(comActDOS.get(0).getCommunityId());
                        }
                        else {
                        } else {
                            ComActDO comActDO=comActDAO.selectOne(new QueryWrapper<ComActDO>().lambda().eq(ComActDO::getAppId,"wx118de8a734d269f0").eq(ComActDO::getName,town).and(comActDOLambdaQueryWrapper -> comActDOLambdaQueryWrapper.like(ComActDO::getAddress,town).or().like(ComActDO::getAddress,area).or().like(ComActDO::getAddress,country)));
                            if(comActDO!=null){
                                loginUserInfoVO.setCommunityId(comActDO.getCommunityId());
@@ -112,15 +112,17 @@
            }
        }
    }
    @RabbitListener(queues = ACID_MESSAGE_QUEUE)
    public void sendMessage(ComActDynVO comActDynVO){
        try{
            List<String> openIds=sysUserDao.selectOpenId();
            String appId = "wx118de8a734d269f0";
            WxXCXTempSend wxXCXTempSend=new WxXCXTempSend();
            WxMaService maService = wxMaConfiguration.getMaService("wx118de8a734d269f0");
            for (int i = 0; i < openIds.size(); i++) {
                try {
                    WxUtil.sendLongTimeTemplate(openIds.get(i),wxXCXTempSend.getAccessTokenValid(appId,i),"疫情快讯",comActDynVO.getTitle().length()>10?comActDynVO.getTitle().substring(0,10)+"..":comActDynVO.getTitle(),"/pages/community_child/community/detail?id="+comActDynVO.getId()+"&title=疫情快讯详情");
                    WxUtil.sendLongTimeTemplate(openIds.get(i), maService.getAccessToken(), "疫情快讯", comActDynVO.getTitle().length() > 10 ? comActDynVO.getTitle().substring(0, 10) + ".." : comActDynVO.getTitle(), "/pages/community_child/community/detail?id=" + comActDynVO.getId() + "&title=疫情快讯详情");
                } catch (Exception e) {
                    e.printStackTrace();
                }
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActActivityServiceImpl.java
@@ -19,6 +19,7 @@
import javax.annotation.Resource;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.hutool.core.collection.CollUtil;
import com.panzhihua.common.constants.HttpStatus;
import com.panzhihua.common.model.dtos.community.ActivityInviteDTO;
@@ -28,6 +29,7 @@
import com.panzhihua.service_community.entity.ComActActivityInvite;
import com.panzhihua.service_community.model.dos.ComActNeighborCircleTopicWestDO;
import com.panzhihua.service_community.service.ComActActivityInviteService;
import com.panzhihua.service_community.util.WxMaConfiguration;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
@@ -140,6 +142,8 @@
    private ComActActivityInviteService comActActivityInviteService;
    @Resource
    private ComActNeighborCircleDAO comActNeighborCircleDAO;
    @Resource
    private WxMaConfiguration wxMaConfiguration;
    /**
     * 新增社区活动
@@ -251,8 +255,8 @@
            List<ActivitySignVO> activitySignVOS = comActActSignDAO.listActivitySigns(activitySignVO);
            if (!activitySignVOS.isEmpty()) {
                try {
                    WxXCXTempSend util = new WxXCXTempSend();
                    String accessToken = util.getAccessToken();
                    WxMaService maService = wxMaConfiguration.getMaService("wx118de8a734d269f0");
                    String accessToken = maService.getAccessToken();
                    ComActDO comActDO=comActDAO.selectById(comActActivityDO.getCommunityId());
                    R<SysTemplateConfigVO> r=userService.selectTemplate(comActDO.getAreaCode(),1);
                    activitySignVOS.forEach(activitySignVO1 -> {
@@ -831,6 +835,7 @@
//        log.info("定时任务--修改社区活动报名状态活动数量【{}】", num1);
        // 查询已经结束的活动,需要计算积分
        List<Long> activityEndIds = comActActivityDAO.selectBeginIds();
        WxMaService maService = wxMaConfiguration.getMaService("wx118de8a734d269f0");
        if(!CollectionUtils.isEmpty(activityEndIds)){
            activityEndIds.forEach(activityId->{
                List<String> openIds=comActActivityDAO.selectOpenIdByActivityId(activityId);
@@ -838,7 +843,7 @@
                    openIds.forEach(op->{
                        WxXCXTempSend wxXCXTempSend=new WxXCXTempSend();
                        try {
                            WxUtil.sendLongTimeTemplate(op,wxXCXTempSend.getAccessToken("wx118de8a734d269f0"),"活动开始提醒","您参加的活动已开始","packageC/pages/activity/communityActivityDetails/communityActivityDetails?id="+activityId);
                            WxUtil.sendLongTimeTemplate(op,maService.getAccessToken(),"活动开始提醒","您参加的活动已开始","packageC/pages/activity/communityActivityDetails/communityActivityDetails?id="+activityId);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
@@ -859,7 +864,7 @@
                    openIds.forEach(op->{
                        WxXCXTempSend wxXCXTempSend=new WxXCXTempSend();
                        try {
                            WxUtil.sendLongTimeTemplate(op,wxXCXTempSend.getAccessToken("wx118de8a734d269f0"),"活动结束提醒","您参加的活动已结束","packageC/pages/activity/communityActivityDetails/communityActivityDetails?id="+id);
                            WxUtil.sendLongTimeTemplate(op,maService.getAccessToken(),"活动结束提醒","您参加的活动已结束","packageC/pages/activity/communityActivityDetails/communityActivityDetails?id="+id);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
@@ -1001,9 +1006,9 @@
            .lambda().le(ComActActivityDO::getBeginAt, DateUtils.addDays(new Date(), 1))
            .ge(ComActActivityDO::getBeginAt, new Date()).notIn(ComActActivityDO::getStatus,5,6));
        if (!actActivityList.isEmpty()) {
            WxXCXTempSend util = new WxXCXTempSend();
            WxMaService maService = wxMaConfiguration.getMaService("wx118de8a734d269f0");
            try {
                String accessToken = util.getAccessToken();
                String accessToken = maService.getAccessToken();
                actActivityList.forEach(actActivity -> {
                    ComActDO comActDO=comActDAO.selectById(actActivity.getCommunityId());
                    R<SysTemplateConfigVO> r=userService.selectTemplate(comActDO.getAreaCode(),9);
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/util/WxMaConfiguration.java
@@ -2,6 +2,14 @@
import javax.annotation.Resource;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.user.SysAppConfigVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.StringUtils;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import cn.binarywang.wx.miniapp.api.WxMaService;
@@ -21,6 +29,12 @@
    @Resource
    private WxMaProperties properties;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Resource
    private UserService userService;
    public WxMaService getMaService() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
@@ -31,4 +45,26 @@
        wxMaService.setWxMaConfig(config);
        return wxMaService;
    }
    public WxMaService getMaService(String appid) {
        WxRedisOps redisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
        WxMaRedisBetterConfigImpl config = new WxMaRedisBetterConfigImpl(redisOps, "access_token");
        if(StringUtils.isNotEmpty(appid)){
            R<SysAppConfigVO> r=userService.selectByAppid(appid);
            if(R.isOk(r)){
                SysAppConfigVO sysAppConfigVO= r.getData();
                config.setAppid(sysAppConfigVO.getAppId());
                config.setSecret(sysAppConfigVO.getSecret());
                config.setMsgDataFormat(properties.getMsgDataFormat());
            }
        }
        else{
            config.setAppid(properties.getAppid());
            config.setSecret(properties.getSecret());
            config.setMsgDataFormat(properties.getMsgDataFormat());
        }
        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);
        return wxMaService;
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/config/WebSocketClient.java
@@ -69,33 +69,6 @@
        dealNewData(message);
    }
    @Async
    void dealNewData(String message) {
        comPropertyAlarmDao = SpringUtil.getBean(ComPropertyAlarmDao.class);
        JSONObject deviceMess = JSONObject.parseObject(message);
        boolean checkFlag =
                ("trace_call".equals(deviceMess.getString("cmd")) && (StringUtils.isNotEmpty(deviceMess.getString("userid"))));
        if (checkFlag) {
            logger.info("收到设备报警信息:{}", message);
            for (int i = 1; i < 10; i++) {
                if (org.apache.commons.lang.StringUtils.isNotEmpty(deviceMess.getString("num" + i))) {
                    ComPropertyAlarm comPropertyAlarm = new ComPropertyAlarm();
                    comPropertyAlarm.setSerialNo(deviceMess.getString("userid"));
                    comPropertyAlarm.setReceiveNo(deviceMess.getString("num" + i));
                    comPropertyAlarm.setStatus(0);
                    // 10位的秒级别的时间戳
                    Date createDate = new Date(deviceMess.getLong("ts" + i) * 1000);
                    //对应的就是时间戳对应的Date
                    comPropertyAlarm.setCreateTime(createDate);
                    comPropertyAlarm.setType(1);
                    comPropertyAlarmDao.insert(comPropertyAlarm);
                } else {
                    break;
                }
            }
        }
    }
    @Deprecated
    @Async
    void dealNewData(String message) {
springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -309,7 +309,7 @@
        Boolean isIndustryOrExpertAccount=(userDao.isIndustryCenterAccount(name)>0 || userDao.isExpertAccount(name)>0);
        if (1 == type) {
            sysUserDO = userDao.selectOne(
                new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getType, type).eq(SysUserDO::getOpenid, name));
                new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getType, type).eq(SysUserDO::getOpenid, name).eq(SysUserDO::getAppId, appId));
        }else if(isIndustryOrExpertAccount) {
            //三说会堂行业分中心或专家后台账号登陆
            sysUserDO = userDao.selectOne(