<?php


namespace App\Console\Commands;


use App\Consts\SysConsts;
use App\Jobs\QappTikTok\QappTikTokUser;
use App\Jobs\QappTikTok\QappTikTokUserRequest;
use App\Libs\Push\OPPOPush\OPPOPushCommon;
use App\Libs\Utils;
use App\Modules\Channel\Models\ChannelAdvert;
use App\Modules\User\Models\QappUser;
use App\Modules\User\Models\User;
use Hashids;
use Illuminate\Console\Command;

class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '测试';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $advert = ChannelAdvert::where('distribution_id',192)
            ->where('release_type',5)
            ->where('status',1)
            ->first();
        dd($advert);
        $user = User::find(278217244);
        $data = QappUser::find(11954352);
        if(is_object($data)){
            $data = $data->toArray();
        }
        $tikTokRegisterRequest                = new QappTikTokUserRequest();
        $tikTokRegisterRequest->ip            = $user->register_ip;
        $tikTokRegisterRequest->device_no     = $data['device_no'];
        $tikTokRegisterRequest->mac           = $data['mac'];
        $tikTokRegisterRequest->channel_id    = $user->distribution_channel_id;
        $tikTokRegisterRequest->uid           = $user->id;
        $tikTokRegisterRequest->register_time = $user->created_at->format('Y-m-d H:i:s');
        $tikTokRegisterRequest->send_order_id = $data['send_order_id'];
        myLog('qapp_register')->info('', compact('tikTokRegisterRequest'));

        // 回传业务
        $job = new QappTikTokUser($tikTokRegisterRequest);
        dispatch($job->onConnection('rabbitmq')->onQueue('qapp_tiktok_user_register_queue'));
        dd('success');

        $sign      = 'd1192936959b3c79be1e1582f7b7c27f';
        $timestamp = 1646118354;
        $key       = 'a!A&AFRWT65Nb3NlklezUiqHyQAA@Z8M';
//        $params    = '/api/login';
        $params = array (
            'androidid' => 'a682b826a7ce46473f30e238647fa38b983f03605a792d0492f561f075c61424',
            'device_info' => '{"brand":"HONOR","manufacturer":"HONOR","model":"ALA-AN70","product":"ALA-AN70","osType":"android","osVersionName":"10","osVersionCode":29,"platformVersionName":"1.080","platformVersionCode":1080,"language":"zh","region":"CN","screenWidth":1080,"screenHeight":2122,"timeZone":"GMT+08:00","emuiApiLevel":"26","emuiVer":"11.0.1","vendorOsName":"magicUI","vendorOsVersion":"11.0.1","fontScale":1,"characteristics":"default","windowWidth":1080,"windowHeight":1978,"cutout":[{"left":501,"top":0,"right":501,"bottom":2238}],"statusBarHeight":102,"pixelRatio":3,"engineProvider":"huawei","screenDensity":3,"screenLogicWidth":750,"screenLogicHeight":1474,"windowLogicWidth":750,"windowLogicHeight":1374,"marketingName":"荣耀V40轻奢版","harmonyOSVer":""}',
            'device_no' => 'a682b826a7ce46473f30e238647fa38b983f03605a792d0492f561f075c61424',
            'package' => 'com.beidao.kuaiying.haohan',
            'send_order_id' => '',
            'timestamp' => '1646118354',
            'sign' => 'd1192936959b3c79be1e1582f7b7c27f',
            '_url' => '/api/login',
        );
        if ($timestamp && $sign == _sign($params, $key)) {
            dd(1);
        } else {
            dd(2,$sign,_sign($params, $key));
        }
        $bid   = $this->argument('bid');
        $enBid = Hashids::encode($bid);

        $enHotBids = array_map(function ($bid) {
            return Utils::getEncodeId($bid);
        }, [$bid]);

        dd($bid, $enBid, $enHotBids);
    }
}