首页 > 文章 > 杂文

Ecshop集成新浪微博登录插件教程分享
时间:2014-02-24 13:56:13  点击: 来源:  作者:


近网站想添加新浪微博登录功能,于是在网上搜索了下,下载了一个插件的放我网站里面没效果,所以觉定自己动手试试,本人php新手说得不到之处还望大侠高手们多多指教。  1.先去http://open.weibo.com/ 这里 ...


       近网站想添加新浪微博登录功能,于是在网上搜索了下,下载了一个插件的放我网站里面没效果,所以觉定自己动手试试,本人php新手说得不到之处还望大侠高手们多多指教。

  1.先去http://open.weibo.com/ 这里申请app

  2.下载最新http://code.google.com/p/libweibo/downloads/list插件包

   2.1其中需要修改config.php文件

 define( "WB_AKEY" , '申请的到的key ); define( "WB_SKEY" , '相对应的App Secret' ); define( "WB_CALLBACK_URL" , 'http://域名/login/callback.php' );

   2.2 修改文件callback.php ,将此处代码复制全部替换

session_start();define('IN_ECS', true);require('../includes/init.php');include_once('../includes/lib_transaction.php');include_once('../includes/lib_passport.php');include_once( 'config.php' );include_once( 'saetv2.ex.class.php' );$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );if (isset($_REQUEST['code'])) {	$keys = array();	$keys['code'] = $_REQUEST['code'];	$keys['redirect_uri'] = WB_CALLBACK_URL;	try {		$token = $o->getAccessToken( 'code', $keys ) ;	} catch (OAuthException $e) {	}}if ($token) {	$_SESSION['token'] = $token;	setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );		$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );$ms  = $c->home_timeline(); // done$uid_get = $c->get_uid();$uid = $uid_get['uid'];$user_message = $c->show_user_by_id( $uid);//根据ID获取用户等基本信息function check_user($username){$sql = "SELECT user_id, password, salt " .                   " FROM " . $GLOBALS['ecs']->table("users").                   " WHERE user_name='$username'";            $row = $GLOBALS['db']->getRow($sql);            if (!empty($row)){    return true;   }else{    return false;    }}if($user_message['screen_name']!==""){ //获取微薄昵称  $username=$user_message['screen_name'];  $password=time();//随便弄个密码 反正没有用  $email='123456@163.com';//随便默认个邮箱  $back_act ="/user.php";        if (check_user($username)!==false){   $GLOBALS['user']->set_session($username);         $GLOBALS['user']->set_cookie($username);            header("Location: /user.php/n");  //验证成功,跳转页面   exit;        }else{   $reg_date = time();   $password =md5($password);   $ip=real_ip();   $GLOBALS['db']->query('INSERT INTO ' . $GLOBALS['ecs']->table("users") . "(`email`, `user_name`, `password`, `reg_time`, `last_login`, `last_ip`) VALUES ('$email', '$username', '$password', '$reg_date', '$reg_date', '$ip')");   $GLOBALS['user']->set_session($username);         $GLOBALS['user']->set_cookie($username);   header("Location: /user.php/n");   exit;   }}else{  echo 'fail';  exit;  }?> } else {?>授权失败。}?>

  修改的就这两文件,其中weibolist.php可以删除。

  3.然后将config.php、callback.php、index.php、saetv2.ex.class.php四个文件放login文件夹上传空间就行了。

  到这基本就完成了功能了,希望对有需要的站长有所帮助。

  本文作者分享演示站:http://www.diy520.cn

http://www.3lian.com/edu/2012/09-11/36501.html

”您可通过以下微信二维码,赞赏作者“
 
 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
linux服务器同步互联网时间
linux服务器同步互联
亚马逊云lightsail服务器使用教程 | 亚马逊云lightsail使用指南
亚马逊云lightsail服
hostdare 4折优惠,直接降价60% 美国洛杉矶低至 $10.4/年 768M内存/1核/10gNVMe/500g流量
hostdare 4折优惠,直接
六类网线cat6a和cat6e的区别
六类网线cat6a和cat6e
相关文章
栏目更新
栏目热门

关于我们 | 广告服务 | 联系我们 | 网站地图 | 免责声明 | WAP | RSS


Copyright © 运维之家 2013-2023