Skip to content

Commit

Permalink
Providers: 添加和彩云
Browse files Browse the repository at this point in the history
  • Loading branch information
xytoki committed Mar 24, 2020
1 parent 64752c0 commit 458f64a
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 2 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TCShare v3
不只是天翼云API的目录列表程序
现已增加支持Onedrive 国际版和世纪互联
现已增加支持Onedrive 国际版和世纪互联
又增加了和彩云
接下来可能还有其他?
【配置文件可视化编辑器绝赞咕咕咕中】
[安装教程:这里](https://xylog.cn/2020/03/03/tcshare.html)
Expand Down Expand Up @@ -55,6 +56,22 @@
XS_KEY_od_SK=client_secret
XS_KEY_od_FD=redirect_uri #格式:http://domain/_app/redirect
```
#### 和彩云登录方式
1. 正常登录和彩云,记得勾选【下次自动登录】。
2. 打开[这个地址](https://caiyun.feixin.10086.cn/Mcloud/sso/getCyToken.action)
3. 复制里面所有内容,填入到配置文件/环境变量的`XS_KEY_<name>_TOKEN`字段中
4. 理论上可用。和彩云cookie有效期理论一年,够用了。
5. 为什么不做自动登录?因为有验证码。
配置示例:
```bash
XS_KEY_cm=caiyun
XS_KEY_cm_TOKEN='{"cyToken":"******|*1*|RCS|******|******","encryPhone":"******"}'
XS_APP_3_NAME="TCShare 和彩云"
XS_APP_3_THEME=mdui
XS_APP_3_BASE=/
XS_APP_3_KEY=cm
XS_APP_3=/caiyun
```
### 功能

#### 已支持
Expand All @@ -77,6 +94,7 @@
### Demo

[天翼云](https://xia.st/)
[和彩云](https://xia.st/caiyun/)
[OneDrive国际](https://xia.st/d/)
[OneDrive世纪互联](https://xia.st/c/)

Expand Down
223 changes: 223 additions & 0 deletions _app/providers/caiyun.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?php
namespace xyToki\xyShare\Providers;
use TC;
use Flight;
use Throwable;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use xyToki\xyShare\Cache;
use xyToki\xyShare\abstractInfo;
use xyToki\xyShare\authProvider;
use xyToki\xyShare\contentProvider;
use xyToki\xyShare\fileInfo;
use xyToki\xyShare\folderInfo;
use xyToki\xyShare\Errors\NotFound;
use xyToki\xyShare\Errors\NoPermission;
use xyToki\xyShare\Errors\NotAuthorized;
use xyToki\xyShare\Errors\NotConfigured;
use Symfony\Contracts\Cache\ItemInterface;

class caiyun implements contentProvider {
private $sky;
public $AK;
public $SK;
public $FD;
public $BASE;
public $token;
public $keyPrefix="caiyun";
const rootId="00019700101000000001";//Magic Number.Why?
function __construct($options){
if(empty($options['TOKEN'])){
throw new NotAuthorized();
}
try{
$j = json_decode($options['TOKEN']);
if($j)$options['TOKEN'] = $j->cyToken;
}catch(Throwable $e){}
$this->cookie = $options['TOKEN'];
$cookieJar = CookieJar::fromArray([
'.mssc' => $options['TOKEN']
], 'caiyun.feixin.10086.cn');
$this->http = new Client([
'base_uri' => 'https://caiyun.feixin.10086.cn/portal/webdisk2',
'timeout' => 5.0,
'cookies' => $cookieJar,
]);
}
private function getListById($id){
$cache = Cache::getInstance();
$key = $this->keyPrefix.".getListById.".md5($this->cookie).".".$id;
$key = str_replace("/",".",$key);
$cached=1;
$res = $cache->get($key, function (ItemInterface $item) use(&$cached,$id) {
$s_id = explode("/",$id);
$cached=0;
$item->expiresAfter(300);
$res = $this->http->request("POST","/queryContentAndCatalog!disk.action", [
'form_params' => [
"startNumber"=>'1',
"endNumber"=>'9999',
"contentID"=>$s_id[count($s_id)-1],
"path"=>$id
]
]);
return (string)$res->getBody();
}, isset($_GET['_tcshare_renew'])?INF:1.0);
Flight::response()->header("X-TCShare-Caiyun-".rand(0,999),$key."=".($cached?"cached":"refreshed"));
$r = json_decode($res,true);
return $r['dci'];
}
private function getByPath($path){
$path = TC::path("/".$this->BASE."/".$path,false);
if($path=="/"){
return [
"path"=>$this::rootId
];
}else{
$paths = explode("/",$path);
array_shift($paths);
$parent = [
"path"=>$this::rootId
];
foreach($paths as $i=>$n){
if(!$parent['path']){
throw new NotFound;
}
$dir = $this->getListById($parent['path']);
$current = false;
foreach($dir['cataloginfos'] as $f){
if($f['catalogName']==$n){
$current = $f;
break;
}
}
foreach($dir['contents'] as $f){
if($f['contentName']==$n){
$current = $f;
break;
}
}
if(!$current){
throw new NotFound;
}
$parent = $current;
}
}
return $current;
}
function getFileInfo($path){
$fileInfo=$this->getByPath($path);
if(isset($fileInfo['contentName'])){
return new caiyunFileInfo($fileInfo,$this);
}else{
return new caiyunFolderInfo($fileInfo);
}
}
function listFiles($fileInfo){
if(!$fileInfo instanceof caiyunFolderInfo)throw new \Exception();
$list = $this->getListById($fileInfo->file['path']);
$returns=[[],[]];
$folders=TC::toArr($list['cataloginfos']);
$files=TC::toArr($list['contents']);
foreach($folders as $one){
if(!$one)continue;
$returns[0][]=new caiyunFolderInfo($one);
}
foreach($files as $one){
if(!$one)continue;
$returns[1][]=new caiyunFileInfo($one,$this);
}
return $returns;
}
}
class caiyunAuth {
function __construct($options){
$this->user = $options['USER'];
$this->user = $options['PASS'];
$cookieJar = CookieJar::fromArray([
], 'caiyun.feixin.10086.cn');
$this->http = new Client([
'base_uri' => 'https://caiyun.feixin.10086.cn/portal/webdisk2',
'timeout' => 5.0,
'cookies' => $cookieJar,
]);
}
}

class caiyunHook{
function __construct($client){
$this->client = $client;
$this->run();
}
function run(){

}
}

class caiyunAbstractInfo implements abstractInfo{
public $file;
function __construct($file){
$this->file=$file;
}
public function isFolder(){

}
public function name(){
return isset($this->file['contentName'])?$this->file['contentName']:$this->file['catalogName'];
}
public function timeModified(){
return $this->formatCaiyunTime($this->file['updateTime']);
}
public function timeCreated(){
return $this->formatCaiyunTime($this->file['uploadTime']);
}
private function formatCaiyunTime($d){
$ds = str_split($d);
array_splice($ds, 4, 0, ['-']);
array_splice($ds, 7, 0, ['-']);
array_splice($ds, 10, 0, [' ']);
array_splice($ds, 13, 0, [':']);
array_splice($ds, 16, 0, [':']);
return implode("",$ds);
}
}
class caiyunFileInfo extends caiyunAbstractInfo implements fileInfo{
function __construct($file,$client){
parent::__construct($file);
$this->client=$client;
}
public function isFolder(){
return false;
}
public function url(){
$cached = 1;
$key="caiyun.download.".$this->file['digest'];
$res = $this->client->http->get('/downLoadAction!downloadToPC.action?shareContentIDs='.$this->file['contentID']);
return json_decode($res->getBody(),true)['redirectURL'];
}
public function size(){
return $this->file['contentSize'];
}
public function extension(){
return strtolower($this->file['contentSuffix']);
}
public function thumbnail(){
if(!isset($this->file['thumbnailURL'])){
return false;
}
return $this->file['thumbnailURL'];
}
}
class caiyunFolderInfo extends caiyunAbstractInfo implements folderInfo{
function __construct($file){
parent::__construct($file);
}
public function isFolder(){
return true;
}
public function hasIndex(){
//Not Implemented.
//TODO
return false;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xytoki/tcshare",
"description": "Multicloud directory listing.",
"version": "3.0.1",
"version": "3.1.0",
"type": "project",
"config": {
"optimize-autoloader": true,
Expand Down

0 comments on commit 458f64a

Please sign in to comment.