Exemplo n.º 1
0
 public function authorize()
 {
     global $_G, $_GET, $clouds;
     if (empty($_G['uid'])) {
         dsetcookie('_refer', rawurlencode(BASESCRIPT . '?mod=connect&op=oauth&bz=JSS'));
         showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1));
     }
     if (submitcheck('jsssubmit')) {
         $access_id = $_GET['access_id'];
         $access_key = $_GET['access_key'];
         $bucket = $_GET['bucket'];
         if (!$access_id || !$access_key) {
             showmessage('请输入京东云存储的accessKey和secretKey', dreferer());
         }
         $jss = new JingdongStorageService($access_id, $access_key);
         try {
             $bucketslist = $jss->list_buckets();
         } catch (Exception $e) {
             showmessage('京东云存储测试连接失败,请确认accessKey和secretKey正确,且当前京东云存储可用', dreferer());
             //showmessage($e->getMessage(),dreferer());
         }
         $type = 'JSS';
         $uid = defined('IN_ADMIN') ? 0 : $_G['uid'];
         $setarr = array('uid' => $uid, 'access_id' => $access_id, 'access_key' => authcode($access_key, 'ENCODE', $type), 'bz' => $type, 'bucket' => $bucket, 'dateline' => TIMESTAMP);
         if ($id = DB::result_first("select id from " . DB::table(self::T) . " where uid='{$uid}' and access_id='{$access_id}' and bucket='{$bucket}'")) {
             DB::update(self::T, $token, "id ='{$id}'");
         } else {
             $id = DB::insert(self::T, $setarr, 1);
         }
         if (defined('IN_ADMIN')) {
             $setarr = array('name' => $clouds[$type]['name'] . ':' . ($bucket ? $bucket : cutstr($access_id, 4, '')), 'bz' => $type, 'isdefault' => 0, 'dname' => self::T, 'did' => $id, 'dateline' => TIMESTAMP);
             if (!DB::result_first("select COUNT(*) from %t where did=%d and dname=%s ", array('local_storage', $id, self::T))) {
                 C::t('local_storage')->insert($setarr);
             }
             showmessage('do_success', BASESCRIPT . '?mod=cloud&op=space');
         } else {
             showmessage('do_success', BASESCRIPT . '?mod=connect');
         }
     } else {
         include template('oauth_JSS');
     }
 }
Exemplo n.º 2
0
<!DOCTYPE html>
<html>
<head>
	<meta charset='utf-8'>
	<title></title>
</head>
<body>

</body>
</html>
<?php 
require_once 'libs/sdk/JingdongStorageService.php';
$storage = new JingdongStorageService("07395fe30c1d4db1b18efb8f3112630a", "e87b653c3d7949fda9f41259132d0a06cDGuQXYE");
$other_headers = array();
//可传入如Range等其他该请求可用的request header
$bucket_name = 'ebook';
$local_file = 'tmp/467.mobi';
$key = '467.mobi';
$storage->get_object($bucket_name, $key, $local_file, $other_headers);
print_r($other_headers);
echo '123';
$f = fopen('tmp/467.mobi', 'r');
echo fread($f, 10);
$bucketslist = $storage->list_buckets();
foreach ($bucketslist as $jss_bucket) {
    print_r("Bucket:" . $jss_bucket->get_name() . "\n");
    print_r("CTime: " . $jss_bucket->get_ctime() . "\n\n");
}
Exemplo n.º 3
0
function getFileUrl($fileName, $bucket)
{
    $storage = new JingdongStorageService(accesskey, secrectkey);
    try {
        $expire = 10 * 60;
        //十分钟后失效
        $url = $storage->get_object_resource($bucket, $fileName, $expire);
        return $url;
    } catch (Exception $e) {
        return '';
    }
}