# 生成二维码并上传到阿里云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']; } }
标签:插件,OSS,filename,token,阿里,path,configAliOss From: https://www.cnblogs.com/ixiangang06/p/18163885