签名
代码语言:javascript复制$appid = config('YUN_APP_ID');
$bucket = '';
$secret_id = config('YUN_SECRET_ID');
$secret_key = config('YUN_SECRET_KEY');
$expired = time() 2592000;
$current = time();
$rdm = rand();
//$fileid = 'getAuthAuto';
$srcStr = 'a='.$appid.'&b='.$bucket.'&k='.$secret_id.'&e='.$expired.'&t='.$current.'&r='.$rdm.'&f=';
$signStr = base64_encode(hash_hmac('SHA1',$srcStr,$secret_key,true).$srcStr);
return $signStr;
curl方法:
代码语言:javascript复制$ch = curl_init();
//设置我们请求的地址
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
//数据返回后不要直接显示
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
//禁止证书校验
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
if ( $content ) {
curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $content);
}
$data = array();
if ( curl_exec( $ch ) ) {
//发送成功,获取数据
$data = curl_multi_getcontent( $ch );
}
curl_close( $ch );
return $data;
请求:
代码语言:javascript复制$img_url = input('post.img_url');
$header = array("Host:recognition.image.myzijiebao.com","Content-type:application/json","authorization:".$this->getAuthAuto());
$res = array(
'appid' => config('YUN_APP_ID'),
'bucket' => '',
'url_list' => array(
$img_url,
),
);
$url = 'https://recognition.image.myzijiebao.com/ocr/businesscard';
$str = $this->tocurl($url,$header,json_encode($res));
$result = json_decode($str,true);