const ServiceBase = require("../../sve.base");
const redisClient = system.getObject("util.redisClient");
const settings = require("./../../../../config/settings");

class messageService extends ServiceBase {
    constructor() {
        super("agriculture", ServiceBase.getDaoName(messageService));
    }

    async ticketProcessing(meg) {
        const messageSecret = settings.ydzKey().messageSecret; // 密钥 16 位
        const iv = messageSecret; // 初始向量 initial vector 16 位, messageSecret 和 iv 可以一致
        //const data = CryptoJS.enc.Utf8.parse(meg.encryptMsg);
        // console.log('-----------------data-------------------');
        // console.log(meg.encryptMsg);
        // var decrypted = CryptoJS.AES.decrypt(data, messageSecret, {
        //     iv: iv,
        //     mode: CryptoJS.mode.CBC,
        //     padding: CryptoJS.pad.Pkcs7
        // });
        // // 转换为 utf8 字符串
        // console.log('---------------------------before -------------');
        // console.log(decrypted);
        // decrypted = CryptoJS.enc.Utf8.stringify(decrypted);
        // console.log('------------------------decrypted--------------------')
        // console.log(decrypted)
        // console.log(iv.length);
        // var clearEncoding = 'utf8'
        // var cipherEncoding = 'base64'
        // var cipherChunks = []
        // var decipher = crypto.createCipheriv('aes-128-ecb', messageSecret, iv)
        // decipher.setAutoPadding(false)

        // cipherChunks.push(decipher.update(this.zeropad(meg.encryptMsg, 8), clearEncoding, cipherEncoding))
        // cipherChunks.push(decipher.final(cipherEncoding))
        // console.log(cipherChunks.join('').toUpperCase());
        // return cipherChunks.join('').toUpperCase();
        // const addRedisResult = await this.redisClient.setWithEx('APP_TICKET', JSON.stringify(obj), 2 * 60 * 60); //俩小时
        // return addRedisResult;
    }
}
module.exports = messageService;