$mes['message']
在我的浏览器中它返回有效数据。可能是什么问题?
$message1 = $db->prepare("SELECT message FROM about where id=1 ");
$message1->execute();
$mes = $message1->fetch();
if (isset($message['text'])) {
// incoming text message
$text = $message['text'];
if ((strpos($text, "/start") === 0) || (strpos($text, "/start") === 0) ) {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => 'Hello', 'reply_markup' => array(
'keyboard' => array(array('Hello', 'Hi')),
'one_time_keyboard' => true,
'resize_keyboard' => true)));
} else if ($text === "Hello" || $text === "Hi") {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'Nice to meet you'));
} else if (strpos($text, "/stop") === 0) {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => 'Did i do anything wrong?', 'reply_markup' => array(
'keyboard' => array(array('Yes', 'No')),
'one_time_keyboard' => true,
'resize_keyboard' => true)));
}else if ($text === "No") {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'Nice to meet you'));
}else if ($text === "Tell me more") {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => '<?php echo $mes2["message"];?>'));
} else {
apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "reply_to_message_id" => $message_id, "text" => '<?php echo $mes1["message"]; ?>'));
}
} else {
apiRequestJson("sendMessage", ['chat_id' => $chat_id, "text" => $me2 , 'reply_markup' => [
'keyboard' => [['Tell me more', 'Got it']],
'one_time_keyboard' => true,
'resize_keyboard' => true]]);
}
答案 0 :(得分:0)
您不需要在函数中使用&lt; php echo 作为参数。
看看你的其他变量,比如$ chat_id,$ me2 ......你应该使用&#34; text&#34; =&GT; $ mes1 [&#34; message&#34;] 和&#34; text&#34; =&GT; $ mes2 [&#34;消息&#34;]
它已经被PHP处理过了。您不需要再次嵌入它
}else if ($text === "Tell me more") {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => $mes2["message"]));
} else {
apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "reply_to_message_id" => $message_id, "text" => $mes1["message"]));
}
答案 1 :(得分:0)
我发现了问题。
数据库对象$text
在持有if语句的函数中不可用。
我不得不在函数中声明它是全局的。
例如
function sendMessage () {
global $text;
//if statements here
}
现在工作正常