更新图床工具
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
|
||||
class baidu implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'https://wenku.baidu.com/user/api/editorimg';
|
||||
$referer = 'https://wenku.baidu.com/';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->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('上传失败!接口错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
|
||||
class dianping implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'https://kf.dianping.com/api/file/burstUploadFile';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
|
||||
class netease implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'http://upload.buzz.163.com/picupload';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->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('上传失败!接口错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
|
||||
class oppo implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'https://api.open.oppomobile.com/api/utility/upload';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->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('上传失败!接口错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
use think\helper\Str;
|
||||
|
||||
class pngcm implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'https://png.cm/app/upload.php';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->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('上传失败!接口错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
|
||||
class ucloud implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'https://spt.ucloud.cn/im/client/upload';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->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('上传失败!接口错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
|
||||
class vipkid implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'https://www.vipkid.com/rest/gw/api/upload/vos';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->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('上传失败!接口错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user