<?php

namespace app\taobao\controller;

use Jdcloud\Credentials\Credentials;
use Jdcloud\Result;
use Jdcloud\Cloudauth\CloudauthClient;
use app\api\model\User;

class Publicget
{ 
    private function getCred(){
        $ak = "JDC_A3B38E573D7404F976472FB42F52";
        $sk = "C9BAE98F49B42DA2DC02868A75AA3AD8";
        $cred = new Credentials($ak, $sk);
        return $cred;
    }

    public function getResult() {
        

        $id_code = $_GET['id_code'];
        $user = new User;
        $user_one_info = $user->getNewOne('certify_id,Id',['id_code'=>$id_code]);


        $client = new CloudauthClient([
            'credentials'  => $this->getCred(),
            'version' => 'latest',
            'scheme' => 'http'
        ]);
        
        $res = $client->GetAliveResult([
            'token'  => $user_one_info['certify_id'],
        ]);

        if ($res['result']['h5Result'] == 'ok' && $res['result']['smResult'] == 'ok' && $res['result']['rxResult'] == 'ok') {


            $update_one = [
                'is_verify' => 1
            ];
            $user->updateOne(['Id'=>$user_one_info['Id']],$update_one);

            echo '<h1>实名认证成功</h1></br>';
            die;
        } else {
            echo '<h1>'.$res['result']['desc'].'</h1></br>';
        }

        if (!isset($res['result']) ) {
            echo "<h1>实名认证超时，请重新认证</h1></br>";
        }
    }

}