|
这是快手的图床接口- curl -H "Content-Type: application/json" -X POST -d '{"mediaType":"image","token":"xxx","fileName":"图片地址","uploadSource":"app_cp"}' "https://onvideoapi.kuaishou.com/api/video/upload/complete_upload?source=cp&__redirectURL=https%3A%2F%2Fonvideo.kuaishou.com%2Fhub%2Fcreate%2Fmaterial%3Fsource%3Dcp" -H "Cookie: xxx" -H "Origin: https://onvideo.kuaishou.com" -H "Referer: https://onvideo.kuaishou.com/" -H "Host: onvideoapi.kuaishou.com"
复制代码
这是我最开始的写法
- <?php
- function PVUpload($file) {
- $post['file'] = file_path($file);
- $imgurl2 = get_curl($file,'https://onvideoapi.kuaishou.com/api/video/upload/complete_upload?source=cp&__redirectURL=https%3A%2F%2Fonvideo.kuaishou.com%2Fhub%2Fcreate%2Fmaterial%3Fsource%3Dcp', $post, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36');
- echo $file;
- $imgurl2 = json_decode($imgurl2, true);
- if(!empty($imgurl2)) {
- $imgurl= $imgurl2['data']['mediaUrl'];
- } else {
- $imgurl= '';
- }
- return $imgurl;
- }
- function get_curl($imgfile, $url, $post = 0, $ua = 0) {
- $img = $imgfile;
- $postData = array(
- "mediaType" => "image",
- "token" => "xxx",
- "fileName" => $img,
- "uploadSource" => "app_cp"
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
- // 不验证证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- // 最大执行时间
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
- curl_setopt($ch, CURLOPT_TIMEOUT, 120);
- $httpheader[] = "Content-Type: application/json";
- $httpheader[] = "Cookie: xxx";
- $httpheader[] = "Origin: https://onvideo.kuaishou.com";
- $httpheader[] = "Referer: https://onvideo.kuaishou.com/";
- $httpheader[] = "Host: onvideoapi.kuaishou.com";
- //$ip = mt_rand(48, 140) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240);
- //随机 ip
- //$httpheader[] = 'CLIENT-IP:' . $ip;
- //$httpheader[] = 'X-FORWARDED-FOR:' . $ip;
- curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
- //curl_setopt($ch, CURLOPT_ENCODING, "gzip");
- //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $ret = curl_exec($ch);
- curl_close($ch);
- return $ret;
- }
- function file_path($file) {
- if (class_exists('CURLFile')) {
- return $post['file'] = new \CURLFile(realpath($file));
- } else {
- return $post['file'] = '@' . realpath($file);
- }
- }
- ?>
复制代码
测试了很多遍,上传不了文件。来个大佬指点一下,谢谢!
|
|