1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------- |
4
|
|
|
// | ThinkLibrary 6.0 for ThinkPhP 6.0 |
5
|
|
|
// +---------------------------------------------------------------------- |
6
|
|
|
// | 版权所有 2017~2020 [ https://www.dtapp.net ] |
7
|
|
|
// +---------------------------------------------------------------------- |
8
|
|
|
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary |
9
|
|
|
// +---------------------------------------------------------------------- |
10
|
|
|
// | 开源协议 ( https://mit-license.org ) |
11
|
|
|
// +---------------------------------------------------------------------- |
12
|
|
|
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary |
13
|
|
|
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary |
14
|
|
|
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary |
15
|
|
|
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary |
16
|
|
|
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git |
17
|
|
|
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
18
|
|
|
// +---------------------------------------------------------------------- |
19
|
|
|
|
20
|
|
|
namespace DtApp\ThinkLibrary\service\upyun; |
21
|
|
|
|
22
|
|
|
use DtApp\ThinkLibrary\Service; |
23
|
|
|
use Exception; |
24
|
|
|
use Upyun\Config; |
25
|
|
|
use Upyun\Upyun; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* 又拍云存储 |
29
|
|
|
* https://www.upyun.com/products/file-storage |
30
|
|
|
* Class UssService |
31
|
|
|
* @package DtApp\ThinkLibrary\service\upyun |
32
|
|
|
*/ |
33
|
|
|
class UssService extends Service |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var |
37
|
|
|
*/ |
38
|
|
|
private $serviceName, $operatorName, $operatorPassword; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $serviceName |
42
|
|
|
* @return $this |
43
|
|
|
*/ |
44
|
|
|
public function serviceName(string $serviceName) |
45
|
|
|
{ |
46
|
|
|
$this->serviceName = $serviceName; |
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $operatorName |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
|
|
public function operatorName(string $operatorName) |
55
|
|
|
{ |
56
|
|
|
$this->operatorName = $operatorName; |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $operatorPassword |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
|
public function operatorPassword(string $operatorPassword) |
65
|
|
|
{ |
66
|
|
|
$this->operatorPassword = $operatorPassword; |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $object |
72
|
|
|
* @param string $filePath |
73
|
|
|
* @return array|bool |
74
|
|
|
* @throws Exception |
75
|
|
|
*/ |
76
|
|
|
public function upload(string $object, string $filePath) |
77
|
|
|
{ |
78
|
|
|
$serviceConfig = new Config($this->serviceName, $this->operatorName, $this->operatorPassword); |
79
|
|
|
$client = new Upyun($serviceConfig); |
80
|
|
|
$file = fopen($filePath, 'r'); |
81
|
|
|
return $client->write($object, $file); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|