企业微信推送
微信企业版适用于企业内部沟通 #生活技巧# #职场生存技巧# #职场沟通软件#
由于需求需要用到news推送方式,尝试了一下并在这里做下总结。
news方式区别于text方式无非多了url(推送点击后的跳转页面) 和 imgUrl(推送消息显示的图片的路径),imgUrl为空字符串时推送消息样式类似于text。
需要注意的是url需要加上微信的地址(一开始直接写跳转页面的地址一直无法显示),路径如下:
https://open.weixin. qq .com/connect/ oauth2 /authorize?appid="+corpid+"&redirect_uri="+ConfigContext.getValue("framework.academic.default.setup['projectUrl']")+"/page/news/announcementDetails.html?id=" + id + "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
其中corpid为企业微信的CorpId, redirect_uri 后面接推送消息点击后需要跳转的页面url即可。
同时imgUrl需要注意的是路径必须是“/”, 无法自动识别“\"为”/“。本小白在图片路径上卡了很久,因为数据库查出来的都是”\", 之前非消息推送的页面url可以识别”\",所以也没在意,在这里吃了亏。好在发现了问题所在,通过 replaceAll后成功显示图片(imgUrl = projectUrl + fullImgUrl.substring(urlIndex).replaceAll("\\\\", "/");)。
代码如下:
Map<String,String> contentMap = new HashMap<String,String>();
StringBuffer buffer = new StringBuffer();
buffer.append(content.split("<p>")[1].split("</p>")[0]).append("\\n").append("\\n");
buffer.append("发布时间:" + currentDateString);
String description = buffer.toString();
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+corpid+"&redirect_uri="+ConfigContext.getValue("framework.academic.default.setup['projectUrl']")+"/page/news/announcementDetails.html?id=" + id + "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
contentMap.put("title", title);
contentMap.put("description", description);
contentMap.put("url", url);
contentMap.put("picurl", imgUrl);
String dk = ConfigContext.getValue("framework.academic.default.setup['agentId']");
SendMessWx.sendWeChatMsgText_util2("@all", "", "", contentMap, "no", dk);
java
运行
//dk为推送模块的AgentId
//==================================================================================
// news推送方式
public static void sendWeChatMsgText_util2(String touser, String toparty, String totag,Map<String,String> content, String safe,String dk) {
URL uRl;
String Title = "";
String Description = "";
String URL = "";
String PIC_URL = "";
String ACCESS_TOKEN = "";
ACCESS_TOKEN = getAccessToken_announcement();
Title = content.get("title");
Description = content.get("description");
URL = content.get("url");
PIC_URL = content.get("picurl");
String action = CREATE_SESSION_URL + ACCESS_TOKEN;
StringBuffer sb = new StringBuffer();
sb.append("{");
sb.append("\"touser\":" + "\"" + touser + "\",");
sb.append("\"toparty\":" + "\"" + toparty + "\",");
sb.append("\"totag\":" + "\"" + totag + "\",");
sb.append("\"msgtype\":" + "\"news\",");
sb.append("\"agentid\":" + "\"" + dk + "\",");
sb.append("\"news\":" + "{");
sb.append("\"articles\":" + "[");
sb.append("{");
sb.append("\"title\":" + "\"" + Title + "\",");
sb.append("\"description\":" + "\"" + Description + "\",");
sb.append("\"url\":" + "\"" + URL + "\",");
sb.append("\"picurl\":" + "\"" + PIC_URL + "\"");
sb.append("}");
sb.append("]");
sb.append("}");
sb.append("}");
String json = sb.toString();
try {
uRl = new URL(action);
String result = WechatUtil.httpsRequest(action,"POST", JSONObject.fromObject(json).toString());
System.out.println("微信返回:"+result);
} catch (Exception e) {
e.printStackTrace();
}
}
java
运行
微信企业号开发文档: http ://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F
网址:企业微信推送 https://www.yuejiaxmz.com/news/view/1448813
相关内容
微信推送怎么做?小白也能懂的微信推送教程企业微信
使用python 发送企业微信告警
怎样在企业微信中使用小程序?可以给企微客户发送小程序吗?
企业微信和个人微信的区别有哪些?
如何推送微信公众号消息
物业软件协同企业微信提效
我校企业微信平台上线了!
微信早安推送 · 提醒喝水小助手
C# 企业微信:开启消息接受&接收消息&推送消息

