first commit

This commit is contained in:
675061370@qq.com
2024-04-04 21:28:09 +08:00
commit fe9661855e
4192 changed files with 618218 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace app\api;
use think\App;
use think\facade\View;
use app\model\Conf as ConfModel;
use app\model\Token as TokenModel;
/**
* 控制器基础类
*/
abstract class QfShop
{
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
// 初始化
protected function initialize()
{
//访问XMLHttpRequest已被CORS政策阻止
header('Access-Control-Allow-Origin: *');
$this->confModel = new ConfModel();
$configs = $this->confModel->select()->toArray();
$c = [];
foreach ($configs as $config) {
$c[$config['conf_key']] = $config['conf_value'];
}
config($c, 'qfshop');
}
public function __call($method, $args)
{
return jerr("API接口方法不存在", 404);
}
/**
* 检测授权 获取当前用户登录信息
* @param $type false不提示登录失败状态
* @param user_id 顾客时为用户id
* @param action 操作者 顾客端为手机号,管理端为登录账号
* @param client_type 0=顾客 1=管理组 -1=游客
*/
protected function getLoginUser($type = true)
{
$is_login = true;
// 获取请求中的token
$access_token = request()->header('X-CSRF-TOKEN');
if (!$access_token) {
if($type){
return jerr("用户未登录", 401);
}else{
$is_login = false;
}
}
$Token = new TokenModel();
$user = $Token->getToken($access_token);
if (!$user) {
if($type){
return jerr("登录过期,请重新登录", 401);
}else{
$is_login = false;
}
}
if($is_login){
$user['action'] = $user['mobile'];
$user['client_type'] = 0;
unset($user['mobile']);
unset($user['status']);
return $user;
}else{
$user['client_type'] = -1;
return $user;
}
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace app\api\controller;
use app\api\QfShop;
class Error extends QfShop
{
public function index()
{
return jerr("Error", 404);
}
}
+16
View File
@@ -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!");
}
}
+37
View File
@@ -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);
}
}
+118
View File
@@ -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);
}
}
+73
View File
@@ -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('已反馈');
}
}