com.tmsps.ne4Weixin.utils.WeixinUtil Maven / Gradle / Ivy
package com.tmsps.ne4Weixin.utils;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tmsps.ne4Weixin.config.WxConfig;
/**
*
* @author zhangwei [email protected] WeixinSupportUtil
*/
public class WeixinUtil {
protected static Logger log = LoggerFactory.getLogger(WeixinUtil.class);
/**
* @author zhangwei [email protected] 验证微信信息
*/
public static boolean isCheck(HttpServletRequest request, String token) {
String signature = request.getParameter("signature");
String timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
return SignUtil.checkSignature(token, signature, timestamp, nonce);
}
/**
* @author zhangwei [email protected] 解密微信接收到的消息
*/
public static String decryptMsg(HttpServletRequest request, WxConfig wc, String ciphertext) {
if (wc.getIssafe()) {
String msgSignature = request.getParameter("msg_signature");
String timeStamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
log.debug("timeStamp:{},nonce:{},msgSignature:{},ciphertext:{}", timeStamp, nonce, msgSignature, ciphertext);
return MsgEncryptUtil.decrypt(ciphertext, timeStamp, nonce, msgSignature, wc);
} else {
return ciphertext;
}
}
public static String handelMessage(HttpServletRequest request) {
return "";
}
}