forked from Dituon/petpet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
74 lines (62 loc) · 1.82 KB
/
example.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
const API_URL = 'http://127.0.0.1:2333/petpet';
class PetRequest
{
protected $curl;
public function __construct()
{
$this->curl = curl_init(API_URL);
curl_setopt($this->curl, CURLOPT_POST, true);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
}
public function __destruct()
{
curl_close($this->curl);
}
function post($data)
{
curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($data));
return curl_exec($this->curl);
}
function get($data)
{
$params = [];
foreach ($data as $key => $value) {
switch ($key) {
case 'from':
case 'to':
case 'group':
case 'bot':
foreach ($value as $targetKey => $targetValue) {
$params[] = $key . ucfirst($targetKey) . '=' . rawurlencode($targetValue) ;
}
break;
case 'randomAvatarList':
case 'textList':
$params[] = $key . '=' . rawurlencode(implode(',', $value));
break;
default:
$params[] = $key . '=' . $value;
break;
}
}
echo API_URL . '?' . implode('&', $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_URL . '?' . implode('&', $params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
// 👇脚本
$data = [
'key' => 'petpet',
'to' => [
'name' => 'Dituon',
'avatar' => 'https://q1.qlogo.cn/g?b=qq&nk=2544193782&s=640'
]
];
$req = new PetRequest();
$image = $req->post($data);
//$image = $req->get($data);