package com.zd.base.message.utils;

import com.zd.common.core.exception.ServiceException;

public class WXPublicUtils {

    private WXPublicUtils() {
        throw new IllegalStateException("WXPublicUtils class");
    }

    /**
     * 验证Token
     * @param msgSignature 签名串，对应URL参数的signature
     * @param timeStamp 时间戳，对应URL参数的timestamp
     * @param nonce 随机串，对应URL参数的nonce
     * @param token Token(令牌)
     * @return 是否为安全签名
     */
    public static boolean verifyUrl(String msgSignature, String timeStamp, String nonce, String token) {
        String signature = SHA1.getSHA1(token, timeStamp, nonce);
        if (!signature.equals(msgSignature)) {
            throw new ServiceException("token 验证失败");
        }
        return true;
    }
}
