iami233
iami233
文章156
标签37
分类4

文章分类

文章归档

PHP跳转QQ聊天窗口源码

PHP跳转QQ聊天窗口源码

最近在整理 TenAPI 的接口,暂时没时间更新博客,放段代码我就溜~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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;
}
本文作者:iami233
本文链接:https://5ime.cn/872.html
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可