Initial commit

This commit is contained in:
net909
2023-09-28 16:21:06 +08:00
parent 498772eb04
commit ba7be004c0
640 changed files with 87745 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
<?php
/**
* QQ高速图床
*/
namespace plugin\utility\imghosting;
use app\Plugin;
use think\facade\Request;
use think\facade\Db;
use Exception;
class App extends Plugin
{
public function index()
{
return $this->view();
}
public function upload(){
if(!isset($_FILES['file']))return json(['code'=>-1, 'msg'=>'请选择文件']);
$filepath = $_FILES["file"]["tmp_name"];
$filename = $_FILES["file"]["name"];
if($_FILES['file']['error']>0 || $filepath == ""){
return json(['code'=>-1, 'msg'=>'文件损坏!']);
}
if($_FILES['file']['size']>10*1024*1024){
return json(['code'=>-1, 'msg'=>'文件最大10M']);
}
$apitype = input('?post.apitype')?input('post.apitype'):'qq';
$classname = 'plugin\\utility\\imghosting\\api\\'.$apitype;
if(class_exists($classname)){
$instance = new $classname();
try{
$result = $instance->upload($filepath, $filename);
Db::name('uploadlog')->insert([
'uid' => request()->islogin ? request()->user['id'] : 0,
'type' => 'image',
'source' => $apitype,
'filename' => $filename,
'fileurl' => $result['url'],
'ip' => $this->clientip,
'addtime' => date("Y-m-d H:i:s")
]);
return json(['code'=>0, 'msg'=>'success', 'data'=>$result]);
}catch(Exception $e){
return json(['code'=>-1, 'msg'=>$e->getMessage()]);
}
}else{
return json(['code'=>-1, 'msg'=>'该上传类型不存在']);
}
}
public function uploadurl(){
exit;
$url = input('post.url');
if(!$url) return json(['code'=>-1, 'msg'=>'no url']);
$apitype = input('?post.apitype')?input('post.apitype'):'qq';
$file_data = get_curl($url);
if(!$file_data) return json(['code'=>-1, 'msg'=>'获取图片数据失败']);
$filepath = tempnam(sys_get_temp_dir(), 'IMG');
file_put_contents($filepath, $file_data);
$filename = time().'.jpg';
$classname = 'plugin\\utility\\imghosting\\api\\'.$apitype;
if(class_exists($classname)){
$instance = new $classname();
try{
$result = $instance->upload($filepath, $filename);
unlink($filepath);
Db::name('uploadlog')->insert([
'uid' => request()->islogin ? request()->user['id'] : 0,
'type' => 'image',
'source' => $apitype,
'filename' => $filename,
'fileurl' => $result['url'],
'ip' => $this->clientip,
'addtime' => date("Y-m-d H:i:s")
]);
return json(['code'=>0, 'msg'=>'success', 'data'=>$result]);
}catch(Exception $e){
unlink($filepath);
return json(['code'=>-1, 'msg'=>$e->getMessage()]);
}
}else{
unlink($filepath);
return json(['code'=>-1, 'msg'=>'该上传类型不存在']);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace plugin\utility\imghosting;
interface api
{
public function upload($filepath, $filename);
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace plugin\utility\imghosting\api;
use Exception;
use plugin\utility\imghosting\api;
class cdn58 implements api
{
public function upload($filepath, $filename){
$url = 'https://upload.58cdn.com.cn/json';
$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'
];
$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;
return ['url'=>$imgurl];
}else{
throw new Exception('上传失败!接口错误');
}
}
}
@@ -0,0 +1,64 @@
<?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){
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;
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace plugin\utility\imghosting\api;
use Exception;
use plugin\utility\imghosting\api;
class imgdd implements api
{
public function upload($filepath, $filename){
$url = 'https://imgdd.com/api/v1/upload';
$referer = 'https://imgdd.com/';
$file = new \CURLFile($filepath);
$file->setPostFilename($filename);
$param = [
'image' => $file,
];
$data = get_curl($url,$param,$referer);
$arr = json_decode($data,true);
if(isset($arr['url'])){
return ['url'=>$arr['url']];
}elseif(isset($arr['message'])){
throw new Exception('上传失败请重试('.$arr['message'].'');
}else{
throw new Exception('上传失败!接口错误');
}
}
}
+28
View File
@@ -0,0 +1,28 @@
<?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('上传失败!接口错误');
}
}
}
+28
View File
@@ -0,0 +1,28 @@
<?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('上传失败!接口错误');
}
}
}
+31
View File
@@ -0,0 +1,31 @@
<?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('上传失败!接口错误');
}
}
}
+28
View File
@@ -0,0 +1,28 @@
<?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('上传失败!接口错误');
}
}
}
+329
View File
@@ -0,0 +1,329 @@
{extend name="common/plugin_layout" /}
{block name="title"}{$plugin.title} - {:config_get('title')}{/block}
{block name="main"}
<style>
.btn-block {
white-space:normal;
}
.btn-active {background-color: #1c2b46;color: #fff;}
textarea.form-control{min-height: auto;}
</style>
<div class="container-xl" id="app">
<div class="col-sm-12 col-md-10 col-xl-9 center-block">
<div class="card card-preview">
<div class="card-inner mt-3">
<div class="nya-title nk-ibx-action-item progress-rating">
<span class="nk-menu-text font-weight-bold">聚合高速图床</span>
</div>
<div class="form-group">
<label class="form-label" for="input">选择图床接口:</label>
<div class="form-control-wrap">
<div class="custom-control custom-radio mr-3 mt-1" v-for="(item,index) in apitypes" :key="index">
<input type="radio" class="custom-control-input" v-model="set.apitype" name="set.apitype" :id="item.key" :value="item.key">
<label class="custom-control-label" :for="item.key">{{item.title}}</label>
</div>
</div>
</div>
<div class="progress progress-lg mt-2 mb-1">
<div class="progress-bar progress-bar-striped progress-bar-animated" v-bind:style="{ width: progress + '%' }">{{progress}}%</div>
</div>
<div class="form-group">
<div class="text-center pt-5 pb-5 btn btn-lg btn-block btn-outline-light mb-1 d-block" id="fileInput">
<div class="preview-icon-wrap"><em class="ni ni-upload"></em></div><span>点击选择文件/Ctrl+V粘贴/拖拽到此处</span>
<input type="file" id="file" accept="image/*" multiple="multiple" style="opacity: 0;position: absolute;cursor: pointer;width: 100%;height: 100%;left: 0;top: 0;" @change="selectFile">
</div>
{if false}<button class="btn btn-outline-light btn-block" data-toggle="modal" data-target="#inputurl">填写图片URL上传</button>{/if}
</div>
<div class="form-group">
<div class="btn-group">
<button v-for="v in set.output_types.items" class="btn btn-outline-dark btn-sm"
:class="{'btn-active':set.output_types.current===v.key}"
@click="set.output_types.current=v.key"
>
{{v.title}}
</button>
</div>
<div class="form-control-wrap">
<textarea class="form-control" id="output" v-model="result" rows="8" placeholder="这里显示上传的结果"></textarea>
</div>
<div class="text-center"><button class="btn btn-sm btn-outline-light" @click="copy"><em class="icon ni ni-copy"></em>点此复制</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-sm btn-outline-light" @click="reset"><em class="icon ni ni-reload"></em>清空</button></div>
</div>
</div>
</div>
<div class="card card-preview">
<div class="card-inner">
<h6><em class="icon ni ni-info"></em> 工具说明</h6>
<div class="accordion-inner">
<p>文件格式支持:jpg,jpeg,png,gif,webp,大小不能超过10M</p>
<p>OPPO:图片域名store.heytapimage.com,原图无压缩</p>
<p>58同城:图片域名58cdn.com.cn,原图无压缩</p>
<p>大众点评:图片域名p1.meituan.net,原图无压缩</p>
</div>
</div>
</div>
</div>
{if false}<div class="modal fade" id="inputurl" tabindex="-1" aria-labelledby="helpLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="helpLabel">填写图片URL上传</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<div class="form-control-wrap">
<textarea class="form-control imgurl" v-model="set.imgurl" rows="3" placeholder="填写图片URL"></textarea>
</div>
</div>
<button class="btn btn-dim btn-outline-primary btn-block" @click="uploadimgurl">
<em class="icon ni ni-upload"></em>立即上传
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>{/if}
</div>
{/block}
{block name="script"}
<script src="{$cdn_cdnjs}vue/2.6.14/vue.min.js"></script>
<script src="{$cdn_cdnjs}jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
new Vue({
el: '#app',
data: {
apitypes: [
{
title: '大众点评',
key: 'dianping'
},
{
title: 'OPPO',
key: 'oppo'
},
{
title: 'VIPKID',
key: 'vipkid'
},
{
title: '简单图床',
key: 'pngcm'
},
{
title: 'IMGDD',
key: 'imgdd'
},
],
set: {
output_types: {
current: 'URL',
items: [
{
title: 'URL',
key: 'URL',
template: '#url#',
},
{
title: 'HTML',
key: 'HTML',
template: '<img src="#url#"/>',
},
{
title: 'BBCode',
key: 'BBCode',
template: '[img]#url#[/img]',
},
{
title: 'Markdown',
key: 'Markdown',
template: '![](#url#)',
},
{
title: 'Markdown&Link',
key: 'MarkdownWithLink',
template: '[![](#url#)](#url#)',
},
]
},
output: [],
apitype: 'dianping',
imgurl: ''
},
progress: 0,
urls: {},
result: '',
},
mounted() {
if($.cookie('imghosting_apitype')){
this.set.apitype = $.cookie('imghosting_apitype')
}
var that=this;
document.addEventListener('paste', function(e) {
if($(e.target).hasClass('imgurl')) return;
var items = ((e.clipboardData || window.clipboardData).items) || [];
var file = null;
if (items && items.length) {
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
file = items[i].getAsFile();
break;
}
}
}
if (!file) {
alert('粘贴内容非图片!');
return;
}
that.pasteFile(file)
});
},
watch: {
'set.apitype'(newVal) {
$.cookie('imghosting_apitype',newVal)
},
'set.output'(newVal) {
let list = {}
for (item of this.set.output_types.items) {
let arr = []
for (const v of newVal) {
arr.push(item.template.replaceAll('#url#', v))
}
list[item.key] = arr;
}
this.urls = list
},
'urls'(newVal) {
this.result = newVal[this.set.output_types.current].join('\n')
},
'set.output_types.current'(newVal) {
this.result = this.urls[newVal] ? this.urls[newVal].join('\n') : '';
}
},
methods: {
async uploadFile(file, total, id){
var that = this;
return new Promise((resolve, reject) => {
if(file.size > 10485760){
reject('上传失败!文件超过10M');return;
}
var data = new FormData();
data.append('file', file);
data.append('apitype', that.set.apitype);
$.ajax({
type : "POST",
url : "/api/{$plugin.alias}/upload",
data : data,
processData: false,
contentType: false,
dataType : 'json',
success : function(data) {
if(data.code == 0){
resolve(data.data.url);
}else{
reject(data.msg);
}
},
error : function(){
reject('上传失败!接口错误');
},
xhr: function() {
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', function (e) {
//console.log(e);
progressRate = Math.round(e.loaded / e.total / total * 100 + (id-1) / total * 100);
that.progress = progressRate;
})
return xhr;
}
});
})
},
async selectFile(e) {
var total = e.target.files.length;
if(total == 0) return;
this.progress = 0;
let loading = layer.msg('正在上传中', {icon: 16,shade: 0.1,time: 0});
var error = '';
var i = 1;
for (const file of e.target.files) {
await this.uploadFile(file, total, i++).then(res => {
this.set.output.push(res)
}, res => {
error += res + "<br/>";
})
}
$("#file").val('');
layer.close(loading);
if(error){
layer.alert(error, {icon: 2});
}
},
async pasteFile(file) {
this.progress = 0;
let loading = layer.msg('正在上传中', {icon: 16,shade: 0.1,time: 0});
var error = '';
var i = 1;
await this.uploadFile(file, 1, i++).then(res => {
this.set.output.push(res)
}, res => {
error += res + "<br/>";
})
$("#file").val('');
layer.close(loading);
if(error){
layer.alert(error, {icon: 2});
}
},
uploadimgurl(){
if(this.set.imgurl.trim() == ''){
alert('图片URL不能为空');return;
}
if(this.set.imgurl.indexOf('http://') == -1 && this.set.imgurl.indexOf('https://') == -1){
alert('图片URL不正确');return;
}
$("#inputurl").modal('hide');
this.progress = 0;
let loading = layer.msg('正在上传中', {icon: 16,shade: 0.1,time: 0});
var that = this;
$.ajax({
type : "POST",
url : "/api/{$plugin.alias}/uploadurl",
data : { url: this.set.imgurl.trim(), apitype: this.set.apitype},
dataType : 'json',
success : function(data) {
layer.close(loading);
if(data.code == 0){
that.progress = 100;
that.set.output.push(data.data.url)
}else{
layer.alert(data.msg, {icon: 2});
}
},
error : function(){
layer.close(loading);
layer.alert('上传失败!接口错误', {icon: 2});
},
});
},
copy(){
if(!this.result) return;
$("#output").select();
document.execCommand("Copy");
layer.msg('复制成功', {icon:1, time:600})
},
reset(){
this.set.output = [];
this.progress = 0;
}
},
})
</script>
{/block}