Commit 6bfb8608 by 杨昕

添加获取百度oss口令

parent 5577ee96
Pipeline #19420 passed with stages
in 1 minute 4 seconds
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api\Client;
use App\Model\AliOssModel;
use App\Model\BaiduOssModel;
use Illuminate\Validation\Rule;
use App\Exceptions\FormException;
use App\Model\MediaModel;
......@@ -28,6 +29,7 @@ class MediaController extends Controller
const OSS_ALI = 'ALI';
const OSS_QI_QIU = 'QI_NIU';
const OSS_BAIDU = 'BAIDU';
/**
* 获取媒资ID
......@@ -84,6 +86,9 @@ class MediaController extends Controller
$domain = $this->domain[$branch];
$data = ["token" => $token,'domain' => $domain];
break;
case self::OSS_BAIDU:
$data = BaiduOssModel::getBaiduOssToken($request);
break;
default:
$token = QiniuModel::uploadToken($this->bucketList[$branch],$key);
$domain = $this->domain[$branch];
......
<?php
namespace App\Model;
class BaiduOssModel
{
/**
* @param $request
* @return mixed
*/
public static function getBaiduOssToken($request){
try {
$ali_base_url = getenv('ofc-store-svr') ? getenv('ofc-store-svr') : "http://ofc-store-svr-svr.micro";
$url = $ali_base_url."/api/v1/bdAssumeRole";
$data = array(
"body"=>'{"accessControlList":[{"service":"bce:bos","region":"bj","effect":"Allow","resource":["media-test-bce/*"],"permission":["READ","WRITE"]}]}'
);
$header = array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen(json_encode($data))
);
$res = http_request_code($url,$header,"POST",json_encode($data),2);
LogModel::addlog([" 获取百度OSS临时token 1"=>$res,"请求URL"=>$url,"请求头header"=>$header]);
$result = json_decode($res,true);
if ($result["code"] != 0){
throw new \Exception("获取token失败");
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return $result["data"];
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment