PHPcms 把盛大登陆换成人人网登陆

PHPcms 把盛大登陆换成人人网登陆,第1张

PHPcms 把盛大登陆换成人人网登陆

首先要确保你的 phpcms是比较新的版本, v9.3以后的吧

这里说明一个函数 rawurlencode() 本函数将字符串编码成 URL 的字符串专用格式,特殊的字符会转换成百分比符号后面加上二个十六位数字的格式。


例如,空格就会变成 %20。


修改member/class/OauthSDK.class.php

protected $systemParam = array(
'connectTimeout' => 5 ,
'timeout' => 3 ,
'gatewayUrl' => 'http://api.renren.com' ,
'authorizeURL' => 'http://graph.renren.com/oauth/authorize' ,
'accessTokenURL' => 'https://graph.renren.com/oauth/token' ,
'systemTokenURL' => 'https://graph.renren.com/oauth/token' ,
'gatewayHost' => 'api.renren.com' ,
'gatewayPort' => 8888
);
//Get accesstoken
public function getAccessToken ($code)
{
$this->_clearError();
$clientID = $this->appId;
$redirectURI = $this->redirectURI;
$clientSecret = $this->appSecret;
$accessTokenURL = self::accessTokenURL();
$url = "{$accessTokenURL}?&grant_type=authorization_code&code={$code}&client_id={$clientID}&client_secret={$clientSecret}&redirect_uri={$redirectURI}"; $result = self::http($url);
$access_token = json_decode($result, TRUE);
if (empty($access_token) || isset($access_token['error'])) {
$this->_setOAuthError($access_token);
return FALSE;
} else {
return $access_token;
}
}

修改member/index.php 中的代码

/**
* 盛大通行证登陆 自己修改为人人登陆接口
*/
public function public_snda_login() {
define('SNDA_AKEY', pc_base::load_config('system', 'snda_akey'));
define('SNDA_SKEY', pc_base::load_config('system', 'snda_skey'));
define('SNDA_CALLBACK', urlencode(APP_PATH.'index.php?m=member&c=index&a=public_snda_login&callback=1')); pc_base::load_app_class('OauthSDK', '' ,0);
$this->_session_start();
if(isset($_GET['callback']) && trim($_GET['callback'])) { $o = new OauthSDK(SNDA_AKEY, SNDA_SKEY, SNDA_CALLBACK);
$code = $_REQUEST['code']; $accesstoken = $o->getAccessToken($code); //var_dump($accesstoken['user']['id']);exit();
if(is_numeric($accesstoken['user']['id'])) {
$userid = $accesstoken['user']['id'];
$username = $accesstoken['user']['name'];
} else {
showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login');
} if(!empty($userid)) {
//检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面
$where = array('connectid'=>$userid, 'from'=>'renren');
$r = $this->db->get_one($where); //connect用户已经绑定本站用户
if(!empty($r)) {
//读取本站用户信息,执行登录 *** 作
$password = $r['password'];
$this->_init_phpsso();
$synloginstr = $this->client->ps_member_synlogin($r['phpssouid']);
$userid = $r['userid'];
$groupid = $r['groupid'];
$username = $r['username'];
$nickname = empty($r['nickname']) ? $username : $r['nickname'];
$this->db->update(array('lastip'=>ip(), 'lastdate'=>SYS_TIME, 'nickname'=>$me['name']), array('userid'=>$userid));
if(!$cookietime) $get_cookietime = param::get_cookie('cookietime');
$_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);
$cookietime = $_cookietime ? TIME + $_cookietime : 0; $phpcms_auth_key = md5(pc_base::load_config('system', 'auth_key').$this->http_user_agent);
$phpcms_auth = sys_auth($userid."\t".$password, 'ENCODE', $phpcms_auth_key); param::set_cookie('auth', $phpcms_auth, $cookietime);
param::set_cookie('_userid', $userid, $cookietime);
param::set_cookie('_username', $username, $cookietime);
param::set_cookie('_groupid', $groupid, $cookietime);
param::set_cookie('cookietime', $_cookietime, $cookietime);
param::set_cookie('_nickname', $nickname, $cookietime);
param::set_cookie('_from', 'snda');
$forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?m=member&c=index';
showmessage(L('login_success').$synloginstr, $forward);
} else {
//d出绑定注册页面
$_SESSION = array();
$_SESSION['connectid'] = $userid;
$_SESSION['from'] = 'renren';
$connect_username = $username;
include template('member', 'connect');
}
}
} else {
$o = new OauthSDK(SNDA_AKEY, SNDA_SKEY, SNDA_CALLBACK);
$accesstoken = $o->getSystemToken();
$aurl = $o->getAuthorizeURL(); include template('member', 'connect_snda');
} }

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/586850.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存