PHP简单实现七牛云对象储存上传

吐槽复杂的sdk,我只要实现一个上传功能却有这么复杂的sdk来操作,代码部分只适用于PHP7,PHP5请替换文件上传部分

<?php
class Qiniu {
private $AccessKey = '';
private $SecretKey = '';
private $bucket;
public function __construct($bucket = '') {
    $this->bucket = $bucket;
}
private function urlsafe_b64encode($string) {
    $data = base64_encode($string);
    $data = str_replace(array('+', '/'), array('-', '_'), $data);
    return $data;
}
public function upload($file, $filename, $dead = 600) {
    $post_data = array(
        'file' => new CURLFile($file),
        'key' => $filename,
    );

    $putPolicy = [
        'scope' => $this->bucket . ':' . $filename,
        'deadline' => TIMESTAMP + $dead, //有效期10分钟
        'returnBody' => '{"name":$(fname),"size":$(fsize),"w":$(imageInfo.width),"h":$(imageInfo.height),"key":$(key)}',
    ];

    $post_data['token'] = $this->makeToken($putPolicy);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://upload.qiniup.com');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $info = curl_exec($ch);
    return $info;
}
private function makeToken($policy) {
    $putPolicy = json_encode($policy); //转为json
    $encodedPutPolicy = $this->urlsafe_b64encode($putPolicy);
    $encodedSign = $this->makeSign($encodedPutPolicy);
    $uploadToken = $this->AccessKey . ':' . $encodedSign . ':' . $encodedPutPolicy;
    return $uploadToken;
}
private function makeSign($encodedPutPolicy) {
    $sign = hash_hmac("sha1", $encodedPutPolicy, $this->SecretKey, true);
    $encodedSign = $this->urlsafe_b64encode($sign);
    return $encodedSign;
}

}
?>