增加Ourbits验证方法

This commit is contained in:
iyuu.cn
2019-12-23 13:50:11 +08:00
parent 63a6894d97
commit 9043bcfc8a
3 changed files with 69 additions and 0 deletions

67
app/Class/Oauth.php Normal file
View File

@ -0,0 +1,67 @@
<?php
/**
* IYUU用户注册、认证
*/
use Curl\Curl;
class Oauth{
// 合作的站点
public static $sites = ['ourbits'];
// 爱语飞飞token
public static $token = '';
// 合作站点用户id
public static $user_id = 0;
// 合作站点密钥
public static $passkey = '';
// 合作站名字
public static $site = '';
public static function init(){
global $configALL;
foreach (self::$sites as $name) {
if (isset($configALL[$name]['passkey']) && $configALL[$name]['passkey'] && isset($configALL[$name]['id']) && $configALL[$name]['id'] ) {
self::$token = self::getSign();
self::$user_id = $configALL[$name]['id'];
self::$passkey = sha1( $configALL[$name]['passkey'] ); // 避免泄露用户passkey秘钥
self::$site = $name;
return true;
}
}
echo "-----缺少用户登录参数token, user_id, passkey, name \n";
echo "-----当前正在使用测试接口,功能会受到限制! \n\n";
return false;
}
/**
* 从配置文件内读取爱语飞飞token作为鉴权参数
*/
public static function getSign(){
global $configALL;
// 爱语飞飞
$token = isset($configALL['iyuu.cn']) && $configALL['iyuu.cn'] ? $configALL['iyuu.cn'] : '';
// 鉴权
#$token = isset($configALL['secret']) && $configALL['secret'] ? $configALL['secret'] : $token;
return $token;
}
/**
* 用户注册与登录
* 作用在服务器端实现微信用户与合作站点用户id的关联
* 参数爱语飞飞token + 合作站点用户id + sha1(合作站点密钥passkey) + 合作站点标识
*/
public static function login($apiUrl = ''){
$is_oauth = self::init();
if ( $is_oauth ) {
$curl = new Curl();
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$data = [
'token' => self::$token,
'id' => self::$user_id,
'passkey'=> self::$passkey,
'site' => self::$site,
];
$res = $curl->get($apiUrl, $data);
p($res->response);
return true;
}
return false;
}
}