| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | <?phpnamespace app\common\service;use fast\Random;use think\Exception;class UserService{    /**     * 获取请求参数     * @return void     */    public function faceAuth($params=[])    {        $result = [            'status' => 1,            'msg' => '获取成功',            'data' => [],        ];        try {            $idCard = isset($params['id_card']) ? $params['id_card'] : '';            $realName = isset($params['real_name']) ? $params['real_name'] : '';            $tencentConfig = config('tencent_im');            $sercrtId = isset($tencentConfig['SecretId']) ? $tencentConfig['SecretId'] : '';            $sercrtKey = isset($tencentConfig['SecretKey']) ? $tencentConfig['SecretKey'] : '';            //获取token            $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.$sercrtId.'&secret='.$sercrtKey.'&grant_type=client_credential&version=1.0.0';            $token_result = file_get_contents($token_url);            if (!$token_result) {                throw new Exception('您的网络开小差啦1~');            }            $token_result = json_decode($token_result, true);echo '<pre>';var_dump($token_result);exit;            if ($token_result['code'] != 0) {                throw new Exception('您的网络开小差啦2~');            }            $token = $token_result['access_token'];            //获取签名鉴权参数ticket            $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.$sercrtId.'&access_token='.$token.'&type=SIGN&version=1.0.0';            $ticket_result = file_get_contents($ticket_url);            if (!$ticket_result) {                throw new Exception('您的网络开小差啦3~');            }            $ticket_result = json_decode($ticket_result, true);            if ($ticket_result['code'] != 0) {                throw new Exception('您的网络开小差啦4~');            }            $ticket = $ticket_result['tickets'][0]['value'];            //获取签名            $sign_data = [                'wbappid' => $sercrtId,                'userId'  => (string)$this->auth->id,                'version' => '1.0.0',                'ticket'  => $ticket,                'nonce'   => Random::alnum(32)            ];            asort($sign_data);//排序            $sign_string = join('', $sign_data);            $sign = sha1($sign_string);            //上传身份信息            $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识            $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo='.$orderNo;            $data = [                'webankAppId' => $sercrtId,                'orderNo' => $orderNo,                'userId' => (string)$this->auth->id,                'name' => $realName,//姓名                'idNo' => $idCard,//证件号                'version' => '1.0.0',                'sign' => $sign,                'nonce' => $sign_data['nonce']            ];            $res = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);            echo '<pre>';var_dump($res);exit;            $result['data'] = $res;        } catch (Exception $e) {            $result['status'] = 0;            $result['msg'] = $e->getMessage();        }        return $result;    }}
 |