• 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');
    		}
    		
    	}
    
  • 相关阅读:
    VUE2.0项目实现动态修改请求的服务器地址
    el-select和data
    el-tree禁用
    国际化全部整理
    洛谷P2899 Cell Phone Network G 题解
    【nvidia jetson xavier】 Deepstream Yolov3示例模型运行
    【nvidia jetson xavier】 风扇开机自启动
    A Semisupervised CRF Model for CNN-Based Semantic Segmentation With Sparse Ground Truth
    Semi-supervised semantic segmentation needs strong, varied perturbations
    Remote Sensing Images Semantic Segmentation with General Remote Sensing Vision Model via a Self-Supervised Contrastive Learning Method
  • 原文地址:https://www.cnblogs.com/mr-amazing/p/3773034.html
Copyright © 2020-2023  润新知