126 lines
2.6 KiB
PHP
126 lines
2.6 KiB
PHP
|
<?php
|
||
|
namespace Open;
|
||
|
|
||
|
use \stdClass;
|
||
|
|
||
|
class Source
|
||
|
{
|
||
|
private $website;
|
||
|
private $source;
|
||
|
private $target;
|
||
|
private $sourceType = array("westdc","heihedata","card");
|
||
|
|
||
|
public function __construct($website){
|
||
|
$this->source = new stdClass();
|
||
|
$this->target = new stdClass();
|
||
|
|
||
|
$this->website = $website;
|
||
|
|
||
|
$this->initSourceConfig();
|
||
|
$this->initTarget();
|
||
|
}
|
||
|
|
||
|
//获得当前绑定的站点
|
||
|
public function getCurrentSite(){
|
||
|
return $this->website;
|
||
|
}
|
||
|
|
||
|
//设置绑定的站点
|
||
|
public function setCurrentSite($website){
|
||
|
$this->website = $website;
|
||
|
$this->initSourceConfig();
|
||
|
}
|
||
|
|
||
|
private function initSourceConfig()
|
||
|
{
|
||
|
if(!in_array($this->website,$this->sourceType))
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// Escience
|
||
|
// passport.escience.cn
|
||
|
$this->source->escience = new stdClass();
|
||
|
$this->source->escience->param = array(
|
||
|
"id" => "client_id",
|
||
|
"secret" => "client_secret",
|
||
|
"code_response" => "response_type",
|
||
|
"grant_type" => "grant_type",
|
||
|
"callback" => "redirect_uri",
|
||
|
"code"=>"code"
|
||
|
);
|
||
|
|
||
|
if($this->website == 'westdc'){
|
||
|
|
||
|
$this->source->escience->config = array(
|
||
|
'id' => '71852',
|
||
|
'secret' => 'ad7gd3jZgbzhQM6vIh9vPnQFZQoTGHZI',
|
||
|
'index' => 'http://westdc.westgis.ac.cn',
|
||
|
'callback' => 'http://westdc.westgis.ac.cn/account/callback/type/escience',
|
||
|
'other' => array(
|
||
|
'theme'=>'full'
|
||
|
)
|
||
|
);
|
||
|
|
||
|
}
|
||
|
|
||
|
if($this->website == 'heihedata'){
|
||
|
|
||
|
$this->source->escience->config = array(
|
||
|
'id' => '78969',
|
||
|
'secret' => 'iTGKdCkUPakA2hza2TJ4XZ4cnwlh8Hqz',
|
||
|
'index' => 'http://www.heihedata.org',
|
||
|
'callback' => 'http://www.heihedata.org/account/callback/type/escience',
|
||
|
'other' => array(
|
||
|
'theme'=>'full'
|
||
|
)
|
||
|
);
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//获得一个源
|
||
|
public function getSource($type = "")
|
||
|
{
|
||
|
if(empty($type))
|
||
|
{
|
||
|
return $this->source;
|
||
|
}else{
|
||
|
if(isset($this->source->$type))
|
||
|
{
|
||
|
return $this->source->$type;
|
||
|
}else{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//Oauth2登录目标
|
||
|
private function initTarget(){
|
||
|
$this->target->escience = array(
|
||
|
'name' => '中国科技网通行证',
|
||
|
'code' => 'http://passport.escience.cn/oauth2/authorize',
|
||
|
'token' => 'https://passport.escience.cn/oauth2/token',
|
||
|
'code_response' => 'code',
|
||
|
'grant_type' => 'authorization_code',
|
||
|
);
|
||
|
}
|
||
|
|
||
|
//获得Oauth2登录模板
|
||
|
public function getTarget($type = "")
|
||
|
{
|
||
|
if(empty($type))
|
||
|
{
|
||
|
return $this->target;
|
||
|
}else{
|
||
|
if(isset($this->target->$type))
|
||
|
{
|
||
|
return $this->target->$type;
|
||
|
}else{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|