"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mslib_1 = require("mslib");
var CryptoJS = require('crypto-js');
/**
 * 验证码token解密
 * @date 2021-10-28 10:15:26
 * @author 单乐鸿
 */
var CaptchaTokenHelper = /** @class */ (function () {
    function CaptchaTokenHelper() {
    }
    CaptchaTokenHelper.prototype.checkToken = function (token, x, y) {
        var current = Math.floor(Date.now());
        var key = CryptoJS.enc.Utf8.parse('stc_pp3_12345678');
        var options = {
            iv: null,
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        };
        var plainText = CryptoJS.AES.decrypt(token, key, options).toString(CryptoJS.enc.Utf8);
        if (plainText == null) {
            mslib_1.logger.info("token 反解析为空");
            return { "repCode": "6111", "repMsg": "验证失败" };
        }
        mslib_1.logger.info("当前时间戳：%s", current);
        mslib_1.logger.info("AES解密出来的明文----%s", plainText);
        var accessTokenArray = plainText.split(":");
        var tokenTimeMillis = Number.parseInt(accessTokenArray[0], 10);
        var originX = Number.parseInt(accessTokenArray[1], 10);
        var originY = Number.parseInt(accessTokenArray[2], 10);
        var slipOffset = Number.parseInt(accessTokenArray[3], 10);
        if ((current - tokenTimeMillis) > 60000) {
            mslib_1.logger.info("时间差：%s毫秒，大于一分钟", current - tokenTimeMillis);
            return { "repCode": "6111", "repMsg": "验证码已失效，请重新获取" };
        }
        if ((originX - slipOffset) > x
            || x > (originX + slipOffset)
            || originY != y) {
            return { "repCode": "6111", "repMsg": "验证失败" };
        }
        return { "repCode": "0000", "repMsg": "成功" };
    };
    return CaptchaTokenHelper;
}());
exports.CaptchaTokenHelper = CaptchaTokenHelper;
//# sourceMappingURL=CaptchaTokenHelper.js.map