前言
接入其他存储的方案太过昂贵,多吉云就成了咱这普通人的最优选。
很可惜的是多吉云没有被任何一家图床程序接入,于是自己动手接入成了最后的选择。
离谱的多吉云
多吉云使用的是腾讯的COS作为底层然后又做了个API接口获取密钥
用多吉云的密钥访问自己的API接口来获取可以访问的密钥
而且密钥是三段式(accessKeyId
/secretAccessKey
/sessionToken
)临时密钥
真TM日狗
兼容多吉云
曲线救国方案临时版,并不是最优解
本来打算直接新增存储策略的,但是改半天都用不了,还给干500错误了
编辑文件 App/Enums/Strategy/S3Option.php
添加上 session_Token
转换 sessionToken
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?php
namespace App\Enums\Strategy;
final class S3Option { const Url = 'url';
const AccessKeyId = 'access_key_id';
const SecretAccessKey = 'secret_access_key'; const sessionToken = 'session_Token';
const Endpoint = 'endpoint';
const Region = 'region';
const Bucket = 'bucket'; }
|
编辑文件 app/Services/ImageService.php
给AwsS3添加上 sessionToken
的获取 'token' => $configs->get(S3Option::sessionToken)
1 2 3 4 5 6 7 8 9 10 11 12
| StrategyKey::S3 => new AwsS3V3Adapter( client: new S3Client([ 'credentials' => [ 'key' => $configs->get(S3Option::AccessKeyId), 'secret' => $configs->get(S3Option::SecretAccessKey), 'token' => $configs->get(S3Option::sessionToken) ], 'endpoint' => $configs->get(S3Option::Endpoint), 'region' => $configs->get(S3Option::Region), 'version' => '2006-03-01', ]), bucket: $configs->get(S3Option::Bucket),
|
新增一个php文件,命名随意,随便扔个地方调用一下,文件调用就可以获取把密钥传到数据库里了
因为是密钥有两小时可用时间,最好还是定时访问更新,直接调用也是可以的,不过要搞清楚优先级
每天的调用量是80000 次 / 天,想必用上多吉的都是穷逼一个,这个调用足够了
可以直接调用文件或者在开个网站内网hosts定时访问
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| <?php
function dogecloud_api($apiPath, $data = array(), $jsonMode = false) { $accessKey = "XXXXXXXXXX"; $secretKey = "XXXXXXXXXXXXX";
$body = $jsonMode ? json_encode($data) : http_build_query($data); $signStr = $apiPath . "\n" . $body; $sign = hash_hmac('sha1', $signStr, $secretKey); $Authorization = "TOKEN " . $accessKey . ":" . $sign;
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.dogecloud.com" . $apiPath); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); if(isset($data) && $data){ curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: ' . ($jsonMode ? 'application/json' : 'application/x-www-form-urlencoded'), 'Authorization: ' . $Authorization )); } $ret = curl_exec($ch); curl_close($ch); return json_decode($ret, true); }
$api = dogecloud_api('/auth/tmp_token.json', array( "channel" => "OSS_FULL", "scopes" => array("*") ), true);
$servername = "XXXXXXX"; $dbname = "XXXXXX"; $username = "XXXXX"; $password = "XXXXX";
$DogeAPI = [ 'url' => 'XXXXX', 'bucket' => 'XXXXX', 'region' => 'automatic', 'queries' => '', 'endpoint' => 'XXXXXXXXXXXXX', 'access_key_id' => $api['data']['Credentials']['accessKeyId'], 'secret_access_key' => $api['data']['Credentials']['secretAccessKey'], 'session_Token' => $api['data']['Credentials']['sessionToken'], ]; $ApiData = json_encode($DogeAPI); $ApiData = addslashes($ApiData);
try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM `strategies` WHERE `id` = 100 "; $sql = "UPDATE `strategies` SET `configs` = '$ApiData' WHERE `strategies`.`id` = 100"; $conn->exec($sql); } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage(); } $conn = null;
?>
|
以上就是全部了!
总结
没钱才是根本原因!