简单两步:引入pom,工具类
官方文档: https://developer.work.weixin.qq.com/document/path/91770#%E6%96%87%E6%9C%AC%E7%B1%BB%E5%9E%8B

<dependency>
  <groupId>com.github.binarywang</groupId>
  <artifactId>weixin-java-cp</artifactId>
  <version>4.6.0</version>
</dependency>
import me.chanjar.weixin.cp.api.WxCpGroupRobotService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;

import java.util.List;

public class WeiXinRobot {
    private final WxCpGroupRobotService robotService;

    public WeiXinRobot(String webhook) {
        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setWebhookKey(webhook);
        WxCpServiceImpl wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(config);
        this.robotService = wxCpService.getGroupRobotService();
    }

    public void textSend(String content, List<String> mobileList) {
        try {
            robotService.sendText(content, null, mobileList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void textSendMarkdown(String content) {
        try {
            robotService.sendMarkdown(content);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

image.png

public static void main(String[] args) {
        String webhook = "xxxx-xxx-xxx";
        String content = "实时新增用户反馈 **132例**,请相关同事注意。\n" +
                "> 类型: *用户反馈* \n" +
                "> 普通用户反馈: *117例* \n" +
                "> VIP用户反馈: *15例*";
        List<String> mobileList = new ArrayList<>();
        mobileList.add("18888888888");
        WeiXinRobot wxClient = new WeiXinRobot(webhook);
        wxClient.textSendMarkdown(content);
        wxClient.textSend(content, mobileList);

ggoo
85 声望2 粉丝