Beispiel #1
0
 /**
  * 用户通过第三方登陆方式来注册
  * @param String $openid 第三方提供的用户信息唯一标识,一般是保密的
  * @param String $name 第三方提供的昵称信息
  * @param Number $sex 第三方提供用户性别 0 男,1女
  * @param String $avatar_url 第三方提供用户头像url
  * @param String $sign 个性签名
  * @param String $type 第三方类型, 2 微信,3 QQ ,4微博
  * @return Number $uid 注册成功返回的Uid
  */
 public function userRegThroughThird($openid, $name, $sex, $avatar_url, $sign, $type)
 {
     $wechat_auth_str = $type == LOGIN_TYPE_WECHAT ? md5($openid) : '';
     $qq_auth_str = $type == LOGIN_TYPE_QQ ? md5($openid) : '';
     $weibo_auth_str = $type == LOGIN_TYPE_WEIBO ? md5($openid) : '';
     $user_data = array('phone' => 0, 'name' => $name, 'pwd' => '', 'spacebg' => 'files/spacebg/default.jpg', 'sex' => $sex, 'sign' => $sign, 'wechat_auth_str' => $wechat_auth_str, 'qq_auth_str' => $qq_auth_str, 'weibo_auth_str' => $weibo_auth_str, 'regtime' => date('Y-m-d H:i:s'));
     $uid = $this->user->insert($user_data);
     // 这个地方图片头像需要想办法处理一下
     // 生成对应的文件夹
     $path = 'files/avatar/' . date('Ymd') . '/';
     $ori_path = $path . 'ori/';
     $sm_path = $path . 'sm/';
     if (!is_dir($path)) {
         mkdir($path);
         mkdir($ori_path);
         mkdir($sm_path);
     }
     // 头像的处理
     if (!empty($avatar_url)) {
         $filename = date('YmdHis') . rand(0, 9);
         $ori_img_path = $ori_path . $filename . '.jpg';
         $sm_img_path = $sm_path . $filename . '.jpg';
         $round_img_path = $sm_path . $filename . '_round.png';
         $tmp_round_img_path = $sm_path . $filename . '_round_tmp.jpg';
         try {
             // 原图片的存储
             Log::write('begin to download avatar');
             $img = http_get_data($avatar_url);
             Log::write('download ok');
             file_put_contents(SKY_ROOT . $ori_img_path, $img);
             Log::write('save ok');
             // 缩略图的存储
             $ic = new ImgCrop(SKY_ROOT . $ori_img_path, SKY_ROOT . $sm_img_path);
             $ic->Crop(200, 200, 1);
             $ic->SaveImage();
             $ic->destory();
             // round小图的存储,好麻烦
             $ic = new ImgCrop(SKY_ROOT . $ori_img_path, SKY_ROOT . $tmp_round_img_path);
             $ic->Crop(100, 100, 4);
             $ic->SaveImage();
             $ic->destory();
             $rounder = new RoundCorner(SKY_ROOT . $tmp_round_img_path, 50);
             $rounder->round_it(SKY_ROOT . $round_img_path);
             unlink(SKY_ROOT . $tmp_round_img_path);
             $imgs = new Imgs();
             $mid = $imgs->insert(array('uid' => $uid, 'ori' => $ori_img_path, 'sm' => $sm_img_path, 'upload_time' => date('Y-m-d H:i:s')));
             if (!empty($mid)) {
                 $user = new User();
                 $user->update(array('avatar' => $mid), array('uid' => $uid));
             }
         } catch (Exception $e) {
             Log::write('get remote avatar ERR');
         }
     }
     return $uid;
     // 注册成功,返回$uid
 }
Beispiel #2
0
 public function roundThumb($width)
 {
     if ($this->canUpload && $this->doUpFile != '') {
         $_ext = $this->getExt();
         $_srcImage = SKY_ROOT . $this->sm_File;
         $_dstImage = SKY_ROOT . $this->sm_directory . $this->doUpFile . "_round." . $_ext;
         $_dstImageRound = SKY_ROOT . $this->sm_directory . $this->doUpFile . "_round.png";
         $ic = new ImgCrop($_srcImage, $_dstImage);
         $ic->Crop($width, $width, 4);
         $ic->SaveImage();
         $ic->destory();
         $rounder = new RoundCorner($_dstImage, $width / 2);
         $rounder->round_it($_dstImageRound);
         unlink($_dstImage);
     }
 }