/** * 登陆回调 */ public function callbackLogin($request_args) { $user = $this->_om->getUserInfo($request_args); $bind_user = $this->_checkBind($this->_type, $user['keyid']); if ($bind_user) { //已经绑定过则更新绑定信息 自动登陆 $this->_updateBindInfo($user); $user_info = M('user')->field('id,username')->where(array('id' => $bind_user['uid']))->find(); //登陆 $this->_oauth_visitor()->assign_info($user_info); return U('user/index'); } else { //处理用户名 if (M('user')->where(array('username' => $user['keyname']))->count()) { $user['pin_user_name'] = $user['keyname'] . '_' . mt_rand(99, 9999); } else { $user['pin_user_name'] = $user['keyname']; } $user['pin_user_name'] = urlencode($user['pin_user_name']); $user['keyname'] = urlencode($user['keyname']); if ($user['keyavatar_big']) { //下载原始头像到本地临时储存 用日期文件夹分类 方便清理 $user['temp_avatar'] = ''; $avatar_temp_root = C('pin_attach_path') . 'avatar/temp/'; $temp_dir = date('ymd', time()) . '/'; $file_name = date('ymdhis' . mt_rand(1000, 9999)) . '.jpg'; mkdir($avatar_temp_root . $temp_dir, 0777, true); $image_content = \Common\ORG\Http::fsockopenDownload($user['keyavatar_big']); file_put_contents($avatar_temp_root . $temp_dir . $file_name, $image_content); $user['temp_avatar'] = $temp_dir . $file_name; } $user['type'] = $this->_type; //把第三方的数据存到COOKIE cookie('user_bind_info', $user); return U('user/binding'); //跳转到绑定注册页 } }
/** * 获取商品卖家ID */ private function _get_seller_id($iid) { $result = array('type' => 'taobao', 'id' => 0); $page_content = \Common\ORG\Http::fsockopenDownload('http://item.taobao.com/item.htm?id=' . $iid); if (!$page_content) { //$page_content = \Common\ORG\Http::fsockopenDownload('http://detail.tmall.com/item.htm?id='.$iid); $page_content = file_get_contents('http://detail.tmall.com/item.htm?id=' . $iid); $result['type'] = 'tmall'; } preg_match('|; userid=(\\d+);">|', $page_content, $out); $result['id'] = $out[1]; return $result; }
protected function _uploadRemote($remote, $dir, $thumb) { $content = \Common\ORG\Http::fsockopenDownload($remote); $savePath = PIN_DATA_ROOT . C('pin_attach_path') . $dir; // 检查上传目录 if (!is_dir($savePath)) { // 尝试创建目录 $c = 0; while (!mkdir($savePath, 0777, true) && $c < 10) { $c++; } if (!is_dir($savePath)) { return array('error' => '上传目录' . $savePath . '不存在'); } } else { if (!is_writeable($savePath)) { return array('error' => '上传目录' . $savePath . '不可写'); } } if (empty($content)) { return array('error' => '无法下载远程文件'); } $fname = uniqid(); $tf = rtrim(sys_get_temp_dir(), '/') . '/' . $fname; file_put_contents($tf, $content); switch (exif_imagetype($tf)) { case IMAGETYPE_GIF: rename($tf, $savePath . $fname . '.gif'); $fname .= '.gif'; $fext = '.gif'; break; case IMAGETYPE_JPEG: rename($tf, $savePath . $fname . '.jpg'); $fname .= '.jpg'; $fext = '.jpg'; break; case IMAGETYPE_PNG: rename($tf, $savePath . $fname . '.png'); $fname .= '.png'; $fext = '.png'; break; case IMAGETYPE_BMP: rename($tf, $savePath . $fname . '.bmp'); $fname .= '.bmp'; $fext = '.bmp'; break; default: rename($tf, $savePath . $fname); $fext = ''; break; } $filename = $savePath . $fname; import('ORG.Util.Image'); $thumbWidth = explode(',', $thumb['width']); $thumbHeight = explode(',', $thumb['height']); $thumbPrefix = explode(',', ''); $thumbSuffix = explode(',', $thumb['suffix']); $thumbPath = $savePath; $thumbExt = $fext; //自定义缩略图扩展名 for ($i = 0, $len = count($thumbWidth); $i < $len; $i++) { $prefix = isset($thumbPrefix[$i]) ? $thumbPrefix[$i] : $thumbPrefix[0]; $suffix = isset($thumbSuffix[$i]) ? $thumbSuffix[$i] : $thumbSuffix[0]; $thumbname = $prefix . basename($filename, $fext) . $suffix; \Common\ORG\Image::thumb($filename, $thumbPath . $thumbname . $thumbExt, '', $thumbWidth[$i], $thumbHeight[$i], true); } return array('savename' => $fname); }