<?php

namespace app\admin\controller;


use crmeb\services\async\LuckyCalc;
use crmeb\services\async\ClearanceCalc;
use crmeb\utils\Redis;
use think\facade\Log;
use app\api\controller\board\UserBoardController;
use app\models\redis\SystemCarousel;
use app\models\user\WechatUser;
use crmeb\services\async\LuckyExtACalc;
use crmeb\services\async\LuckyExtBCalc;
use crmeb\services\async\task\WechatNotify;
use think\facade\Config;
use RobThree\Auth\TwoFactorAuth;
use RobThree\Auth\TwoFactorAuthException;


class Test
{
    public function index()
    {

        $redis = Redis::instance();
        var_dump($redis->get(['CRMEB','TESD']));
    }

    protected function test_board() {
        Log::warning("board updated.");
        $ctl = new UserBoardController();
        $ctl->cache_board();
    }

    protected function test_calc() {
        $activities = [new ClearanceCalc(), new LuckyCalc(), new LuckyExtACalc(), new LuckyExtBCalc()];
        foreach($activities as $activity) {
            $activity->calc();
        }
    }

    protected function test_carousel() {
        SystemCarousel::add('good test', '/pages/leader_board/index');
        print_r(SystemCarousel::getFirst(20));
        SystemCarousel::removeTrash();
    }

    protected function test_wechat_robot() {
        $key = Config::get('app.qy_weixin_robot_aristotle');
        // $svc = \crmeb\services\QyWeixinService::instance();
        // $svc->key($key)->markdown("### user commented\n>hhhh\n1. upm youth\n2. shiny tommorowwww")->post();
        WechatNotify::push(WechatNotify::TYPE_COMMENT, $key, 'gdf');
    }

    protected function test_2fa()
    {
        $tfa = new TwoFactorAuth('twong');
        $secret = $tfa->createSecret();
        echo 'secret:' . $secret;
        $img = $tfa->getQRCodeImageAsDataUri('twongqr', $secret);
        echo 'img:' . $img;
        echo '<img src="'.$img .'" />';
        echo 'chunk:' . chunk_split($secret, 4, ' ');
        $code = $tfa->getCode($secret);
        echo 'code:' . $code;
        echo 'result:' . $tfa->verifyCode($secret, $code);
    }

    protected function test_routine_reg()
    {
        $routine['nickName'] = '山河另';
        $routine['gender']=1;
        $routine['language'] = 'zncn';
        $routine['city']='zd';//
        $routine['province']='hn';
        $routine['country']='cn';//
        $routine['avatarUrl']='http://x';
        $routine['openId']='great';//
        $routine['session_key']='bbc';
        $routine['unionId']='';//用户在开放平台的唯一标识符
        $routine['spid'] = 3;
        $routine['code'] = '5';
        $routine['session_key'] = 'bi';
        $routine['login_type'] = 'routine';
        echo WechatUser::routineOauth($routine);
    }

    public function test()
    {
        // return $this->test_routine_reg();
    }
}