百度广告投放Api
视频上传
/**
* 上传视频
* @param $advertiser_id
* @param string $access_token
* @param $filename
* @param $file_url
* @return array|mixed
*/
static public function uploadVideo($userName,$access_token,$filename,$file_url,$md5_file ='')
{
// $mt = explode(' ', microtime());
// $m = $mt[0] * 1000;
// $time_mic_begin = $mt[1].$m;
$headers = [
'Content-Type'=>'multipart/form-data'
];
$url = self::URI . 'json/sms/service/VideoUploadService/addVideo';
$params_json = [
'videoName'=> $filename,
'source'=>2,
'format'=>'mp4',
// 'httpProtocol'=>'HTTPS',
];
$fields = [
'userName' => $userName,
'accessToken' => $access_token,
// 'signature' => md5_file($file_url),
'signature' => $md5_file??md5_file($file_url), // 9bf3662424d1de88591a6779dc31f563
// 'signature' => '9bf3662424d1de88591a6779dc31f563', // 9bf3662424d1de88591a6779dc31f563
// 'params' => json_encode([
// 'videoName' => '',
// 'source' => 2,
// 'format' => 'mp4'
// ]),
'params' =>json_encode($params_json),
'file' => new \CURLFile($file_url)
];
// pp($fields);
// $mt = explode(' ', microtime());
// $m = $mt[0] * 1000;
// $time_mic_end = $mt[1].$m;
// $user_mictime = $time_mic_end-$time_mic_begin;
// pp($user_mictime);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 设置请求的内容类型为multipart/form-data
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
// $mt = explode(' ', microtime());
// $m = $mt[0] * 1000;
// $time_mic_end2 = $mt[1].$m;
// $user_mictime2 = $time_mic_end2-$time_mic_end;
// pp($user_mictime2);
// $user_mictime122 = $time_mic_end2-$time_mic_begin;
// pp($user_mictime122);
return json_decode($response,true);
}