function attachment_alioss_buctkets($key, $secret) { require '../framework/library/alioss/sdk.class.php'; $oss = new ALIOSS($key, $secret); $response = $oss->list_bucket(); if (!empty($response)) { $xml = isimplexml_load_string($response->body, 'SimpleXMLElement', LIBXML_NOCDATA); $buckets = json_decode(json_encode($xml), true); } if (empty($buckets['Buckets']['Bucket'][0])) { $buckets['Buckets']['Bucket'] = array($buckets['Buckets']['Bucket']); } $bucket_container = array(); if (!empty($buckets['Buckets']['Bucket'])) { foreach ($buckets['Buckets']['Bucket'] as $bucket) { $bucket_container[$bucket['Name']] = array('name' => $bucket['Name'], 'location' => $bucket['Location']); } } return $bucket_container; }
public function authorize() { global $_G, $_GET, $clouds; if (empty($_G['uid'])) { dsetcookie('_refer', rawurlencode(BASESCRIPT . '?mod=connect&op=oauth&bz=ALIOSS')); showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1)); } if (submitcheck('alisubmit')) { $access_id = $_GET['access_id']; $access_key = $_GET['access_key']; $hostname = $_GET['hostname']; $bucket = $_GET['bucket']; if (!$access_id || !$access_key) { showmessage('please input aliyun Access Key ID and Access Key Secret', dreferer()); } if (!$bucket || !$hostname) { showmessage('请选择bucket和节点地址', dreferer()); } require_once DZZ_ROOT . './core/api/oss_sdk/sdk.class.php'; $oss = new ALIOSS($access_id, $access_key, $hostname); try { $response = $oss->list_bucket(); if (!$response->isOK()) { showmessage('aliyun Access Key ID or Access Key Secret error', dreferer()); } } catch (Exception $e) { showmessage($e->getMessage(), dreferer()); } $type = 'ALIOSS'; $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, 'hostname' => $hostname, '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, $setarr, "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_ALIOSS'); } }