若依集成企业微信步骤

  1. pom.xml引入企业微信与RabbitMQ依赖

2.RabbitMQ全局配置:

3. RabbitMQ的监听、配置

原代码如下:

@Component
public class RabbitMQWorldListener {

    @Autowired
    private IQywxService qywxService;

    @RabbitListener(queues = "zyRabbitMQ")
    public void receiveMessage(String queueMessage) throws WxErrorException {

        if (queueMessage.length() > 0) {
            String[] strs = queueMessage.split("@");
            if (strs.length >= 2) {
                qywxService.push(strs[0], strs[1]);

            }
        }

    }
}
@Configuration
public class RabbitConfig {
    @Bean
    public Queue queue(){
        return new Queue("zyRabbitMQ");
    }
}

4.企业微信的service层、impl层

原代码如下:

@Service
public class QywxService implements IQywxService {
    //企业微信
    public static final String CORPID = "*****";
    public static final Integer AGENTID = ***;
    public static final String CORPSECRET = "****";
    public void push(String user, String content) {
        System.out.println("=====================================push()=============================");
        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setCorpId(CORPID);      // 设置微信企业号的appid
        config.setCorpSecret(CORPSECRET);  // 设置微信企业号的app corpSecret
        config.setAgentId(AGENTID);     // 设置微信企业号应用ID
        WxCpServiceImpl wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(config);
        System.out.println(user + "===" + content);
        WxCpMessage message = WxCpMessage.TEXT().agentId(AGENTID).toUser(user).content(content).build();
        System.out.println("send message===" + content);
        WxCpMessageSendResult wxCpMessageSendResult = new WxCpMessageSendResult();
        try {
            wxCpMessageSendResult = wxCpService.messageSend(message);
        } catch (WxErrorException e) {
            e.printStackTrace();
            System.out.println(e.getCause() + "===" + e.getMessage());
        }
        if (wxCpMessageSendResult.getErrCode() == 0) {
            System.out.println("0===推送成功");
        } else {
            System.out.println("500===推送失败");
        }
    }
}
public interface IQywxService {
    //消息推送
    public  void push(String user,String content) throws WxErrorException;
}

5.在具体的方法中调用convertAndSend方法 -->用于企业微信消息提醒

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值