本帖最后由 strangebank 于 2011-8-2 10:13 编辑
说明: 文件中包含的类文件大部分内容来自互联网。版权归原创者所有,也感谢他们的分享精神。
类以外文件不做版权说明。代码没有做优化,需要的朋友可根据自己实际情况优化,有金币的给个金币没金币的也可以下载!有不明白的地方,请留言,me不定期答疑。
官方演示地址 http://www.miaomimi.com/index.php注意: 文件中的编码需要特别注意。如果是非utf-8的请注意修改函数 showmessage()。
P.S :希望大家关注流浪猫or其他小动物,有身边喜欢猫的朋友也欢迎推荐。
喜欢的朋友 http://t.sina.com.cn/miaomimi 粉丝下吧!
文件 weibooauth.php 到 http://code.google.com/p/libweibo/下载
- <?php
- header("Content-type:text/html;charset=utf-8");
- define( "WB_AKEY" , '' );
- define( "WB_SKEY" , '' );
- include_once("../../common.php");
- include_once('function.php');
- ?>
复制代码 以上两个 KEY 到官方申请
- <?php
- if($_GET['debug=1']) {phpinfo();exit;}
- session_start();
- #if( isset($_SESSION['last_key']) ) header("Location: weibolist.php");
- include_once( 'config.php' );
- include_once( 'weibooauth.php' );
- $o = new WeiboOAuth( WB_AKEY , WB_SKEY );
- $keys = $o->getRequestToken();
- $aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , 'http://www.miaomimi.com/plugins/sinablog/callback.php');
- $_SESSION['keys'] = $keys;
- if($aurl){
- #header("Location: $aurl");
- #exit();
- }
- ?>
- <a href="<?=$aurl?>"><img src="http://i3.dpfile.com/s/res/sina_t_btn.v3.png" alt="新浪微博登录" /></a>
复制代码
- <?php
- session_start();
- include_once( 'config.php' );
- include_once( 'weibooauth.php' );
- $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] );
- $msg = $c->verify_credentials();
- $jumpurl = $app?"userapp.php?id=$app&my_extra=invitedby_bi_{$uid}_{$code}&my_suffix=Lw%3D%3D":'space.php?do=home';
- #print_r($msg);
- if ($msg === false || $msg === null){
- echo "Error occured";
- return false;
- }else{
- $step = $_GET['m']?$_GET['m']:'continue';
- if(!@include_once S_ROOT.'./uc_client/client.php') {
- showmessage('system_error');
- }
- if($step =='continue'){
- #continue
- #print_r($msg);
- #die();
- }elseif($step=='bind'){
- $password = $_POST['password'];
- $username = trim($_POST['username']);
- //同步获取用户源
- if(!$passport = getpassport($username, $password)) {
- showmessage('login_failure_please_re_login', 'do.php?ac='.$_SCONFIG['login_action']);
- }
- $newuid=$uid = $passport['uid'];
- }
-
- foreach($msg as $k=>$v){
- if($k=='verified')break;
- $k =iconv('utf-8','gbk',$v);
- }
- $note =$msg->status->text;//['text'];
- $sql = "select openuid,brageid from uc_open_api_members where brageid!=0 and openuid = '$id'";
- $queryc = $_SGLOBAL['db']->query($sql);
- if($now =$_SGLOBAL['db']->fetch_array($queryc)) {
- #登录过了
- $brageid = $now['brageid'];
- $username= $name;
- $password = trim('miao'.$id);
- //同步获取用户源
- if(!$passport = getpassport($username, $password)) {
- showmessage('login_failure_please_re_login', 'do.php?ac='.$_SCONFIG['login_action']);
- }
- $setarr = array(
- 'uid' => $passport['uid'],
- 'username' => addslashes($passport['username']),
- 'password' => md5("$passport[uid]|$_SGLOBAL[timestamp]")//本地密码随机生成
- );
- include_once(S_ROOT.'./source/function_space.php');
- //开通空间
- $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('space')." WHERE uid='$setarr[uid]'");
- if(!$space = $_SGLOBAL['db']->fetch_array($query)) {
- $space = space_open($setarr['uid'], $setarr['username'], 0, $passport['email']);
- }
- $_SGLOBAL['member'] = $space;
- //实名
- realname_set($space['uid'], $space['username'], $space['name'], $space['namestatus']);
- //检索当前用户
- $query = $_SGLOBAL['db']->query("SELECT password FROM ".tname('member')." WHERE uid='$setarr[uid]'");
- if($value = $_SGLOBAL['db']->fetch_array($query)) {
- $setarr['password'] = addslashes($value['password']);
- } else {
- //更新本地用户库
- inserttable('member', $setarr, 0, true);
- }
- //清理在线session
- insertsession($setarr);
- ssetcookie('auth', authcode("$setarr[password]\t$setarr[uid]", 'ENCODE'), 2592000);
- ssetcookie('loginuser', $passport['username'], 31536000);
- ssetcookie('_refer', '');
- //同步登录
- if($_SCONFIG['uc_status']) {
- include_once S_ROOT.'./uc_client/client.php';
- $ucsynlogin = uc_user_synlogin($setarr['uid']);
- } else {
- $ucsynlogin = '';
- }
- $_SGLOBAL['supe_uid'] = $space['uid'];
- if(empty($_POST['refer'])) {
- $_POST['refer'] = 'space.php?do=home';
- }
- header("Location: http://www.miaomimi.com/space.php?do=home&ref=sianminiblog");
- }else{
- $username = trim($name);
- $password = 'miao'.$id;
- $email = $domain.'@miaomimi.com';
- $newuid = uc_user_register($username, $password, $email);
- if($newuid <= 0) {
- if($newuid == -1) {
- showmessage('user_name_is_not_legitimate');
- } elseif($newuid == -2) {
- showmessage('include_not_registered_words');
- } elseif($newuid == -3) {
- showmessage('user_name_already_exists');
- } elseif($newuid == -4) {
- showmessage('email_format_is_wrong');
- } elseif($newuid == -5) {
- showmessage('email_not_registered');
- } elseif($newuid == -6) {
- showmessage('email_has_been_registered');
- } else {
- showmessage('register_error');
- }
- } else {
- $setarr = array(
- 'uid' => $newuid,
- 'username' => $username,
- 'password' => md5("$newuid|$_SGLOBAL[timestamp]")//本地密码随机生成
- );
- //更新本地用户库
- inserttable('member', $setarr, 0, true);
- $image = str_replace('/50/','/180/',$profile_image_url);
- $mpath= str_replace('http://miaomimi.com/','../../',avatar_path($newuid,'big',true));
- $path= getImage($image,'test',0);
- rmkdir($mpath,'777');
- $them = array('big'=>array(180,180),
- 'small'=>array(50,50),
- 'middle'=>array(100,100));
-
- foreach($them as $k=>$v){
- $image= str_replace('http://miaomimi.com/','../../',avatar($newuid,$k,true));
- makethumb($path,$image,$v[0],$v[1]);
- }
- //开通空间
- include_once(S_ROOT.'./source/function_space.php');
- $space = space_open($newuid, $username, 0, $email);
- #修改头像状态 和 用户资料
- updatetable('space', array('avatar'=>1,'name'=>$name), array('uid'=>$newuid));
- $s = split(' ',$location);
- updatetable('spacefield', array('birthprovince'=>$s[0],'birthcity'=>$s[1],'resideprovince'=>$s[0],'residecity'=>$s[1],'spacenote'=>$description, 'note'=>$note), array('uid'=>$newuid));
-
- //在线session
- insertsession($setarr);
- //设置cookie
- ssetcookie('auth', authcode("$setarr[password]\t$setarr[uid]", 'ENCODE'), 2592000);
- ssetcookie('loginuser', $username, 31536000);
- ssetcookie('_refer', '');
- //变更记录
- if($_SCONFIG['my_status']) inserttable('userlog', array('uid'=>$newuid, 'action'=>'add', 'dateline'=>$_SGLOBAL['timestamp']), 0, true);
- $sql = "INSERT INTO uc_open_api_members (
- `openuid` ,
- `screen_name` ,
- `name` ,
- `province` ,
- `city` ,
- `location` ,
- `description` ,
- `url` ,
- `profile_image_url` ,
- `domain` ,
- `brageid` ,
- `addtime`
- )
- VALUES (
- '".$id."',
- '".$screen_name."',
- '".$name."',
- '".$province."',
- '".$city."',
- '".$location."',
- '".$description."',
- '".$url."',
- '".$profile_image_url."',
- '".$domain."',
- '".$newuid."',
- 'now()'
- );";
- $_SGLOBAL['db']->query($sql);
- #showmessage('registered', $jumpurl);
- header("Location: http://www.miaomimi.com/space.php?do=home'");
- }
- }
- exit();
- }
- ?>
复制代码
|