适用版本:v3.3.6+;

dependency

<dependency>
   <groupId>com.lc.ibps.common</groupId>
   <artifactId>ibps-msg-biz</artifactId>
</dependency>

配置说明

配置文件在application-app.yml

#------------wechat的配置   --------
wechat:
  getToken: ${WECHAT_GETTOKEN:https://qyapi.weixin.qq.com/cgi-bin/gettoken}
  sendMessage: ${WECHAT_SENDMESSAGE:https://qyapi.weixin.qq.com/cgi-bin/message/send}
  #微信应用的agentid
  agentId: ${WECHAT_AGENTID:1}
  corpid: ${WECHAT_CORPID:}
  corpsecret: ${WECHAT_CORPSECRET:}
  messageType: ${WECHAT_MESSAGETYPE:text} 

API说明

/**
 * 
 * 微信消息推送
 *
 * @param wechat
 *            微信post主体
 * @param sendMessageUrl
 *            微信接口地址,若空使用配置地址
 * @param token
 *            微信参数,若空自动根据默认配置请求
 */
public static void sendMessage(Wechat wechat, String sendMessageUrl, String token)

/**
     * 
     * 获取微信access_token
     *
     * @param getTokenUrl
     *            接口请求地址,若空使用配置地址
     * @param corpid
     *            企业微信CorpID
     * @param corpsecret
     *            企业微信应用Secret
     * @return
     */
    public static String getToken(String getTokenUrl, String corpid, String corpsecret)

使用示例

Wechat wechat = new Wechat();
wechat.setTouser(touser);
wechat.setMsgtype(WechatMsgType.TEXT.getKey());
wechat.setAgentid(AppUtil.getProperty("wechat.agentId"));
wechat.setText(new Text(message.getTemplate().getContent()));
logger.debug(">>>>>>>>>sending wechat to {}.", touser);
WechatUtil.sendMessage(wechat, "", "");
文档更新时间: 2022-11-19 11:36   作者:Eddy