Update callback.php

This commit is contained in:
iVampireSP.com 2023-07-21 02:26:05 +08:00 committed by GitHub
parent 87dff56946
commit 8ee7fe4b67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,7 @@ if (!isset($_GET['state']) || $_GET['state'] !== $state) {
$moduleconfig = Capsule::table('tbladdonmodules')->where('module', 'LoliArtAccount')->get();
foreach ($moduleconfig as $key => $value) {
foreach ($moduleconfig as $key => $value) {
$config[$value->setting] = $value->value;
}
@ -30,7 +30,7 @@ if ($_GET['code']) {
'code' => $_GET['code'],
];
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
@ -45,75 +45,53 @@ if ($_GET['code']) {
$data = json_decode($result);
$ch = curl_init($config['user_info_url']);
$headers[] = 'Authorization: Bearer ' . $data->access_token;
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
// exit($response);
$data = json_decode($response);
if (empty($data)) {
exit(curl_error($ch));
exit('遇到了错误: ' . curl_error($ch));
// die('<script>window.location.href="/dologin.php";</script>');
}
if (empty($data->real_name_verified_at)) {
// 没有实名
$_SESSION['realnamed'] = false;
} else {
// 再请求 /api/real-name
$ch = curl_init($config['realname_info_url']);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$realname_response = curl_exec($ch);
$realname_data = json_decode($realname_response);
// // 验证 iso_code 是否为 CN
// $validate_ch = curl_init('https://www.lae.email/api/geoip?ip=' . $_SESSION['user_ip']);
// curl_setopt($validate_ch, CURLOPT_RETURNTRANSFER, TRUE);
// curl_setopt($validate_ch, CURLOPT_SSL_VERIFYPEER, 0);
// curl_setopt($validate_ch, CURLOPT_SSL_VERIFYHOST, 0);
// $validate_ch = json_decode(curl_exec($validate_ch));
if (empty($realname_data)) {
exit('获取实名认证信息时遇到了错误: ' . curl_error($ch));
}
// if (empty($validate_ch)) {
// die('Something went wrong, please contact us or try again later.');
// }
$_SESSION['realnamed'] = true;
}
// // exit($validate_ch->iso_code == 'CN');
// if ($validate_ch->iso_code == 'CN') {
// // 如果用户的区域在 中国大陆,则将用户带去实名认证
// if (is_null($data->verified_at)) {
// die('<script>window.location.href="https://www.lae.email/zh-CN/real-name-authentication";</script>');
// }
// }
// 我不认为 WHMCS 国家代码这边设计的很合理所以监测到HK和TW时必须将他们强制修改为CN
// if ($validate_ch->iso_code == 'HK' || $validate_ch->iso_code == 'TW') {
// $validate_ch->iso_code = 'CN';
// }
$openID = Capsule::table('tblclients')->where('email', $data->email)->first()->id;
if ($openID) {
go_oauth_login($openID);
// //更新实名状态
// $realnameID = Capsule::table('tblclients_realname')->where('userid', $openID)->first()->id;
// if (!empty($realnameID)) {
// Capsule::table('tblclients_realname')->where('id', $realnameID)->update([
// 'userid' => $openID,
// 'verified_at' => $data->verified_at,
// 'real_name' => $data->real_name,
// ]);
// } else {
// Capsule::table('tblclients_realname')->insert([
// 'userid' => $openID,
// 'verified_at' => $data->verified_at,
// 'real_name' => $data->real_name,
// ]);
// }
} else {
//创建账户
$user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
@ -140,36 +118,60 @@ if ($_GET['code']) {
];
// Client
$results = localAPI($command, $postData);
if ($results['result'] != 'success') {
// print_r($results);
// Capsule::table('tblusers')->where('id', $realnameID)->update([
// 'userid' => $openID,
// 'verified_at' => $data->verified_at,
// 'real_name' => $data->real_name,
// ]);
die("无法新增用户");
exit("无法新增用户。");
} else {
// Capsule::table('tblusers')->where('email', $data->email)->update([
// 'email_verified_at' => $data->verified_at,
// ]);
$user = Capsule::table('tblusers')->where('email', $data->email)->first();
// dd($user->id);
$openID = $results['clientid'];
$hookParams = ["user_id" => $user->id, "client_id" => $results['clientid'], "userid" => $results['clientid']];
// dd($hookParams);
run_hook("ClientAreaRegister", $hookParams);
go_oauth_login($results['clientid']);
}
}
if ($_SESSION['redirect_url']) {
$redirect_url = $_SESSION['redirect_url'];
unset($_SESSION['redirect_url']);
if ($_SESSION['realnamed'] === true) {
// 如果有 mod_realname_clients 表,则继续
if (Capsule::schema()->hasTable('mod_realname_clients')) {
$query = Capsule::table('mod_realname_clients')->where('client_id', $openID);
$realname_id = $query->first()->id;
if (!empty($realname_id)) {
Capsule::table('mod_realname_clients')->where('id', $realname_id)->update([
'client_id' => $openID,
'verified_at' => $realname_data->real_name_verified_at,
'name' => $realname_data->real_name,
'id_card' => $realname_data->id_card,
]);
} else {
Capsule::table('mod_realname_clients')->insert([
'client_id' => $openID,
'verified_at' => $realname_data->real_name_verified_at,
'name' => $realname_data->real_name,
'id_card' => $realname_data->id_card,
]);
}
}
} else {
// 如果有 mod_realname_clients 表,则删除
if (Capsule::schema()->hasTable('mod_realname_clients')) {
$query = Capsule::table('mod_realname_clients')->where('client_id', $openID);
$realname_id = $query->first()->id;
if (!empty($realname_id)) {
Capsule::table('mod_realname_clients')->where('id', $realname_id)->delete();
}
}
}
header('Location: ' . $redirect_url);
if ($_SESSION['redirect_uri']) {
$redirect_uri = $_SESSION['redirect_uri'];
unset($_SESSION['redirect_uri']);
header('Location: ' . $redirect_uri);
} else {
header('Location: /clientarea.php');
}
@ -178,19 +180,21 @@ if ($_GET['code']) {
function go_oauth_login($uid)
{
// 登
// 登
// 写入 SESSION UID
$_SESSION['uid'] = $uid;
// 获取 UID
$userinfo = Capsule::table('tblclients')->where('id', $uid)->first();
$username = $userinfo->firstname . ' ' . $userinfo->lastname;
$userinfo = Capsule::table('tblclients')->where('id', $uid)->first();
// $username = $userinfo->firstname . ' ' . $userinfo->lastname;
// 取出值
$login_uid = $userinfo->id;
$login_pwd = $userinfo->password;
$language = $userinfo->language;
$login_uid = $userinfo->id;
// $login_pwd = $userinfo->password;
// $language = $userinfo->language;
$remote_ip = $_SERVER['REMOTE_ADDR'];
// 更新登录时间登录IP
$fullhost = gethostbyaddr($remote_ip);
@ -206,9 +210,9 @@ function go_oauth_login($uid)
}
Capsule::table('tblclients')->where('id', $login_uid)->update([
'lastlogin' => time(),
'ip' => $remote_ip,
'host' => $fullhost,
'lastlogin' => time(),
'ip' => $remote_ip,
'host' => $fullhost,
]);
@ -217,9 +221,9 @@ function go_oauth_login($uid)
if ($login_cid) {
$_SESSION['cid'] = $login_cid;
}
//仅支持8.1+
// 仅支持8.1+
oauth_finishLogin($login_uid);
$hookParams = array('userid' => $login_uid);
$hookParams = ['userid' => $login_uid];
$hookParams['contactid'] = $login_cid ? $login_cid : 0;
run_hook('ClientLogin', $hookParams);
// $loginsuccess = true;
@ -227,8 +231,6 @@ function go_oauth_login($uid)
}
function oauth_getWHMCSversion()
{
//获取WHMCS当前版本
@ -261,7 +263,7 @@ function oauth_authUserV8(\WHMCS\User\Client $client)
{
try {
$class = new \WHMCS\Authentication\AuthManager();
$result = $class->login($client->owner());
$class->login($client->owner());
return true;
} catch (\Error $e) {
return false;
@ -275,13 +277,9 @@ function oauth_authUserOther($userData)
return validateClientLogin($user, $password);
}
function oauth_random_str($length, $type = 1)
function oauth_random_str(int $length, int $type = 1)
{
if ($type == 1) {
// 密码字符集,可任意添加你需要的字符
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
} else if ($type == 2) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
@ -290,11 +288,7 @@ function oauth_random_str($length, $type = 1)
}
$str = '';
for ($i = 0; $i < $length; $i++) {
// 这里提供两种字符获取方式
// 第一种是使用 substr 截取$chars中的任意一位字符
// 第二种是取字符数组 $chars 的任意元素
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
// $str .= $chars[mt_rand(0, strlen($chars) - 1)];
}
return $str;
}