Skip to content

Commit

Permalink
update echo
Browse files Browse the repository at this point in the history
  • Loading branch information
anhao committed Feb 7, 2021
1 parent 8cbc1bd commit 70c2833
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@
if ($type === 'webhook') {
// 获取/token 命令,获取聊天 id
$data = json_decode(file_get_contents("php://input"), true);
$message = $data['message']['text'];
$message = $data['message']['text'] ?? '';
if ($message === '/token') {
$chat_id = $data['message']['chat']['id'];
$bot->sendMessage(['text' => $bot->encryption($chat_id), 'chat_id' => $chat_id]);
}
return json_encode(['code' => 200, 'message' => 'success']);
echo json_encode(['code' => 200, 'message' => 'success']);
} else {
if (is_null($token)) {
return json_encode(['code' => 422, 'message' => 'token 不能为空']);
echo json_encode(['code' => 422, 'message' => 'token 不能为空']);
} else {
// 发送消息
$chat_id = $bot->decryption($token);
$ret = $bot->sendMessage(['text' => $message, 'chat_id' => $chat_id]);
if ($ret['ok']) {
return json_encode(['code' => 200, 'message' => 'success']);
echo json_encode(['code' => 200, 'message' => 'success']);
} else {
return json_encode(['code' => 422, 'message' => 'error']);
echo json_encode(['code' => 422, 'message' => 'error']);
}
}
}

class Bot
{
// chat_id sign key
public string $key = "abc";
//Bot Token
public string $token = "1679016407:AAEHII057c26C5_vY8tSLbO8G6mnyXUOYbM";

public function sendMessage($data): array
Expand Down

0 comments on commit 70c2833

Please sign in to comment.