Ucenter 头像存储到BOS插件
小****子 · 小****子 发布于2016-06-21 17:29 浏览:2551 回复:2
1.Ucenter获取头像位置的程序是ucenter/avatar.php
2.上传头像的控制程序是ucenter/control/user.php : onrectavatar()这个函数。知道了这个之后,利用bos API签名算法就可以实现将ucenter头像直接上传到BOS。

主要是这个函数upload_bos:

    function upload_bos($localpath,$info,$path){
    // 内网和外网自行修改 推荐内网
    date_default_timezone_set('UTC');
    $timestamp = date("Y-m-d")."T".date("H:i:s")."Z";
    $host       = 'http://bj.bcebos.com';
    $AK  = '自己的AK';
    $SK = '自己的SK';
    $bucket     = 'flask-zxd';
    $expirationPeriodInSeconds = "3600";

    $authStringPrefix = "bce-auth-v1"."/".$AK."/".$timestamp."/".$expirationPeriodInSeconds;
    $SigningKey=hash_hmac('SHA256',$authStringPrefix,$SK);
    $CanonicalHeaders1 = "host;"."x-bce-date";
    $CanonicalHeaders2 = "host:bj.bcebos.com\n"."x-bce-date:".urlencode($timestamp);
    $CanonicalString = "";
    $CanonicalURI = '/' . $bucket . '/avatar/' . $path;
    $CanonicalRequest = "PUT\n".$CanonicalURI."\n".$CanonicalString."\n".$CanonicalHeaders2;    //第二步

    $Signature = hash_hmac('SHA256',$CanonicalRequest,$SigningKey);
    $Authorization = "bce-auth-v1/{$AK}/".$timestamp."/{$expirationPeriodInSeconds}/{$CanonicalHeaders1}/{$Signature}";
    print $Authorization."\n";

    $mime = $info['mime'];
    $head =  array("Content-Type: {$mime}","Authorization:{$Authorization}","x-bce-date:{$timestamp}");
    $timeout    = 30;
    $length     = filesize($localpath);
    $uri = '/' . $bucket . '/avatar/' . $path;

    $resource = fopen($localpath, 'r');
    $ch  = curl_init($host . $uri);

    curl_setopt($ch, CURLOPT_HEADER,true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_INFILE, $resource);
    curl_setopt($ch, CURLOPT_INFILESIZE, $length);
    curl_setopt ($ch, CURLOPT_UPLOAD, true );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    $response = curl_exec($ch);
    $status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    fclose($resource);
    if ($status == 200) {
        print "success";
        return true;
    } else {
        print $response;
        return false;
    }

签名算法可以参考百度的官方文档: https://bce.baidu.com/doc/Reference/AuthenticationMechanism.html

这两个文件我扔到github上了,地址: https://github.com/tanxiniao/bce/tree/master/ucenter_bos


点赞  ( 1 )
收藏
评论(2)
共2条回复 最后由数****络回复于2017-11-29 11:57
#2数****络回复于2017-11-29 11:57:09

0
#3二****白回复于2018-01-13 02:24:30

https://www.apple.com/us/search/54%E6%A9%A1%E8%83%B6%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8E%8B%E7%BC%A9%E6%B0%94%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/r77%E5%B7%A6%E8%BD%AE%E6%B0%94%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%AF%94%E8%B5%9B%E7%94%A8%E6%B0%94%E6%89%8B%E6%9E%AA%E4%BB%B7%E6%A0%BC%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%AF%94%E8%B5%9B%E4%B8%93%E7%94%A8%E6%B0%94%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%BE%B7%E5%9B%BD%E9%92%A2%E7%8F%A0%E6%B0%94%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%8E%A9%E4%BB%BF%E7%9C%9F%E6%B0%94%E6%89%8B%E6%9E%AA%E4%BC%9A%E6%80%8E%E4%B9%88%E6%A0%B7%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E8%B4%AD%E9%92%A2%E7%8F%A0%E6%B0%94%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E8%8E%AB%E9%87%8C%E5%B0%BC%E6%B0%94%E6%89%8B%E6%9E%AA%E5%B0%84%E5%87%BB%E5%90%A7%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E6%B9%BE%E6%B0%94%E6%89%8B%E6%9E%AA%E5%8E%9F%E7%90%86%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E9%92%A2%E7%8F%A0%E6%B0%94%E6%89%8B%E6%9E%AA%E5%9B%BE%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%9C%80%E5%A5%BD%E9%92%A2%E7%8F%A0%E6%B0%94%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E9%92%A2%E7%8F%A0%E6%B0%94%E6%89%8B%E6%9E%AA%E5%B0%84%E7%A8%8B%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%B0%94%E6%89%8B%E6%9E%AA%E6%89%93%E9%92%A2%E7%8F%A0%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E4%BB%BF%E7%9C%9F%E6%B0%94%E6%89%8B%E6%9E%AA%E4%BB%B7%E6%A0%BC%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E4%BB%BF%E7%9C%9F%E6%89%93%E9%B8%9F%E6%B0%94%E6%89%8B%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E4%BB%B7%E6%A0%BC%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E5%8E%89%E5%AE%B3%E4%B8%8D%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%85%B3%E4%BA%8E%E5%8F%B0%E7%A7%83%E5%92%8C%E5%9B%BD%E7%A7%83%E7%9A%84%E9%97%AE%E9%A2%98%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E6%9C%89%E6%95%88%E5%B0%84%E7%A8%8B%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E5%92%8C%E7%BE%8E%E7%A7%83%E5%A8%81%E5%8A%9B%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E5%8F%AF%E4%BB%A5%E4%B8%8A%E5%A4%9A%E5%B0%91%E5%AD%90%E5%BC%B9%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E5%86%85%E9%83%A8%E7%BB%93%E6%9E%84%E5%9B%BE%E7%BA%B8%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/pcp%E5%8F%B0%E7%A7%83%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E5%A8%81%E5%8A%9B%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E4%B8%8E%E7%BE%8E%E7%A7%83%E7%9A%84%E5%8C%BA%E5%88%AB%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%BE%8E%E5%9B%BD%E7%A7%83%E9%B9%B0%E5%92%8C%E5%8F%B0%E7%A7%83%E5%8C%BA%E5%88%AB%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E5%92%8C%E7%BE%8E%E7%A7%83%E5%8C%BA%E5%88%AB%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%80%8E%E6%A0%B7%E9%89%B4%E5%88%AB%E5%9B%BD%E7%A7%83%E5%8F%B0%E7%A7%83%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E7%A7%83%E5%B0%84%E7%A8%8B%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%B8%A6%E6%9C%A8%E6%89%98%E7%9A%84%E5%8F%B0%E6%B9%BE%E7%A7%83%E9%B9%B0%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E6%B9%BE%E7%A7%83%E9%B9%B0%E4%BB%8B%E7%BB%8D%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E6%B9%BE%E7%A7%83%E9%B9%B0%E8%B4%A8%E9%87%8F%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8F%B0%E6%B9%BE%E7%A7%83%E9%B9%B0qiqiang%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%B3%B0%E5%9B%BD%E7%A7%83%E9%B9%B0pcp%E4%BB%B7%E6%A0%BC%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E7%8B%99%E5%87%BB%E6%9E%AA%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%BE%8E%E5%9B%BD%E7%A7%83%E9%B9%B0%E7%8B%99%E5%87%BB%E6%9E%AA%E5%8E%9F%E7%90%86%E5%9B%BE%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%B9%BF%E5%B7%9E%E7%A7%83%E9%B9%B0%E6%B0%94%E6%AD%A5%E6%9E%AA%E9%85%8D%E4%BB%B6%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E6%B0%94%E6%AD%A5%E6%9E%AA%E7%9A%84%E6%9C%89%E6%95%88%E5%B0%84%E7%A8%8B%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E6%B0%94%E6%AD%A5%E6%9E%AA%E6%8A%A5%E4%BB%B7%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E6%B0%94%E6%AD%A5%E6%9E%AA%E5%9B%BE%E7%89%87%E6%8A%A5%E4%BB%B7%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%BE%8E%E5%9B%BD%E9%80%A0%E7%A7%83%E9%B9%B0%E6%B0%94%E6%AD%A5%E6%9E%AA%E6%8A%A5%E4%BB%B7%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E6%B0%94%E9%98%80%E5%87%BB%E9%94%A4%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E6%B0%94%E9%98%80%E7%9A%84%E8%A3%85%E6%B3%95%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E6%81%92%E5%8E%8B%E6%B0%94%E9%98%80%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E7%A7%83%E9%B9%B0%E6%B0%94%E9%98%80%E7%BB%B4%E4%BF%AE%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%9E%AA%E7%AE%A1%E5%AF%BF%E5%91%BD%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%82%AC%E6%B5%AE%E6%9E%AA%E7%AE%A1%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%9E%AA%E7%AE%A1%E6%9D%90%E6%96%99%E5%AD%A6%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E5%8D%81%E4%B9%9D%E4%B8%96%E7%BA%AA%E6%9E%AA%E7%AE%A1%E6%9D%90%E6%96%99%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%9E%AA%E7%AE%A1%E7%9A%84%E6%9D%90%E6%96%99%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav

https://www.apple.com/us/search/%E6%9E%AA%E7%AE%A1%E5%88%B7%20%E2%98%85%E8%B4%AD%E6%9E%AA%E2%95%86Q2140465565?src=globalnav


TOP