1.修改 src/AppBundle/Util/UploaderToken.php
<?php
namespace AppBundle\Util;
use AppBundle\Component\JWT\JWT;
use Topxia\Service\Common\ServiceKernel;
use AppBundle\Common\TimeMachine;
/**
* 素材库文件上传Token.
*/
class UploaderToken
{
public function make($targetType, $targetId, $bucket, $ttl = 86400)
{
$user = $this->getCurrentUser();
$metas = "{$user['uuid']}|{$targetType}|{$targetId}|{$bucket}";
$payload = array(
"iss" => "EduSoho",
"aud" => "EduSoho",
"exp" => TimeMachine::time() + $ttl,
"metas" => $metas,
);
return JWT::encode($payload, $this->getKey(), 'HS256');
}
public function parse($token)
{
if (empty($token)) {
return null;
}
$payload = JWT::decode($token, $this->getKey(), array('HS256'));
$metas = $payload->metas;
list($uuid, $targetType, $targetId, $bucket) = explode('|', $metas);
$user = $this->getUserService()->getUserByUUID($uuid);
if (empty($user)) {
return null;
}
return array(
'userId' => $user['id'],
'targetType' => $targetType,
'targetId' => $targetId,
'bucket' => $bucket,
);
}
private function base64Encode($data)
{
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
private function base64Decode($data)
{
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
private function getCurrentUser()
{
return ServiceKernel::instance()->getCurrentUser();
}
private function getKey()
{
$this->getSettingService()->get('storage', array());
$accessKey = empty($storage['cloud_access_key']) ? '' : $storage['cloud_access_key'];
$secretKey = empty($storage['cloud_secret_key']) ? '' : $storage['cloud_secret_key'];
return md5($accessKey.$secretKey);
}
/**
* @return SettingService
*/
private function getSettingService()
{
return $this->getServiceKernel()->getBiz()->service("System:SettingService");
}
/**
* @return UserService
*/
private function getUserService()
{
return $this->getServiceKernel()->getBiz()->service("User:UserService");
}
private function getServiceKernel()
{
return ServiceKernel::instance();
}
}
修改 src/Biz/File/Service/Impl/UploadFileServiceImpl.php 的对应方法
3. 最主要的 引入JWT 。。。。。将JWT文件夹复制到 项目目录 src/AppBundle/Component 下
链接: https://pan.baidu.com/s/1YOAW9FV4lxLLV6QBvYO20Q?pwd=5o7s 提取码: 5o7s? --来自百度网盘超级会员v1的分享
这时候 上传试一下?
4.如果你不是只能https访问的话会存在跨域的报错 处理方案就是把sdk本地化? ?sdk本地化教程
这时候 上传就没啥问题了? ,已在8.3.36版本测试有效。如遇问题可找我帮你看下
|