當前位置:編程學習大全網 - 源碼下載 - 微信的java例子在哪

微信的java例子在哪

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 = "感謝關註";

sendMsg = new WxSendTextMsg(sendMsg, content);

WeiXin.send(sendMsg, getResponse().getOutputStream());

renderNull();

}

}

if(msg instanceof WxRecvTextMsg) {

WxRecvTextMsg m = (WxRecvTextMsg) msg;

String text = m.getContent();

if(null != text)

text = text.trim();

Set<String> keyworkds = new HashSet<String>();

keyworkds.add("1");

keyworkds.add("菜單");

keyworkds.add("menu");

if(keyworkds.contains(text)) {

String content = "1. 菜單\n2.音樂\n,3.圖文\n";

sendMsg = new WxSendTextMsg(sendMsg, content);

} else if("2".equals(text)) {

sendMsg = new WxSendMusicMsg(sendMsg, "夜夜夜夜","林誌炫",

"/-fo3dSag_xI4khGko9WTAnF6hhy/album/w=230/sign=b2b8791418d8bc3ec60801c9b28ba6c8/1ad5ad6eddc451da5ff2c0c5b7fd5266d016329c.jpg", "/94o3dSag_xI4khGko9WTAnF6hhy/album/w=230/sign=67afac3d242dd42a5f0906a8333a5b2f/8c1001e93901213f088bb78855e736d12f2e952e.jpg", "")

.addItem("圖片2", "描述2", "/-4o3dSag_xI4khGko9WTAnF6hhy/album/w=230/sign=5254e9265243fbf2c52ca120807eca1e/77c6a7efce1b9d1669f2564ff2deb48f8c5464e3.jpg", "")

.addItem("圖片3", "描述3", "/-Po3dSag_xI4khGko9WTAnF6hhy/album/w=230/sign=c3b3fe3aaa18972ba33a07c9d6cc7b9d/3812b31bb051f81995bdc164dbb44aed2e73e700.jpg", "")

;

} else {

String content = "1. 菜單\n2.音樂\n,3.圖文\n";

sendMsg = new WxSendTextMsg(sendMsg, content);

}

WeiXin.send(sendMsg, getResponse().getOutputStream());

renderNull();

return;

} else {

String content = "1. 菜單\n2.音樂\n,3.圖文\n";

sendMsg = new WxSendTextMsg(sendMsg, content);

WeiXin.send(sendMsg, getResponse().getOutputStream());

renderNull();

return;

}

} catch (JDOMException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

renderNull();

}

}

  • 上一篇:具有藝術價值的數藏軟件藝術數藏家必備軟件推薦
  • 下一篇:金庸群俠傳下載
  • copyright 2024編程學習大全網