抱歉,将代码发布为屏幕截图。在将代码粘贴到此处时出错,因此我上传了代码here 我找到了此代码来发送电报消息,但我想使其成为代码点火器控制器中的功能。你们能帮我吗?
对不起,英语不好。
图片1: 图片2:
谢谢。
答案 0 :(得分:0)
您可以创建一个名称为'actionSendMessage'的新动作,然后获取POST或GET数据。 您可以将功能(图片1)移到其他位置
protected function sendMessage(...$params)
{
// here code...
}
在您的控制器中
答案 1 :(得分:0)
您只需在控制器上创建一个send_message
方法,如下所示:
/* -----------------------------------------------------
Simple PHP script for Sending Telegram Bot Message
~ Iky | https://www.wadagizig.com
------------------------------------------------------ */
public function send_message()
{
/*----------------------
only basic POST method :
-----------------------*/
$telegram_id = $this->input->post('telegram_id');
$message_text = $this->input->post('message_text');
/*--------------------------------
Isi TOKEN dibawah ini:
--------------------------------*/
$secret_token = "622322475:AAGE7HouAbjlr-K4AUrCBCv2bZCNZ0P7Ka4";
$url = "https://api.telegram.org/bot" . $secret_token . "/sendMessage?parse_mode=markdown&chat_id=" . $telegram_id;
$url = $url . "&text=" . urlencode($message_text);
$ch = curl_init();
$optArray = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
$result = curl_exec($ch);
curl_close($ch);
echo "<script>alert('Pesan berhasil terkirim!'); window.location.href = './';</script>";
}
并将您的控制器名称更改为您通过上述send_message
方法插入的控制器名称:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>wadagizig Telegram bots</title>
<!--link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"-->
</head>
<body>
<div class="content">
<section class="content-header">
<i class="fa fa-home"></i> Home / <i class="fa fa-dashboard"></i> Dashboard / <b>wadagizig</b>
</section>
<div class="col-md-4">
<div class="box box-solid box-primary">
<div class="box-header">
<h4 class="box-title"><b>Telegram Message <i class="fa fa-send"></i></b></h4>
</div>
<div class="box-body">
<form method="post" action="<?php echo site_url() . 'your_controller_name/send_message' ?>}}">
<div class="form-group row">
<label class="col-md-4 col-form-label">Telegram ID</label>
<div class="col-md-8">
<input type="text" class="form-control" name="telegram_id" placeholder="Telegram ID">
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label">Messages</label>
<div class="col-md-8">
<input type="text" class="form-control" name="message_text" placeholder="Custom Text Message">
</div>
</div>
<button type="submit" class="btn btn-primary pull-right">Send <i class="fa fa-send"></i></button>
</form>
</div>
</div>
</div>
</div>
</body>
</html>