赞
踩
1. 企业微信使用的是以下依赖
- <dependency>
- <groupId>com.github.binarywang</groupId>
- <artifactId>weixin-java-cp</artifactId>
- <version>3.8.0</version>
- </dependency>
2. 在企业微信后台创建一个应用,获取AGENTID,CORPSECRET,CORPID。
3. 创建Service,使用binarywang的sdk包进行企业微信消息发送。
- @Service
- public class QywxService {
-
-
-
- public static final String CORPID="XXX";
- public static final Integer AGENTID=XXX;
- public static final String CORPSECRET="XXXX";
- public static final String GET_TOKEN_URL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET";
-
-
-
- public void push(String user,String content) throws WxErrorException {
-
- System.out.println("=====================================push()=============================");
- WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
- config.setCorpId(CORPID); // 设置微信企业号的appid
- config.setCorpSecret(CORPSECRET); // 设置微信企业号的app corpSecret
- config.setAgentId(AGENTID); // 设置微信企业号应用ID
- // config.setToken(token); // 设置微信企业号应用的token
-
-
- WxCpServiceImpl wxCpService = new WxCpServiceImpl();
- wxCpService.setWxCpConfigStorage(config);
-
- System.out.println(user+"==="+content);
- WxCpMessage message = WxCpMessage.TEXT().agentId(AGENTID).toUser(user).content(content).build();
- wxCpService.messageSend(message);
- WxCpUser usercp = wxCpService.getUserService().getById(user);
- System.out.println("accessToken==="+wxCpService.getAccessToken());
- System.out.println("accessToken==="+usercp.getName()+"==="+usercp.getMobile());
- }
- }

4. 代码调用
qywxService.push(num,username);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。