前言
这一周的博客记录了这一周关于微信端的代码编写,出现的问题,以及解决方案。差不多微信这一块已经可以了,之后需要解决的就是通过微信链接进入的网页的一些内容了。
图文消息
微信端如果只提供前文提到的text类型的消息回复是远远不足以满足需求的。而且微信端的为终端所提供的Menu,只能对应一系列event,也就是说只能向微信的服务端发送请求,无法进行跳转。
因此,我需要一个能够实现跳转的地方。
在框架里,学长已经写过了一个图文消息的类,我可以根据这个发送图文消息,对应一个链接,然后链接到填写问卷的页面。
图文消息如下:
public class Articles {
//图文消息的一个Bean
private String Title;
private String Description;
private String PicUrl;//图片URL
private String Url; //外部网站URL
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getPicUrl() {
return PicUrl;
}
public void setPicUrl(String picUrl) {
PicUrl = picUrl;
}
public String getUrl() {
return Url;
}
public void setUrl(String url) {
Url = url;
}
(其中的URL即为点击跳转的地址,可以将其设为团队开发的填写问卷的那个地址,当然那个页面需要可以适应手机端的界面。)
实现
学长曾写过一个关于绑定账号的图文消息显示,在具体程序中,我的开发都是参照了这段内容,下面附上这一块内容。
case "bd":
//绑定
smsg.setMsgType("news");
smsg.setArticleCount("2");
Articles a1=new Articles();
a1.setDescription("最后加参即可");
a1.setPicUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1495082230317&di=f57fe3b0e3bc2af9b335cd194ad3bcf6&imgtype=0&src=http%3A%2F%2Fimg3.yxlady.com%2Fyl%2FUploadFiles_5361%2F20160312%2F20160312115540742.jpg");
a1.setUrl("http:// XXX.XX.XXX.XXX/XXX/admin.html?user="+msg.getFromUserName());//222.175.103.23
a1.setTitle("绑定账号");
Articles a2=new Articles();
a2.setDescription("描述");
a2.setPicUrl("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1173791250,1086762243&fm=23&gp=0.jpg");
a2.setUrl("http://www.qq.com/");
a2.setTitle("解绑账号");
ArrayList<Articles>ar=new ArrayList<>();
ar.add(a1);//ar.add(a2);//
smsg.setArticles(ar);//输入的消息包含两项
break;
case "hupu":
//测试使用
smsg.setMsgType("news");
smsg.setArticleCount("2");
Articles a21=new Articles();
a21.setDescription("最后加参即可");
a21.setPicUrl("http://i3.hoopchina.com.cn/user/926/1126926/1331427828_045275.jpg");
a21.setUrl("https://m.hupu.com/");
//a21.setUrl("http://211.87.225.204/YJS/admin.html?user="+msg.getFromUserName());
a21.setTitle("访问虎扑");
Articles a22=new Articles();
a22.setDescription("描述");
a22.setPicUrl("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1173791250,1086762243&fm=23&gp=0.jpg");
a22.setUrl("http://XXX.XX.XXX.XXX/XXX/index.jsp");
a22.setTitle("今日新闻");
ArrayList<Articles>ar2=new ArrayList<>();
ar2.add(a21);ar2.add(a22);//
smsg.setArticles(ar2);//输入的消息包含两项
break;
本文介绍了如何利用微信图文消息功能实现跳转至自定义页面,包括图文消息的配置方法及示例代码,适用于希望增强微信公众号互动性的开发者。
1036

被折叠的 条评论
为什么被折叠?



