微信企业号如何预览发布消息前如何用指定的手机进行预览?

2976人阅读
微信(13)
微信企业号(11)
移动开发(12)
企业可以主动发消息给成员,消息量不受限制。
调用接口时,使用Https协议、JSON数据包格式,数据包不需做加密处理。
目前消息型应用支持文本、图片、语音、视频、文件、图文等消息类型。除了news类型,其它类型的消息可在发送时加上保密选项,保密消息会被打上水印,并且只有接收者才能阅读。主页型应用支持文本类型,文本长度不超过20个字。
&touser&: &UserID1|UserID2|UserID3&,
&toparty&: & PartyID1 | PartyID2 &,
&totag&: & TagID1 | TagID2 &,
&msgtype&: &news&,
&agentid&: 1,
&articles&:[
&title&: &Title&,
&description&: &Description&,
&url&: &URL&,
&picurl&: &PIC_URL&
&title&: &Title&,
&description&: &Description&,
&url&: &URL&,
&picurl&: &PIC_URL&
成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
消息类型,此时固定为:news
企业应用的id,整型。可在应用的设置页面查看
图文消息,一个图文消息支持1到10条图文
description
点击后跳转的链接。
图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80。如不填,在客户端不显示图片
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
* 主动发送消息
* @param mess
boolean sendReqMsg(ReqBaseMessage mess){
//消息json格式
String jsonContext=mess.toJsonStr();
//System.out.println(jsonContext);
//获得token
String token=getTokenFromWx();
boolean flag=
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost= new HttpPost(&https://qyapi./cgi-bin/message/send?access_token=&+token);
//发送json格式的数据
StringEntity myEntity = new StringEntity(jsonContext,
ContentType.create(&text/plain&, &UTF-8&));
//设置需要传递的数据
httpPost.setEntity(myEntity);
// Create a custom response handler
ResponseHandler&JSONObject& responseHandler = new ResponseHandler&JSONObject&() {
//对访问结果进行处理
public JSONObject handleResponse(
final HttpResponse response) throws ClientProtocolException, IOException {
int status = response.getStatusLine().getStatusCode();
if (status &= 200 && status & 300) {
HttpEntity entity = response.getEntity();
if(null!=entity){
String result= EntityUtils.toString(entity);
//根据字符串生成JSON对象
JSONObject resultObj = JSONObject.fromObject(result);
return resultO
throw new ClientProtocolException(&Unexpected response status: & + status);
//返回的json对象
JSONObject responseBody = httpclient.execute(httpPost, responseHandler);
System.out.println(responseBody);
int result= (Integer) responseBody.get(&errcode&);
if(0==result){
httpclient.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
---------------------------------------------------------------------------------------------------------------
------实体类
---------------------------------------------------------------------------------------------------------------
* @author muyunfei
* &p&Modification History:&/p&
Description&/p&
* &p&------------------------------------------------------------------&/p&
* &p&Apr 8, 2015
public class WxNewsMessage extends ReqBaseMessage {
WxNewsMessage(){}
public List&WxArticle&
public List&WxArticle& getNews() {
public void setNews(List&WxArticle& news) {
this.news =
WxNewsMessage(String touser, String toparty, String totag,
String msgtype, String agentid) {
super.touser =
super.toparty =
super.totag =
super.msgtype =
super.agentid =
public String toJsonStr(){
StringBuffer jsonStr=new StringBuffer(&{&);
StringBuffer str_tmp= new StringBuffer(&&);
//&\&touser\&: \&@all\&,\&msgtype\&: \&text\&,\&agentid\&: \&0\&,\&text\&: {\&content\&: \&helloworld\&},\&safe\&: \&0\&}&;
if(null!=touser&&!&&.equals(touser)){
if(!&&.equals(str_tmp.toString())){
str_tmp.append(&,&);
str_tmp.append(&\&touser\&: \&&+touser+&\&&);
if(null!=toparty&&!&&.equals(toparty)){
if(!&&.equals(str_tmp.toString())){
str_tmp.append(&,&);
str_tmp.append(&\&toparty\&: \&&+toparty+&\&&);
if(null!=totag&&!&&.equals(totag)){
if(!&&.equals(str_tmp.toString())){
str_tmp.append(&,&);
str_tmp.append(&\&totag\&: \&&+totag+&\&&);
if(null!=msgtype&&!&&.equals(msgtype)){
//去除空格
msgtype=msgtype.trim();
//判断是否加逗号
if(!&&.equals(str_tmp.toString())){
str_tmp.append(&,&);
str_tmp.append(&\&msgtype\&: \&&+msgtype+&\&&);
//新闻消息
if(null!=news&&0!=news.size()){
if(!&&.equals(str_tmp.toString())){
str_tmp.append(&,&);
StringBuffer content=new StringBuffer(&&);
for (int i = 0; i & news.size(); i++) {
content.append(&,&);
content.append(&{&);
//获得一条消息
WxArticle info = news.get(i);
StringBuffer artileContent=new StringBuffer(&&);
if(null!=info.getTitle()&&!&&.equals(info.getTitle())){
if(null!=artileContent.toString()&&!&&.equals(artileContent.toString())){
artileContent.append(&,&);
artileContent.append(&\&title\&: \&&+info.getTitle()+&\&&);
if(null!=info.getDescription()&&!&&.equals(info.getDescription())){
if(null!=artileContent&&!&&.equals(artileContent)){
artileContent.append(&,&);
artileContent.append(&\&description\&: \&&+info.getDescription()+&\&&);
if(null!=info.getUrl()&&!&&.equals(info.getUrl())){
if(null!=artileContent&&!&&.equals(artileContent)){
artileContent.append(&,&);
//详细地址
artileContent.append(&\&url\&: \&&+info.getUrl()+&\&&);
if(null!=info.getPicurl()&&!&&.equals(info.getPicurl())){
if(null!=artileContent&&!&&.equals(artileContent)){
artileContent.append(&,&);
//图片地址
artileContent.append(&\&picurl\&: \&&+info.getPicurl()+&\&&);
content.append(artileContent.toString()+&}&);
str_tmp.append(&\&news\&: {\&articles\&:[&+content+&]}&);
if(null!=agentid&&!&&.equals(agentid)){
if(!&&.equals(str_tmp.toString())){
str_tmp.append(&,&);
str_tmp.append(&\&agentid\&: \&&+agentid+&\&&);
jsonStr.append(str_tmp);
jsonStr.append(&}&);
return jsonStr.toString();
package com.haiyisoft.entity.wx.
* 图文model
public class WxArticle {
// 图文消息名称
// 图文消息描述
// 图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80
// 点击图文消息跳转链接
public String getTitle() {
public void setTitle(String title) {
this.title =
public String getDescription() {
public void setDescription(String description) {
this.description =
public String getPicurl() {
public void setPicurl(String picurl) {
this.picurl =
public String getUrl() {
public void setUrl(String url) {
this.url =
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:431884次
积分:5689
积分:5689
排名:第3912名
原创:148篇
转载:18篇
评论:134条
(1)(2)(7)(6)(7)(3)(1)(1)(1)(1)(5)(9)(5)(2)(2)(4)(6)(1)(2)(2)(1)(2)(1)(2)(2)(3)(3)(11)(5)(8)(3)(5)(4)(9)(5)(1)(4)(2)(4)(3)(1)(3)(4)(10)(4)

我要回帖

更多关于 微信企业号推送消息 的文章

 

随机推荐