91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

微信公眾平臺,開發(fā)者模式下的Java實現(xiàn)。實現(xiàn)菜單,自動回復,關注事件等!利用SpringMVC框架實現(xiàn)。如有疑問,可以關注我的博客~

資源截圖

代碼片段和文件信息

package?com.duowan.yymobilegame.controller.wechat;

import?java.io.IOException;
import?java.io.InputStream;
import?java.io.PrintWriter;
import?java.security.MessageDigest;
import?java.security.NoSuchAlgorithmException;
import?java.util.Arrays;
import?java.util.List;

import?javax.servlet.http.HttpServletRequest;
import?javax.servlet.http.HttpServletResponse;
import?javax.xml.parsers.DocumentBuilder;
import?javax.xml.parsers.DocumentBuilderFactory;

import?org.apache.commons.logging.Log;
import?org.apache.commons.logging.LogFactory;
import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.stereotype.Controller;
import?org.springframework.web.bind.annotation.RequestMapping;
import?org.w3c.dom.Document;
import?org.w3c.dom.Element;
import?org.w3c.dom.Node;
import?org.w3c.dom.NodeList;

import?com.duowan.yymobilegame.exception.YymobilegameException;
import?com.duowan.yymobilegame.model.GTextInfo;
import?com.duowan.yymobilegame.model.WeChatReceiveMsg;
import?com.duowan.yymobilegame.service.GTextInfoService;

/**
?*?微信設置控制器
?*?@author?Administrator
?*
?*/
@RequestMapping(“/client“)
@Controller
public?class?WeChatController{

private?static?final?Log?log?=?LogFactory.getLog(WeChatController.class);
public?final?String?TOKEN?=?“ziqiangbuxi“;
private?final?String?SUBSCRIBE_EVENT?=?“subscribe“;//訂閱事件
private?final?String?MENU_CLICK_EVENT?=?“CLICK“;
@Autowired
private?GTextInfoService?gTextInfoService;//圖文信息服務
/**
?*?驗證微信URL的合法性,申請開發(fā)者模式
?*?@param?request
?*?@param?response
?*?@throws?IOException?
?*/
@RequestMapping(“/valid.do“)
public?void?weChatService(HttpServletRequest?request?HttpServletResponse?response?InputStream?is)?throws?IOException{
String?method?=?request.getMethod();
if(method.equals(“GET“)){
valid(request?response);
}else{
doPost1(request?response?is);
}

}

/**
?*?微信服務器驗證
?*?@param?request
?*?@param?response
?*/
private?void?valid(HttpServletRequest?request?HttpServletResponse?response){
String?signature?=?request.getParameter(“signature“);//微信加密簽名,signature結合了開發(fā)者填寫的token參數(shù)和請求中的timestamp參數(shù)、nonce參數(shù)。
String?timestamp?=?request.getParameter(“timestamp“);//時間戳
String?nonce?=?request.getParameter(“nonce“);//隨機數(shù)
String?echostr?=?request.getParameter(“echostr“);//隨機字符串

try?{
boolean?result?=??checkSignature(signature?timestamp?nonce?TOKEN);
if(result?==?true){
PrintWriter?pw?=?response.getWriter();
pw.write(echostr);
}
}catch?(Exception?e)?{
log.error(e.getMessage()?e);
}
}

/**
?*?響應微信發(fā)來的消息
?*?@param?request
?*?@param?response
?*/
private?void?doPost1(HttpServletRequest?request?HttpServletResponse?response?InputStream?is){
try?{
WeChatReceiveMsg?msg?=?getMsg(is);
String?msgType?=?msg.getMsgType();//獲得信息類型
if(msgType?==?null?||?msgType.length()?==?0)
throw?new?YymobilegameException(“----------公眾平臺服務器返回的信息不實標準格式,請檢查!-

評論

共有 條評論