first commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\QfShop;
|
||||
|
||||
class Error extends QfShop
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return jerr("Error", 404);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\QfShop;
|
||||
|
||||
class Index extends QfShop
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return jok("Hello World!");
|
||||
}
|
||||
public function search() {
|
||||
return jok("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\QfShop;
|
||||
use app\model\Source as SourceModel;
|
||||
|
||||
class Search extends QfShop
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$SourceModel = new SourceModel();
|
||||
$data = $SourceModel->getList(input(''));
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
|
||||
public function getDetail()
|
||||
{
|
||||
$SourceModel = new SourceModel();
|
||||
$data = $SourceModel->getDetail(input(''));
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
|
||||
public function getNew()
|
||||
{
|
||||
$SourceModel = new SourceModel();
|
||||
$data = $SourceModel->getNew(input(''));
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
|
||||
public function getHot()
|
||||
{
|
||||
$SourceModel = new SourceModel();
|
||||
$data = $SourceModel->getHot(input(''));
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\App;
|
||||
use app\api\QfShop;
|
||||
use think\facade\Cache;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use app\model\Source as SourceModel;
|
||||
use app\model\SourceLog as SourceLogModel;
|
||||
|
||||
class Source extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//第三方转存接口地址
|
||||
$this->url = "https://pan.xinyuedh.com";
|
||||
|
||||
$this->model = new SourceModel();
|
||||
$this->SourceLogModel = new SourceLogModel();
|
||||
}
|
||||
public function day()
|
||||
{
|
||||
// 当前日期
|
||||
$currentDate = Carbon::today()->toDateString();
|
||||
// 缓存键名
|
||||
$cacheKey = 'api_alone_date_' . $currentDate;
|
||||
|
||||
// 检查缓存中是否存在该键
|
||||
if (Cache::has($cacheKey)) {
|
||||
return jerr("该接口今天已经执行过,请明天再试!");
|
||||
}
|
||||
|
||||
Cache::set($cacheKey, time(), 43200);
|
||||
|
||||
ini_set('max_execution_time', -1);
|
||||
//分页转存
|
||||
$page_no = 1;
|
||||
$dataList = '';
|
||||
$logId = '';
|
||||
while ($dataList=='' || !empty($dataList['items'])) {
|
||||
$searchData = array(
|
||||
'page_no' => $page_no,
|
||||
'page_size' => 100,
|
||||
'type' => 2,
|
||||
'day' => 2,
|
||||
);
|
||||
$res = curlHelper($this->url."/api/search", "POST", $searchData)['body'];
|
||||
$res = json_decode($res, true);
|
||||
|
||||
if($res['code'] !== 200){
|
||||
ini_set('max_execution_time', 300);
|
||||
return jerr($res['message']);
|
||||
}
|
||||
$dataList = $res['data'];
|
||||
$page_no++;
|
||||
|
||||
if($logId == ''){
|
||||
$logId = $this->SourceLogModel->addLog('每日更新',$dataList['total_result']);
|
||||
}
|
||||
|
||||
foreach ($dataList['items'] as $key => $value) {
|
||||
//如已有此资源 跳过
|
||||
$detail = $this->model->where('title', $value['title'])->find();
|
||||
if(!empty($detail)){
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'skip_num','重复跳过转存');
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = $value['url'];
|
||||
$substring = strstr($url, 's/');
|
||||
|
||||
if ($substring !== false) {
|
||||
$pwd_id = substr($substring, 2); // 去除 's/' 部分
|
||||
} else {
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'fail_num','资源地址格式有误');
|
||||
continue;
|
||||
}
|
||||
|
||||
$urlData = array(
|
||||
'cookie' => Config('qfshop.quark_cookie'),
|
||||
'url' => $url,
|
||||
);
|
||||
$res = curlHelper($this->url."/api/open/transfer", "POST", $urlData)['body'];
|
||||
$res = json_decode($res, true);
|
||||
|
||||
if($res['code'] !== 200){
|
||||
if($res['message'] == 'capacity limit[{0}]'){
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'fail_num',$res['message']);
|
||||
break;
|
||||
}else{
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'fail_num',$res['message']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//添加资源到系统中
|
||||
$data["title"] = $value['title'];
|
||||
$data["url"] = $res['data']['share_url'];
|
||||
$data["update_time"] = time();
|
||||
$data["create_time"] = time();
|
||||
$this->model->insertGetId($data);
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'new_num','');
|
||||
}
|
||||
// 可以添加一个最大重试次数的限制,防止无限循环
|
||||
if ($page_no > 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'','',3);
|
||||
ini_set('max_execution_time', 300);
|
||||
return jok('已提交任务,稍后查看结果',$dataList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\App;
|
||||
use app\api\QfShop;
|
||||
use app\model\User as Usermodel;
|
||||
use app\model\Ads as Adsmodel;
|
||||
use app\model\Feedback as FeedbackModel;
|
||||
|
||||
class Tool extends QfShop
|
||||
{
|
||||
/**
|
||||
* 系统配置参数
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$data = [
|
||||
'app_name' => Config('qfshop.app_name'),
|
||||
'qcode' => getimgurl(Config('qfshop.qcode')),
|
||||
];
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function Upload()
|
||||
{
|
||||
// 获取当前登录的用户信息
|
||||
$userInfo = $this->getLoginUser();
|
||||
|
||||
try {
|
||||
$file = request()->file('file');
|
||||
} catch (\Exception $error) {
|
||||
return jerr('上传文件失败,请检查你的文件!');
|
||||
}
|
||||
$Usermodel = new Usermodel();
|
||||
$data = $Usermodel->Upload($file, $userInfo);
|
||||
return jok('上传成功',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据广告位关键词获取广告图片列表
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAdsCode()
|
||||
{
|
||||
$Adsmodel = new Adsmodel();
|
||||
$data = $Adsmodel->getAdsCode(input(''));
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户反馈
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function feedback()
|
||||
{
|
||||
$data = input('');
|
||||
if (empty($data['content'])) {
|
||||
return jerr("请输入要看的内容");
|
||||
}
|
||||
$FeedbackModel = new FeedbackModel();
|
||||
$FeedbackModel->save(['content' => $data['content']]);
|
||||
return jok('已反馈');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user