获取access_token
<?php
declare (strict_types = 1);
namespace app\API\controller;
use think\Request;
use app\API\service\BaiduApi;
class Employee
{
public function EmployeeSel()
{
$url = 'https://aip.baidubce.com/oauth/2.0/token';
$post_data['grant_type'] = 'client_credentials';
$post_data['client_id'] = '4lgdMQaC2ckr8HMT8CUFhGXn';
$post_data['client_secret'] = 'HRPrMoPhgteU53vl04BAm4gr1OM4xqk9';
$o = "";
foreach ( $post_data as $k => $v )
{
$o.= "$k=" . urlencode( $v ). "&" ;
}
$post_data = substr($o,0,-1);
$date = BaiduApi::request_post($url,$post_data);
//搜索所呈现的sql语句 取出access_token 有效期三十天 可以放心使用
return $date;
}
}
服务层封装方法 找到access_token