广告投放-百度

百度广告投放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);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值