你好我有问题,从php中的其他类/文件检查返回值函数。
此文件fungsi.php
function pendaftaranUser($iduser,$nrp,$pas){
global $koneksi;
$hasil = '';
//melakukan pengecekan nrp dan password
$querycekAuth = mysql_query("select nrp from user_login where nrp ='$nrp' and password='$pas' ");
$cekAuth = mysql_num_rows($querycekAuth);
if($cekAuth != 0)
{
//melakukan pengecekan apakah id Telegram sudah terdaftar atau belum
$querycekUser = mysql_query("select nrp from userbot where idTelegram = '$iduser'");
$cekUser = mysql_num_rows($querycekUser);
if($cekUser == 0)
{
$queryTambah = mysql_query("insert into userbot(idTelegram,nrp) values($iduser,$nrp)");
$hasil .= " Selamat NRP $nrp berhasil didaftar.";
}
else
{
while($row = mysql_fetch_array($querycekUser))
{
$hasil .= " ID Telegram anda telah terdaftar sebagai ".$row['nrp'];
$hasil .= "\n 1 ID hanya dapat mendaftarkan 1 User saja.";
}
}
}
else
{
$hasil .= "⛔️ Gagal!\n\n NRP dan Password tidak sesuai.";
}
return $hasil;
}
我想在proses.php
中显示值之前检查值return $ hasil case 'daftar':
sendApiAction($idchat);
if(isset($pecah[1]) && isset($pecah[2])){
$nrp = $pecah[1];
$pas = $pecah[2];
$text = pendaftaranUser($iduser,$nrp,$pas);
//if $text value is '⛔️ Gagal...' i want the sendApiMsg is called.
if(pendaftaranUser($iduser,$nrp,$pas) === '⛔️ Gagal!\n\n NRP dan Password tidak sesuai.'){
sendApiMsg($idchat, $text);
}
//this condition if $text value is ' Selamat NRP....' and called funtion apiRequestJson
else {
apiRequestJson("sendMessage", array('chat_id' => $idchat, "text" => $text, 'reply_markup'=>$keyboard_full));
}
} else {
$text = "Pendaftaran akun Anda Gagal.\n\n";
$text .= "Contoh: daftar [NRP] [Kata Sandi]";
sendMessage($idpesan, $idchat, $text);
}
break;
我为电报机器人创建了这个代码。如果我得到$ text是'Gagal ..'的错误条件我不会显示键盘,但如果$ text是成功键盘显示。如何在使用php调用sendMessage或apiRequestJson for telegram bot之前先检查这个条件?