public class WxCtr1 extends Controller {
private static final String TOKEN = "xxxxxx";
public void index() {
String signature = getPara("signature");
String timestamp = getPara("timestamp");
String nonce = getPara("nonce");
String echostr = getPara("echostr");
if(null != timestamp && null != nonce && null != echostr && null != signature) {
if( WeiXin.access(TOKEN, signature, timestamp, nonce)) {
renderHtml(echostr);
return;
}
renderNull();
return;
}
try {
WxRecvMsg msg = WeiXin.recv(getRequest().getInputStream( ));
WxSendMsg sendMsg = WeiXin.builderSendByRecv(msg);
System.out.println(msg);
if(msg instanceof WxRecvEventMsg) {
WxRecvEventMsg m = (WxRecvEventMsg) msg;
String event = m.getEvent();
if("subscribe".equals(event)) {
String content = "Thank you for your attention";
sendMsg = new WxSendTextMsg(sendMsg, content);
WeiXin.send(sendMsg, getResponse().getOutputStream ());
renderNull();
}
}
if(msg instanceof WxRecvTextMsg) {
< p> WxRecvTextMsg m = (WxRecvTextMsg) msg;String text = m.getContent();
if(null != text)
text = text .trim();
Set
keyworkds.add("1");
keyworkds .add("menu");
keyworkds.add("menu");
if(keyworkds.contains(text)) {
String content = "1. Menu\n2. Music\n,3. Graphics\n";
sendMsg = new WxSendTextMsg(sendMsg, content);
} else if("2 ".equals(text)) {
sendMsg = new WxSendMusicMsg(sendMsg, "夜夜夜夜","Lin Zhixuan",
"/-fo3dSag_xI4khGko9WTAnF6hhy/album/w=230 /sign=b2b8791418d8bc3ec60801c9b28ba6c8/1ad5ad6eddc451da5ff2c0c5b7fd5266d016329c.jpg", "/94o3dSag_xI4khGko9WTAnF6hhy/album/w=230/sign=67afac3d242dd42 a5f0906a8333a5b2f/8c1001e93901213f088bb78855e736d12f2e952e.jpg", "")
.addItem("Picture 2", "Description 2 ", "/-4o3dSag_xI4khGko9WTAnF6hhy/album/w=230/sign=5254e9265243fbf2c52ca120807eca1e/77c6a7efce1b9d1669f2564ff2deb48f8c5464e3.jpg", "")
Item("Picture 3", "Description 3", "/-Po3dSag_xI4khGko9WTAnF6hhy/ album/w=230/sign=c3b3fe3aaa18972ba33a07c9d6cc7b9d/3812b31bb051f81995bdc164dbb44aed2e73e700.jpg", "")
;
} else {
String content = "1. Menu \n2. Music\n,3. Graphics\n";
sendMsg = new WxSendTextMsg(sendMsg, content);
}
WeiXin.send (sendMsg, getResponse().getOutputStream());
renderNull();
return;
} else {
String content = "1. Menu\n2. Music\n,3. Graphics\n";
sendMsg = new WxSendTextMsg(sendMsg, content);
WeiXin.send(sendMsg , getResponse().getOutputStream());
renderNull();
return;
}
} catch (JDOMException e ) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
renderNull();
}
}