示例#1
0
 /**
  * 七牛中获取账户信息
  * @param  $username 七牛登录账号一般为邮箱
  * @param  $password 七牛登录密码
  * @param  $access_token 授权码
  */
 public function user_info($username, $password, $access_token)
 {
     $phppost = new PhpPost();
     //post提交
     $url = "https://acc.qbox.me/user/info";
     $data = array('grant_type' => 'password', 'username' => $username, 'password' => $password);
     $data = http_build_query($data);
     $user_result = $phppost->curl_post($url, $data, $access_token);
     $user_array = json_decode($user_result, true);
     return $user_array;
 }
示例#2
0
 public function actionsetdomainbyqiniu()
 {
     $ret = array('status' => 0, 'msg' => 'Set failure!');
     try {
         $phppost = new PhpPost();
         //post提交
         $qiniu = new erp_qiniu();
         //七牛的接口类
         $f_access_token = '';
         $f_username = '******';
         $f_password = '******';
         //$f_bucket='baiyitest';
         //父级获取账户凭证
         $f_access_token = $qiniu->oauth2_token($f_username, $f_password);
         if (empty($f_access_token)) {
             throw new Exception('Set failure!');
         }
         $brandid = 0;
         //品牌ID号
         $access_token = '';
         $username = '******';
         //test5@beubeu.com
         $password = '******';
         //123456789
         $uid = 0;
         $bucket = 'baiyitest2';
         //baiyitest2
         $domain = 'www.beubeu.com';
         //自定义域名www.beubeu.com
         $icp = '沪ICP备10035694号';
         //域名的备案号沪ICP备10035694号
         if (Yii::app()->request->getParam('brandid')) {
             $brandid = Yii::app()->request->getParam('brandid');
         }
         if (Yii::app()->request->getParam('username')) {
             $username = Yii::app()->request->getParam('username');
         }
         if (Yii::app()->request->getParam('password')) {
             $password = Yii::app()->request->getParam('password');
         }
         if (Yii::app()->request->getParam('bucket')) {
             $bucket = Yii::app()->request->getParam('bucket');
         }
         if (Yii::app()->request->getParam('domain')) {
             $domain = Yii::app()->request->getParam('domain');
         }
         if (Yii::app()->request->getParam('icp')) {
             $icp = Yii::app()->request->getParam('icp');
         }
         if (empty($brandid) || empty($username) || empty($password) || empty($bucket) || empty($domain) || empty($icp)) {
             throw new Exception('请将数据信息填写完成后再设置!');
         }
         //子账户获取账户凭证
         $access_token = $qiniu->oauth2_token($username, $password);
         if (empty($access_token)) {
             throw new Exception('Set failure!');
         }
         if (!empty($access_token)) {
             //获取账户信息
             $access_token = 'Bearer ' . $access_token;
             $user_array = $qiniu->user_info($username, $password, $access_token);
             if (count($user_array) > 0 && isset($user_array['uid'])) {
                 $uid = $user_array['uid'];
                 $f_access_token = 'Bearer ' . $f_access_token;
                 //自定义域名
                 $url = "https://api.qiniu.com/v6/oem/user/" . $uid . "/bucket/" . $bucket . "/customdomain";
                 $data = array('domain' => $domain, 'icp' => $icp);
                 $data = http_build_query($data);
                 $domain_result = $phppost->curl_post($url, $data, $f_access_token);
                 $domain_result_array = json_decode($domain_result, true);
                 if (count($domain_result_array) > 0) {
                     if (isset($domain_result_array['success']) && $domain_result_array['success'] == true) {
                         try {
                             //通过品牌ID修改设置的域名信息
                             erp_qiniu_account::model()->updateAll(array('domain' => $domain), 'brandid=:textx', array(':textx' => $brandid));
                         } catch (BeubeuException $e) {
                             throw new Exception('Set failure!');
                         }
                         $ret['msg'] = 'set success';
                         $ret['status'] = 1;
                     } else {
                         $ret['msg'] = $domain_result_array['message'];
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     echo json_encode($ret);
     exit;
 }