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

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

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

修改member/class/OauthSDK.class.php

1
2
3
4
5
6
7
8
9
10
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
    );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//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 中的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
     * 盛大通行证登陆  自己修改为人人登陆接口
     */
    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 {               
                    //弹出绑定注册页面
                    $_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‘);
        }
         
    }

 

PHPcms 把盛大登陆换成人人网登陆,布布扣,bubuko.com

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

上一篇:[Nodejs] 错误 DEPTH_ZERO_SELF_SIGNED_CERT


下一篇:jquery 实现iframe 自适应高度