2019-12-23 23:11:57 +08:00

67 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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, site \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;
}
}