const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
//缓存首次登录的赠送的宝币数量
class VCodeCache extends CacheBase {
  constructor() {
    super();
    this.smsUtil = system.getObject("util.smsClient");
  }
  // isdebug() {
  //   return settings.env == "dev";
  // }
  desc() {
    return "缓存给手机发送的验证码60妙";
  }
  prefix() {
    return "g_vcode_"
  }
  async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
    //inputkey采用appkey_mobile的形式
    var mobile = inputkey.split("_")[1];
    var tmplCode = val;
    var signName = items ? items[0] : "";
    var vcode = await this.smsUtil.getUidStr(6, 10);
    // var content=tmpl.replace(/\|vcode\|/g,vcode);
    //this.smsUtil.sendMsg(mobile,content);
    if (!tmplCode && !signName) {
      this.smsUtil.sendMsg(mobile, vcode);
    } //tmplCode为发送短信编码，需在阿里开通，signName为短信头描述信息，二者没有传递则用默认的发送验证码
    else {
      this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode }));
    }
    return JSON.stringify({ vcode: vcode });
  }
}
module.exports = VCodeCache;
