当前位置:Gxlcms > PHP教程 > upyun刷新缓存的签名不知道哪错了

upyun刷新缓存的签名不知道哪错了

时间:2021-07-01 10:21:17 帮助过:16人阅读

返回的结果是401 Sign error

public function delete($path) {
    //比如http://www.xx.com/a/b.jpg,我传过来删除的就是/a/b.jpg
    //删除部分略过
    //刷新缓存开始
    $ch = curl_init('http://purge.upyun.com/purge/');
    $date = gmdate('D, d M Y H:i:s \G\M\T');

    //这里签名我是直接用的$path,我是怀疑这里错了 但是我试过http://www.xx.com加在前面也还是错误
    $sign = md5($path.'&'.$this->bucket.'&'.$date.'&'.md5($this->password));

    //头信息
    $header = array(
        'Expect: ""',
        'Authorization: UpYun '.$this->config['bucket'].':'.$this->config['username'].':'.$sign,
        'Date: '.$date,
        'Content-Type: application/x-www-form-urlencoded',
    );
    curl_setopt($ch,CURLOPT_HTTPHEADER,$header);

    //POST方式
    curl_setopt($ch,CURLOPT_POST,1);

    //这里也是个问题,我不知道这个要不要提交过去
    $data = array(
        'purge' => urlencode($path),
    );
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

    //是否返回头信息
    curl_setopt($ch,CURLOPT_HEADER,1);

    $response = curl_exec($ch);

    $status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);

    //打印结果
    var_dump($response);
}

回复内容:

返回的结果是401 Sign error

public function delete($path) {
    //比如http://www.xx.com/a/b.jpg,我传过来删除的就是/a/b.jpg
    //删除部分略过
    //刷新缓存开始
    $ch = curl_init('http://purge.upyun.com/purge/');
    $date = gmdate('D, d M Y H:i:s \G\M\T');

    //这里签名我是直接用的$path,我是怀疑这里错了 但是我试过http://www.xx.com加在前面也还是错误
    $sign = md5($path.'&'.$this->bucket.'&'.$date.'&'.md5($this->password));

    //头信息
    $header = array(
        'Expect: ""',
        'Authorization: UpYun '.$this->config['bucket'].':'.$this->config['username'].':'.$sign,
        'Date: '.$date,
        'Content-Type: application/x-www-form-urlencoded',
    );
    curl_setopt($ch,CURLOPT_HTTPHEADER,$header);

    //POST方式
    curl_setopt($ch,CURLOPT_POST,1);

    //这里也是个问题,我不知道这个要不要提交过去
    $data = array(
        'purge' => urlencode($path),
    );
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

    //是否返回头信息
    curl_setopt($ch,CURLOPT_HEADER,1);

    $response = curl_exec($ch);

    $status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);

    //打印结果
    var_dump($response);
}

$path 后面加 \n,类似:http://www.xx.com/a/b.jpg\n

人气教程排行