From affb5a38272a5d43b41263947203358f9900e6f7 Mon Sep 17 00:00:00 2001 From: net909 Date: Mon, 14 Jul 2025 12:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9B=BE=E5=BA=8A=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/utility/imghosting/api/baidu.php | 28 +++++ plugin/utility/imghosting/api/cdn58.php | 126 +++++++++++++++++++-- plugin/utility/imghosting/api/dianping.php | 67 ----------- plugin/utility/imghosting/api/imgdd.php | 2 +- plugin/utility/imghosting/api/locimg.php | 39 ++++++- plugin/utility/imghosting/api/netease.php | 28 ----- plugin/utility/imghosting/api/oppo.php | 28 ----- plugin/utility/imghosting/api/pngcm.php | 31 ----- plugin/utility/imghosting/api/ucloud.php | 27 ----- plugin/utility/imghosting/api/vipkid.php | 28 ----- plugin/utility/imghosting/index.html | 10 +- 11 files changed, 182 insertions(+), 232 deletions(-) create mode 100644 plugin/utility/imghosting/api/baidu.php delete mode 100644 plugin/utility/imghosting/api/dianping.php delete mode 100644 plugin/utility/imghosting/api/netease.php delete mode 100644 plugin/utility/imghosting/api/oppo.php delete mode 100644 plugin/utility/imghosting/api/pngcm.php delete mode 100644 plugin/utility/imghosting/api/ucloud.php delete mode 100644 plugin/utility/imghosting/api/vipkid.php diff --git a/plugin/utility/imghosting/api/baidu.php b/plugin/utility/imghosting/api/baidu.php new file mode 100644 index 0000000..af7663b --- /dev/null +++ b/plugin/utility/imghosting/api/baidu.php @@ -0,0 +1,28 @@ +setPostFilename($filename); + $param = [ + 'file' => $file, + ]; + $cookie = 'BDUSS=3plTHA0aHpRNGI3MmIxTkpmNVpWTTYtLXpVWjlaRjdRQzFsNmxQNlNufkRiWGhvSVFBQUFBJCQAAAAAAAAAAAEAAAB5WXC40tfDzsTPs8cAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMPgUGjD4FBoS'; + $data = get_curl($url,$param,$referer, $cookie); + $arr = json_decode($data,true); + if(isset($arr['link'])){ + $imgurl = str_replace('.cdn.bcebos.com', '.bj.bcebos.com', $arr['link']); + return ['url'=>$imgurl]; + }else{ + throw new Exception('上传失败!接口错误'); + } + } +} \ No newline at end of file diff --git a/plugin/utility/imghosting/api/cdn58.php b/plugin/utility/imghosting/api/cdn58.php index ef771a4..920a20d 100644 --- a/plugin/utility/imghosting/api/cdn58.php +++ b/plugin/utility/imghosting/api/cdn58.php @@ -8,21 +8,123 @@ use plugin\utility\imghosting\api; class cdn58 implements api { public function upload($filepath, $filename){ - $url = 'https://upload.58cdn.com.cn/json/nowater/webim/big/'; - $referer = 'https://ai.58.com/pc/'; - $imgdata = base64_encode(file_get_contents($filepath)); - $params = [ - 'Pic-Data' => $imgdata, - 'Pic-Encoding' => 'base64', - 'Pic-Path' => '/nowater/webim/big/', - 'Pic-Size' => '0*0' + $file_ext = pathinfo($filename, PATHINFO_EXTENSION); + if(!in_array($file_ext, ['jpg','jpeg','png','gif','bmp'])) throw new Exception('上传失败!不支持的文件格式'); + + $user_id = '58Anonymous'.$this->guid(); + $user_info = [ + 'user_id' => $user_id, + 'source' => '14', + 'im_token' => $user_id, + 'client_version' => '1.0', + 'client_type' => 'pcweb', + 'os_type' => 'Chrome', + 'os_version' => '122.0.6261.95', + 'appid' => '10140-mcs@jitmouQrcHs', + 'extend_flag' => '0', + 'unread_index' => '1', + 'sdk_version' => '6432', + 'device_id' => $user_id, + 'xxzl_smartid' => '', + 'id58' => 'CkwAd2e0U3tBNxbRAzQ2Ag==', ]; - $data = get_curl($url,json_encode($params),$referer,0,0,0,0,['application/json']); - if(strpos($data, 'n_v2')!==false){ - $imgurl = 'https://pic'.rand(1,8).'.58cdn.com.cn/nowater/webim/big/'.$data; + $params = http_build_query($user_info); + $params = $this->encrypt($params); + + $post = [ + 'sender_id' => $user_id, + 'sender_source' => 14, + 'to_id' => '10002', + 'to_source' => 100, + 'file_suffixs' => [$file_ext], + ]; + $post = json_encode($post); + $post = $this->encrypt($post); + + $url = 'https://im.58.com/msg/get_pic_upload_url?params='.$params.'&version=j1.0'; + $referer = 'https://ai.58.com/pc/'; + $ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36'; + $data = get_curl($url,$post,$referer,0,0,$ua,0,['Content-Type: text/plain;charset=UTF-8', 'Origin: https://ai.58.com']); + $arr = json_decode($data, true); + if(isset($arr['error_code']) && $arr['error_code']==0){ + if(empty($arr['data']['upload_info'])) throw new Exception('上传失败!未返回上传地址'); + $url = $arr['data']['upload_info'][0]['url']; + }else{ + throw new Exception('上传失败!'.(isset($arr['error_msg']) ? $arr['error_msg'] : '接口错误')); + } + + $mine_type = $this->mime_content_type($file_ext); + [$httpCode, $header, $body] = $this->curl_upload($url, file_get_contents($filepath), ['Content-Type: '.$mine_type]); + + if($httpCode == 200){ + $filename = getSubstr($url, '/nowater/im/', '?'); + $imgurl = 'https://pic'.rand(1,8).'.58cdn.com.cn/nowater/im/'.$filename; return ['url'=>$imgurl]; }else{ - throw new Exception('上传失败!接口错误'); + throw new Exception('上传失败!httpCode='.$httpCode); } } + + private function mime_content_type($ext) + { + $mime_types = [ + 'png' => 'image/png', + 'jpeg' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'gif' => 'image/gif', + 'bmp' => 'image/bmp', + ]; + return isset($mime_types[$ext]) ? $mime_types[$ext] : 'application/octet-stream'; + } + + private function encrypt($data){ + $str = base64_encode($data); + $equal_count = substr_count($str, '='); + $str = str_replace(['+','/','='], ['-','_',''], $str).$equal_count; + $half = floor(strlen($str)/2); + $str = substr($str, $half).substr($str, 0, $half); + return $str; + } + + private function decrypt($data) { + $half = ceil(strlen($data)/2); + $data = substr($data, $half).substr($data, 0, $half); + $equal_count = substr($data, -1); + $data = substr($data, 0, -1); + $data = str_replace(['-', '_'], ['+', '/'], $data); + $data .= str_repeat('=', $equal_count); + return base64_decode($data); + } + + private function guid(){ + $guid = md5(uniqid(mt_rand(), true)); + return substr($guid,0,8).'-'.substr($guid,8,4).'-4'.substr($guid,12,3).'-'.substr($guid,16,4).'-'.substr($guid,20,12); + } + + private function curl_upload($url, $body, $header, $timeout = 10) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36'); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + $data = curl_exec($ch); + if (curl_errno($ch) > 0) { + $errmsg = curl_error($ch); + curl_close($ch); + throw new Exception($errmsg, 0); + } + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + $header = substr($data, 0, $headerSize); + $body = substr($data, $headerSize); + curl_close($ch); + return [$httpCode, $header, $body]; + } } \ No newline at end of file diff --git a/plugin/utility/imghosting/api/dianping.php b/plugin/utility/imghosting/api/dianping.php deleted file mode 100644 index a8b2d44..0000000 --- a/plugin/utility/imghosting/api/dianping.php +++ /dev/null @@ -1,67 +0,0 @@ -setPostFilename($filename); - $param = [ - 'files' => $file, - 'fileName' => $filename, - 'part' => '0', - 'partSize' => '1', - 'fileID' => time().rand(111,999) - ]; - $header = [ - 'CSC-VisitId: '.$this->getvisitid() - ]; - $data = get_curl($url,$param,'https://h5.dianping.com/',0,0,0,0,$header); - $arr = json_decode($data,true); - if(isset($arr['code']) && $arr['code'] == 200){ - $picurl = str_replace('http://','https://',$arr['data']['uploadPath']); - return ['url'=>$picurl]; - }elseif(isset($arr['errMsg'])){ - throw new Exception('上传失败!'.$arr['errMsg']); - }else{ - throw new Exception('上传失败!接口错误'); - } - } - - private function getvisitid(){ - $visitid = cache('dianping_visitid'); - if($visitid) return $visitid; - $url = 'https://kf.dianping.com/csCenter/access/dealOrder_Help_DP_PC'; - $url = $this->get_location_url($url); - if($url){ - $visitid = getSubstr($url, 'visitId=', '&'); - if($visitid){ - $url = 'https://kf.dianping.com/api/portal/message/init?visitId='.$visitid.'&accessToken=undefined'; - $post = '{"type":"Init","parameters":{"isPreview":true,"build":null}}'; - get_curl($url, $post); - cache('dianping_visitid', $visitid, 86400); - return $visitid; - } - } - throw new Exception('上传失败!获取visitId异常'); - } - - private function get_location_url($url){ - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"); - curl_exec($ch); - $final_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); - curl_close($ch); - return $final_url; - } -} \ No newline at end of file diff --git a/plugin/utility/imghosting/api/imgdd.php b/plugin/utility/imghosting/api/imgdd.php index eb56550..9a88e6a 100644 --- a/plugin/utility/imghosting/api/imgdd.php +++ b/plugin/utility/imghosting/api/imgdd.php @@ -8,7 +8,7 @@ use plugin\utility\imghosting\api; class imgdd implements api { public function upload($filepath, $filename){ - $url = 'https://imgdd.com/api/v1/upload'; + $url = 'https://imgdd.com/upload'; $referer = 'https://imgdd.com/'; $file = new \CURLFile($filepath); $file->setPostFilename($filename); diff --git a/plugin/utility/imghosting/api/locimg.php b/plugin/utility/imghosting/api/locimg.php index 181309b..dbcc425 100644 --- a/plugin/utility/imghosting/api/locimg.php +++ b/plugin/utility/imghosting/api/locimg.php @@ -8,14 +8,14 @@ use plugin\utility\imghosting\api; class locimg implements api { public function upload($filepath, $filename){ - $url = 'https://www.locimg.com/upload/upload.html'; - $referer = 'https://www.locimg.com/'; + $url = 'https://yunimg.cc/upload/upload.html'; + $referer = 'https://yunimg.cc/'; $file = new \CURLFile($filepath, 'image/jpeg', $filename); $param = [ 'image' => $file, 'fileId' => $filename, ]; - $data = get_curl($url,$param,$referer,0,0,0,0,['X-Requested-With: XMLHttpRequest']); + $data = $this->curl($url,$param,$referer,['X-Requested-With: XMLHttpRequest']); $arr = json_decode($data,true); if(isset($arr['data']['url'])){ return ['url'=>$arr['data']['url']]; @@ -25,4 +25,37 @@ class locimg implements api throw new Exception('上传失败!接口错误'); } } + + private function curl($url, $post=0, $referer=0, $addheader=0) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + /*curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); + curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1'); + curl_setopt($ch, CURLOPT_PROXYPORT, 10809); + curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);*/ + $httpheader[] = "Accept: */*"; + $httpheader[] = "Accept-Encoding: gzip,deflate,sdch"; + $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; + $httpheader[] = "Connection: close"; + if($addheader){ + $httpheader = array_merge($httpheader, $addheader); + } + curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); + if ($post) { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } + if($referer){ + curl_setopt($ch, CURLOPT_REFERER, $referer); + } + curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"); + curl_setopt($ch, CURLOPT_ENCODING, "gzip"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $ret = curl_exec($ch); + curl_close($ch); + return $ret; + } } \ No newline at end of file diff --git a/plugin/utility/imghosting/api/netease.php b/plugin/utility/imghosting/api/netease.php deleted file mode 100644 index 95f0add..0000000 --- a/plugin/utility/imghosting/api/netease.php +++ /dev/null @@ -1,28 +0,0 @@ -setPostFilename($filename); - $param = [ - 'file' => $file, - 'from' => 'neteasecode_mp', - ]; - $data = get_curl($url,$param,$url); - $arr = json_decode($data,true); - if(isset($arr['code']) && $arr['code']==200){ - return ['url'=>str_replace('http://','https://',$arr['data']['url'])]; - }elseif(isset($arr['msg'])){ - throw new Exception('上传失败请重试('.$arr['msg'].')'); - }else{ - throw new Exception('上传失败!接口错误'); - } - } -} \ No newline at end of file diff --git a/plugin/utility/imghosting/api/oppo.php b/plugin/utility/imghosting/api/oppo.php deleted file mode 100644 index 5d5bec4..0000000 --- a/plugin/utility/imghosting/api/oppo.php +++ /dev/null @@ -1,28 +0,0 @@ -setPostFilename($filename); - $param = [ - 'file' => $file, - 'type' => 'feedback', - ]; - $data = get_curl($url,$param,$url); - $arr = json_decode($data,true); - if(isset($arr['errno']) && $arr['errno']==0){ - return ['url'=>str_replace('store2.heytapimage.com', 'store.heytapimage.com', $arr['data']['url'])]; - }elseif(isset($arr['data']['message'])){ - throw new Exception('上传失败请重试('.$arr['data']['message'].')'); - }else{ - throw new Exception('上传失败!接口错误'); - } - } -} \ No newline at end of file diff --git a/plugin/utility/imghosting/api/pngcm.php b/plugin/utility/imghosting/api/pngcm.php deleted file mode 100644 index 3ff1ccb..0000000 --- a/plugin/utility/imghosting/api/pngcm.php +++ /dev/null @@ -1,31 +0,0 @@ -setPostFilename($filename); - $param = [ - 'name' => $filename, - 'uuid' => 'o_'.Str::random(27), - 'sign' => time(), - 'file' => $file, - ]; - $data = get_curl($url,$param,'https://png.cm/'); - $arr = json_decode($data,true); - if(isset($arr['code']) && $arr['code']==200){ - return ['url'=>$arr['url']]; - }elseif(isset($arr['message'])){ - throw new Exception('上传失败请重试('.$arr['message'].')'); - }else{ - throw new Exception('上传失败!接口错误'); - } - } -} \ No newline at end of file diff --git a/plugin/utility/imghosting/api/ucloud.php b/plugin/utility/imghosting/api/ucloud.php deleted file mode 100644 index 8588503..0000000 --- a/plugin/utility/imghosting/api/ucloud.php +++ /dev/null @@ -1,27 +0,0 @@ -setPostFilename($filename); - $param = [ - 'file' => $file, - ]; - $data = get_curl($url,$param,$url,0,0,0,0,['Authorization: UCloud TOKEN_12134567890']); - $arr = json_decode($data,true); - if(isset($arr['Files']) && !empty($arr['Files'])){ - return ['url'=>'https://uchat.cn-bj.ufileos.com/'.$arr['Files'][0]]; - }elseif(isset($arr['Message'])){ - throw new Exception('上传失败请重试('.$arr['Message'].')'); - }else{ - throw new Exception('上传失败!接口错误'); - } - } -} \ No newline at end of file diff --git a/plugin/utility/imghosting/api/vipkid.php b/plugin/utility/imghosting/api/vipkid.php deleted file mode 100644 index eb83dbe..0000000 --- a/plugin/utility/imghosting/api/vipkid.php +++ /dev/null @@ -1,28 +0,0 @@ -setPostFilename($filename); - $param = [ - 'file' => $file, - 'uploadType' => 'IM' - ]; - $data = get_curl($url,$param,$url,0,0,0,0,['vk-cr-code: kr']); - $arr = json_decode($data,true); - if(isset($arr['code']) && $arr['code']==200){ - return ['url'=>$arr['data']['url']]; - }elseif(isset($arr['msg'])){ - throw new Exception('上传失败请重试('.$arr['msg'].')'); - }else{ - throw new Exception('上传失败!接口错误'); - } - } -} \ No newline at end of file diff --git a/plugin/utility/imghosting/index.html b/plugin/utility/imghosting/index.html index bb77046..b9ce2f9 100644 --- a/plugin/utility/imghosting/index.html +++ b/plugin/utility/imghosting/index.html @@ -96,17 +96,13 @@ textarea.form-control{min-height: auto;} el: '#app', data: { apitypes: [ - { - title: 'Ucloud', - key: 'ucloud' - }, { title: '58同城', key: 'cdn58' }, { - title: 'LOCIMG', - key: 'locimg' + title: '百度文库', + key: 'baidu' }, { title: 'IMGDD', @@ -145,7 +141,7 @@ textarea.form-control{min-height: auto;} ] }, output: [], - apitype: 'ucloud', + apitype: 'baidu', imgurl: '' }, progress: 0,