提交 61910ccf 编写于 作者: H HFO4

add: Onedrive

上级 1fe7be12
......@@ -9,4 +9,6 @@
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
return [];
return [
'app\index\command\Task',
];
<?php
namespace app\index\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Task extends Command
{
protected function configure()
{
$this->setName('run')->setDescription('Start processing tasks for Cloudreve');
}
protected function execute(Input $input, Output $output)
{
$output->writeln("TestCommand:");
}
}
?>
\ No newline at end of file
......@@ -513,5 +513,20 @@ class Admin extends Controller{
return json(['error'=>1,'message'=>"取消失败"]);
}
}
public function UpdateOnedriveToken(){
$policyId = input("get.id");
$this->adminObj->updateOnedriveToken($policyId);
}
public function OneDriveCalllback(){
$code = input("get.code");
$this->adminObj->oneDriveCalllback($code);
}
public function uploadTest(){
$this->adminObj->oneDriveTest();
}
}
......@@ -5,6 +5,7 @@ use think\Model;
use think\Db;
use \app\index\model\Mail;
use \app\index\model\FileManage;
use \Krizalys\Onedrive\Client;
class AdminHandler extends Model{
......@@ -709,6 +710,68 @@ class AdminHandler extends Model{
}
return ["error"=>0,"msg"=>"设置已保存"];
}
public function updateOnedriveToken($policyId){
$policyData = Db::name("policy")->where("id",$policyId)->find();
if(empty($policyData)){
throw new \think\Exception("Policy not found");
}
$onedrive = new Client([
'client_id' => $policyData["bucketname"],
]);
$url = $onedrive->getLogInUrl([
'offline_access',
'files.readwrite.all',
], Option::getValue("siteURL")."Admin/oneDriveCalllback");
echo "<a href='$url'>继续绑定账号</a>";
Db::name("policy")->where("id",$policyId)->update([
"sk" => json_encode($onedrive->getState()),
]);
\think\Session::set('onedrive.pid',$policyId);
}
public function oneDriveCalllback($code){
$policyId = \think\Session::get('onedrive.pid');
$policyData = Db::name("policy")->where("id",$policyId)->find();
$onedrive = new Client([
'client_id' => $policyData["bucketname"],
// Restore the previous state while instantiating this client to proceed in
// obtaining an access token.
'state' => json_decode($policyData["sk"]),
]);
// Obtain the token using the code received by the OneDrive API.
$onedrive->obtainAccessToken($policyData["ak"], $_GET['code']);
// Persist the OneDrive client' state for next API requests.
Db::name("policy")->where("id",$policyId)->update([
"sk" => json_encode($onedrive->getState()),
]);
}
public function oneDriveTest(){
$policyId = \think\Session::get('onedrive.pid');
$policyData = Db::name("policy")->where("id",$policyId)->find();
$onedrive = new Client([
'client_id' => $policyData["bucketname"],
// Restore the previous state while instantiating this client to proceed in
// obtaining an access token.
'state' => json_decode($policyData["sk"]),
]);
$onedrive->renewAccessToken($policyData["ak"]);
Db::name("policy")->where("id",$policyId)->update([
"sk" => json_encode($onedrive->getState()),
]);
$file = fopen("C:/Users/i/Downloads/Video/test.mp4","r");
$onedrive->createFile(urlencode("Git提交代码简教程.mp4"),"/me/drive/root:/sdfdsf",$file);
}
}
?>
\ No newline at end of file
#!/usr/bin/env php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
// 定义项目路径
define('APP_PATH', __DIR__ . '/application/');
// 加载框架引导文件
require __DIR__.'/thinkphp/console.php';
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册