zoukankan      html  css  js  c++  java
  • 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."	".$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');
    		}
    		
    	}
    
  • 相关阅读:
    读书笔记:《HTML5开发手册》-- 现存元素的变化
    关于微信小程序,一些想法
    HTML5--details活学活用
    读书笔记:《HTML5开发手册》--figure、time、details、mark
    读书笔记:《HTML5开发手册》--HTML5新的结构元素
    微信小程序开源项目库汇总
    Debian安装fail2ban来防止扫描
    Debian更新软件源提示There is no public key available for the following key IDs的解决方法
    JavaBugCharSequence
    分析 《7吨碳九泄漏,40万泉港人在无声中消逝》虚假报道
  • 原文地址:https://www.cnblogs.com/mr-amazing/p/3773034.html
Copyright © 2011-2022 走看看