Exemplo n.º 1
0
 /**
  * 生成新用户 - 通用入口
  *
  * @param string $username 用户名
  * @param string $nickname 昵称
  * @param string $avatar 头像链接
  * @return int 用户id
  */
 protected static function createUser($username, $nickname, $avatar)
 {
     $newUserInfo = array();
     $newUserInfo['username'] = $username;
     $newUserInfo['nickname'] = $nickname;
     $newUserInfo['avatar'] = !empty($avatar) ? $avatar : '';
     $newUserInfo['salt'] = PhalApi_Tool::createRandStr(32);
     $newUserInfo['password'] = '******';
     $newUserInfo['reg_time'] = $_SERVER['REQUEST_TIME'];
     $userModel = new Model_User_User();
     return $userModel->insert($newUserInfo);
 }
Exemplo n.º 2
0
 /**
  * 文件上传
  * @param string $filePath 待上传文件的绝对路径
  * @return string 上传成功后的URL,失败时返回空
  */
 public function uploadFile($filePath)
 {
     $fileUrl = '';
     if (!file_exists($filePath)) {
         return $fileUrl;
     }
     $config = $this->config;
     $fileName = date('YmdHis_', $_SERVER['REQUEST_TIME']) . md5(PhalApi_Tool::createRandStr(8) . microtime(true));
     Qiniu_SetKeys($config['accessKey'], $config['secretKey']);
     $putPolicy = new Qiniu_RS_PutPolicy($config['space_bucket']);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $fileName, $filePath, $putExtra);
     if ($err !== null) {
         DI()->logger->debug('failed to upload file to qiniu', array('Err' => $err->Err, 'Reqid' => $err->Reqid, 'Details' => $err->Details, 'Code' => $err->Code));
     } else {
         $fileUrl = $config['space_host'] . '/' . $fileName;
         DI()->logger->debug('succeed to upload file to qiniu', $ret);
     }
     return $fileUrl;
 }
Exemplo n.º 3
0
 /**
  * @group testCreateRandStr
  */
 public function testCreateRandStr()
 {
     $len = '5';
     $rs = PhalApi_Tool::createRandStr($len);
     $this->assertEquals($len, strlen($rs));
 }