通过fatsadmin阿里云OSS存储插件-生成二维码图片,并上传阿里云OSS存储空间里

# 生成二维码并上传到阿里云OSS
if (!function_exists('create_qrcode')){
    function create_qrcode($url){
        $filename = time().rand(100,999).'.png';
        $path = 'uploads/qrcode/'.$filename;
        $code = new QRcode();
        $code->png($url,$path)->entry();
        $tokenUrl = request()->domain()."/addons/alioss/index/params";
        # 通过插件-获取阿里云OSS配置
        $configAliOss = get_addon_config('alioss');
        # 生成 token
        $data = ['deadline' => time().$configAliOss['endpoint']];
        $signature = hash_hmac('sha1', json_encode($data), $configAliOss['accessKeySecret'], true);
        $token =  $configAliOss['accessKeyId'] . ':' . base64_encode($signature) . ':' . base64_encode(json_encode($data));
        $params = [
            'name' => $filename,
            'md5' => md5($filename),
            'chunk' => 0,
            'aliosstoken' => $token,
        ];
        $response = posturl($tokenUrl,$params);
        if (!$response){
            return false;
        }
        $real_path = ROOT_PATH."public".DS.$path;
        $file = new CURLFile(realpath($real_path));
        $dataPost = [
            'file'      =>      $file,
            'aliosstoken'=>      $token
        ];
        $uploadUrl = request()->domain()."/addons/alioss/index/upload";
        $res = posturl($uploadUrl,$dataPost);
        if (!$res){
            return false;
        }
        return $res['data']['url'];
    }
}

 

 
posted @ 2024-04-28 15:50  丶XianGang  阅读(22)  评论(0编辑  收藏  举报