微信 请求校验(确认请求来自微信服务器)

/**

* 请求校验(确认请求来自微信服务器)

*/

public void wxOauth() throws Exception {

// String signature = (String) getRequest().getAttribute("signature");

if (signature == null || signature.equals("")) {

logger.error("微信验证 缺少参数  signature============" + signature);

}

// String timestamp = (String)

// getRequest().getAttribute("timestamp");

if (timestamp == null || timestamp.equals("")) {

logger.error("微信验证 缺少参数  timestamp============" + timestamp);

}

// String nonce = (String) getRequest().getAttribute("nonce");

if (nonce == null || nonce.equals("")) {

logger.error("微信验证 缺少参数  nonce============" + nonce);

}

// String echostr = (String) getRequest().getAttribute("echostr");

if (echostr == null || echostr.equals("")) {

logger.error("微信验证 缺少参数  echostr============" + echostr);

}

String token = ConfigUtil.WXTOKEN;

logger.error("微信验证token.....");

String[] str = { token, timestamp, nonce };

logger.error("微信验证token  str============" + str);

Arrays.sort(str); // 字典序排序

String bigStr = str[0] + str[1] + str[2];

logger.error("微信验证token  bigStr============" + bigStr);

// SHA1加密

String digest = new SHA1().getDigestOfString(bigStr.getBytes()).toLowerCase();

// 确认请求来至微信

if (digest.equals(signature)) {

logger.error("微信验证token  token============" + token);

super.write(echostr);

//wxMessageReceive(echostr);

logger.error("微信验证token  成功============" + token);

}

}

猜你喜欢

转载自a729812804.iteye.com/blog/2257320