PHP跳转QQ聊天窗口源码
1 min read
最近在整理 TenAPI 的接口,暂时没时间更新博客,放段代码我就溜~
<?php
// title: PHP跳转QQ聊天窗口源码
// update: 2024-05-03
// author: iami233
header('Access-Control-Allow-Origin:*');
$qq = $_GET['qq'] ?? null; // 从查询参数获取QQ号码
if (!$qq || !is_numeric($qq)) {
sendResponse(201, '提供的QQ号码无效。');
exit;
}
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$is_pc = strpos($agent, 'windows nt') !== false;
$is_iphone = strpos($agent, 'iphone') !== false;
$is_ipad = strpos($agent, 'ipad') !== false;
$is_android = strpos($agent, 'android') !== false;
$urls = [
'pc' => "tencent://Message/?uin=$qq",
'iphone' => "mqq://im/chat?chat_type=wpa&uin=$qq&version=1&src_type=web",
'ipad' => "mqq://im/chat?chat_type=wpa&uin=$qq&version=1&src_type=web",
'android' => "mqqwpa://im/chat?chat_type=wpa&uin=$qq"
];
if ($is_pc) {
header("Location: " . $urls['pc']);
} elseif ($is_iphone) {
header("Location: " . $urls['iphone']);
} elseif ($is_ipad) {
header("Location: " . $urls['ipad']);
} elseif ($is_android) {
header("Location: " . $urls['android']);
} else {
sendResponse(201, '不支持的设备类型。');
}
function sendResponse($code, $message) {
echo json_encode(['code' => $code, 'message' => $message], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
exit;
}