package com.hz.pm.api.user.manage;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.HMac;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * <p>
 * AgentLoginProxyManage
 * </p>
 *
 * @author WendyYang
 * @since 09:35 2023/12/21
 */
@Component
public class AgentLoginManage {

    /**
     * 代登录代理接口：secretKey
     */
    @Value("${agent-login.proxy.secret-key}")
    private String agentLoginProxySecretKey;

    public boolean agentLoginProxySignCheck(String userId, Long timestamp, String sign) {
        if (System.currentTimeMillis() - timestamp > 5000) {
            return false;
        }
        HMac hmacMd5 = SecureUtil.hmacMd5(agentLoginProxySecretKey);
        String digestHex = hmacMd5.digestHex(userId + "#" + timestamp);
        return digestHex.equals(sign);
    }

}
