大家好,我来解释一下我的代码:
我有一个电报机器人,我必须在一组中快速编写许多消息,要编写消息,必须执行链接(使用电报Api)。
为此,我使用Curl:
curl_setopt($ch, CURLOPT_URL, $url_telegram);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, getRandomUserAgent());
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 80);
$return= curl_exec($ch);
if($return !== FALSE){ //cURL works
save_variable_in_js_file();
}
如果信息是书面的,我相信一定是:
$return == TRUE or maybe != False
因此,如果不为false,则运行函数
save_variable_in_js_file()
将变量保存在javascript文件中。
奇怪的是,有些消息不是由bot编写的,它似乎不起作用,也许它的$return是==FALSE,但无论如何,函数是运行的,变量保存在文件中。
为什么会这样?
我知道
CURLOPT_RETURNTRANSFER, TRUE
$return
的卷曲可以是
request
或
false
.
这就是问题所在吗?
使用的方法
API Telegram
发送消息是
sendMessage
:
https://core.telegram.org/method/messages.sendMessage
编辑
:
当我用bot写消息时,一切正常,它会返回以下内容
JSON
:
ok: true
result:
message_id: 546
from:
id: xxx1
is_bot: true
first_name: "name bot"
username: "name bot"
chat:
id xxx111
title "name group"
username "name bot"
type "supergroup"
date 1627749641
text "Ciao"
也许我可以这样做:
if(json_decode($return, true) ['ok']){
save_variable_in_js_file();
}
你怎么认为?