适用版本:v3.3.6+;
dependency
<dependency>
<groupId>com.ak.iform.common</groupId>
<artifactId>iform-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, "", "");
作者:caoyl 创建时间:2024-02-29 17:43
最后编辑:caoyl 更新时间:2024-11-25 19:17
最后编辑:caoyl 更新时间:2024-11-25 19:17