All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tmsps.ne4Weixin.utils.WeixinUtil Maven / Gradle / Ivy

There is a newer version: 0.8.1
Show newest version
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 "";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy