<?php


namespace App\Http\Controllers\Api;


use App\Models\DynamicModel;
use App\Models\User;
use App\Models\UserInfoModel;
use App\Services\JPushService;
use App\Services\TencentImAccountService;
use App\Services\TencentImFriendService;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Util\Exception;

class TestController
{
    public function creat_user(){
        return response()->json(['message'=>"暂时无法使用"]);
        $total = 1000;

        for ($i=0;$i<$total;$i++){
            $ins = array();
            $ins['mobile'] = '199'.rand(10000000,99999999);
            $ins['password'] = '123456';
            $ins['pid'] = 0;
            $ins['sex'] = rand(1,2);
            $ins['is_vip'] = rand(0,1);
            $ins['is_auth'] = 1;
            $ins['ycode'] = create_invite_code();
            $ins['latitude'] = '30.'.rand(100000,999999);//30.720653
            $ins['longitude'] = '103.'.rand(100000,999999);//103.720653
            $ins['online'] = rand(0,1);
            $ins['notice_status'] = 1;
            $user = User::query()->firstOrCreate($ins);
            $ins_info = array();
            $ins_info['user_id'] = $user->id;
            $ins_info['avatar'] = 'https://zhengda.oss-accelerate.aliyuncs.com/chengluApp/image_picker977203985037292577.jpg';
            $ins_info['nickname'] = '用户'.$user->id;
            $ins_info['birthday'] = rand(1980,2010).'-'.rand(1,12).'-'.rand(1,28);
            $ins_info['height'] = rand(140,190);
            $ins_info['weight'] = rand(30,100);
            $ins_info['work'] = ['学生','老师','程序员','工程师'][rand(0,3)];
            $ins_info['info'] = '这是个人介绍';
            $ins_info['area'] = '成都市';
            $ins_info['area_code'] = '510100';
            $ins_info['figure'] = '健美';
            $ins_info['feeling'] = '单身';
            $ins_info['education'] = '本科';
            $ins_info['income'] = '10-30W';
            $ins_info['hobby'] = '火锅,音乐,k歌,蹦迪';
            $ins_info['drink'] = '饮酒';
            $ins_info['photo'] = json_encode(['https://zhengda.oss-accelerate.aliyuncs.com/chengluApp/image_picker977203985037292577.jpg','https://zhengda.oss-cn-chengdu.aliyuncs.com/chengluApp/img/%E4%B8%8B%E8%BD%BD.jpg','https://zhengda.oss-cn-chengdu.aliyuncs.com/chengluApp/img/u%3D3564444755%2C3599870531%26fm%3D26%26gp%3D0.jpg']);
            $ins_info['video'] = json_encode(['https://zhengda.oss-cn-chengdu.aliyuncs.com/chengluApp/a69ce78c4898a7bcf13138bbea71608f.mp4']);
            UserInfoModel::query()->create($ins_info);
        }
        echo  'success';
    }

    public function juzi(){
        return [
            '坎坷路途,给身边一份温暖。生活,本就是体谅和理解,把快乐装在心中,静静融化,慢慢扩散',
            '梦想也许在今天无法实现,但重要的是,它在你心里。重要的是,你一直在努力',
            '奋斗的意义,不在于,一定会让你取得多大的成就,只是让你在平凡的日子里,活得比原来的那个',
            '心若年轻,岁月不老。那些偷偷溜走的时光,沧桑了我们的容颜,却丰盈了我们的人生。即使青春不',
            '人生,就要活得漂亮,走得铿锵。自己不奋斗,终归是摆设。无论你是谁,宁可做拼搏的失败者,也',
        ];
    }

    public function create_dynamic(){
        return response()->json(['message'=>"暂时无法使用"]);
        $total = 100;
        for ($i=0;$i<$total;$i++){
            $ins = array();
            $ins['user_id'] = rand(30,900);
            $ins['content'] = $this->juzi()[rand(0,4)];
            $ins['img_url'] = json_encode([
                'https://zhengda.oss-cn-chengdu.aliyuncs.com/chengluApp/img/u%3D3870964477%2C3746012709%26fm%3D26%26gp%3D0.jpg',
                'https://zhengda.oss-cn-chengdu.aliyuncs.com/chengluApp/img/%E4%B8%8B%E8%BD%BD.jpg',
                'https://zhengda.oss-accelerate.aliyuncs.com/chengluApp/image_picker977203985037292577.jpg',
                'https://zhengda.oss-accelerate.aliyuncs.com/chengluApp/image_picker977203985037292577.jpg'
            ]);
            $ins['type'] = 1;
            $ins['status'] = 1;
            $ins['site'] = json_encode(["city"=>"成都市","lat"=>"30.720653","lng"=>"103.899019"]);
            $ins['tag'] = rand(1,10);

            DynamicModel::query()->create($ins);
        }
    }

    public function test_push(){
        $users_info = UserInfoModel::query()->get();
        foreach ($users_info as $item){
            if(!empty($item->photo)){
                $photo = json_decode($item->photo,true);
                if(count($photo)>0){
                    foreach ($photo as $k=>$v){
                       $photo[$k]['state'] = (empty($v['state']) || $v['state']==0)? 0: (int) $v['state'];
                    }
                    $item->photo = json_encode($photo);
                    $item->save();
                }
            }
        }

//        try {
//            $res = JPushService::pushNotify([
//                //标题
//                'title' => '测试',
//                //内容
//                'content' => '测试',
//                //设备标识，跟设备相关
//                'reg_id' => 'xxxxxxxxxxx',
//                //扩展字段
//                'extras' => [
//                    'key' => 'value',
//                ],
//                //推送类型
//                'type' => JPushService::PUSH_TYPE_ALL,
//            ]);
//        }catch (\Exception $exception){
//            return response()->json(['msg'=>$exception->getMessage()]);
//        }
//        return response()->json(['data'=>$res]);
    }

    public function jg_auth(){

//       $tencent = new TencentImAccountService();
//       $arr = array();
//        for ($i=1;$i<100;$i++){
//            $ar = array();
//            $ar['UserID'] = 'IM_USER_TEST_'.$i;
//            $arr[]=json_encode($ar);
//        }
//        $res = $tencent->accountDelete($arr);
//        dd($res);

        $tencent = new TencentImFriendService();
        $res = $tencent->friendCheck('IM_USER_TEST_2_75',['IM_USER_TEST_2_80']);
        dd($res);

        dd(GetDistance(30.720518,103.998353,30.721384,103.996072));

        die;
        $token="asdasd";
        $exId="111111";
         $ret = JPushService::jgLoginTokenVerify($token,$exId);
         dd($ret);

         $res = JPushService::jgOpensslPrivateDecrypt($ret['phone']);
    }


}
