| ????????$url ? ? ? ? ? ? ? ? ? ? ? ?= 'https://aip.baidubce.com/oauth/2.0/token';//地址? ? ? ? $post_data['grant_type'] ? ?= 'client_credentials';
 ? ? ? ? $post_data['client_id'] ? ? = 'xxxx';
 ? ? ? ? $post_data['client_secret'] = 'xxxx';
 ? ? ? ? $o ? ? ? ? ? ? ? ? ? ? ? ? ?= "";
 ? ? ? ? foreach ($post_data as $k => $v) {
 ? ? ? ? ? ? $o .= "$k=" . urlencode($v) . "&";
 ? ? ? ? }
 ? ? ? ? $post_data ? = substr($o, 0, -1);
 ? ? ? ? $res ? ? ? ? = $this->request_post($url, $post_data);
 ? ? ? ? $token ? ? ? = json_decode($res, true)['access_token'];
 ? ? ? ? $verify_info = $this->http_post("https://aip.baidubce.com/rpc/2.0/brain/solution/faceprint/verifyToken/generate?access_token=" . $token, ['plan_id' => 13472]);
 ? ? ? ? if ($verify_info['success'] == '') {
 ? ? ? ? ? ? returnApi($verify_info['message']);
 ? ? ? ? } else {
 ? ? ? ? ? ? $verify_token = $verify_info['result']['verify_token'];
 ? ? ? ? }
 ? ? ? ? $userinfo = $this->http_post("https://brain.baidu.com/solution/faceprint/idcard/submit", ['verify_token' => $verify_token, 'id_name' => app('user')->real_name, 'id_no' => app('user')->idcard]);
 ? ? ? ? if ($userinfo['success'] == '') {
 ? ? ? ? ? ? returnApi($userinfo['message']);
 ? ? ? ? }
 ? ? ? ? require_once '../extend/phpqrcode/phpqrcode.php';
 ? ? ? ? $object ? ? ? ? ? ? ? = new \QRcode();
 ? ? ? ? $errorCorrectionLevel = 'L'; //容错级别
 ? ? ? ? $matrixPointSize ? ? ?= 5; //生成图片大小
 ? ? ? ? //打开缓冲区
 ? ? ? ? ob_start();
 ? ? ? ? $data = "https://brain.baidu.com/face/print/?token=" . $verify_token . "&successUrl=http://xxx.cn/home/disend/seccess/&failedUrl=http://xxxx";
 ? ? ? ? //生成二维码图片
 ? ? ? ? $returnData = $object->png($data, false, $errorCorrectionLevel, $matrixPointSize, 2);
 ? ? ? ? //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
 ? ? ? ? $imageString = base64_encode(ob_get_contents());
 ? ? ? ? //关闭缓冲区
 ? ? ? ? ob_end_clean();
 ? ? ? ? $base64 = "data:image/png;base64," . $imageString;
 ? ?
 ? ? public function request_post($url = '', $param = '')? ? {
 ? ? ? ? if (empty($url) || empty($param)) {
 ? ? ? ? ? ? return false;
 ? ? ? ? }
 ? ? ? ? $con = file_get_contents($url . '?' . $param);
 ? ? ? ? return $con;
 ? ? }
 ? ? public function http_post($url, $data_string)? ? {
 ? ? ? ? $ch = curl_init();
 ? ? ? ? curl_setopt($ch, CURLOPT_URL, $url);
 ? ? ? ? curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 ? ? ? ? curl_setopt($ch, CURLOPT_HTTPHEADER, array(? ? ? ? ? ? 'X-AjaxPro-Method:ShowList',
 ? ? ? ? ? ? 'Content-Type: application/json; charset=utf-8',
 ? ? ? ? ? ? 'Content-Length: ' . strlen(json_encode($data_string)))
 ? ? ? ? );
 ? ? ? ? curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 ? ? ? ? curl_setopt($ch, CURLOPT_POST, 1);
 ? ? ? ? curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data_string));
 ? ? ? ? $data = curl_exec($ch);
 ? ? ? ? curl_close($ch);
 ? ? ? ? return json_decode($data, true);
 ? ? }
 |