我有一个代码点火器项目。已经有像clickatell和twilio这样的短信网关。我想在我的项目中再包含一个名为 lifetimesms.com 的 SMS 网关。这是生命周期短信网关的代码。
<?php
$username = 'username';
$password = 'password';
$to = '44xxxxxxxx';
$from = 'Brand';
$message = 'Test SMS from Lifetimesms.com';
$url = "http://Lifetimesms.com/plain?username=".$username."&password=".$password."&to=".$to."&from=".urlencode($from)."&message=".urlencode($message)."";
//Curl Start
$ch = curl_init();
$timeout = 30;
curl_setopt ($ch,CURLOPT_URL, $url) ;
curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT, $timeout) ;
$response = curl_exec($ch) ;
curl_close($ch) ;
//Write out the response
echo $response ;
?>
在代码点火器中应该做什么?
为什么不直接将其添加到控制器文件(SMS.php )喜欢这个
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class SMS extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$username = 'username';
$password = 'password';
$to = '44xxxxxxxx';
$from = 'Brand';
$message = 'Test SMS from Lifetimesms.com';
$url = "http://Lifetimesms.com/plain?username=".$username."&password=".$password."&to=".$to."&from=".urlencode($from)."&message=".urlencode($message)."";
//Curl Start
$ch = curl_init();
$timeout = 30;
curl_setopt ($ch,CURLOPT_URL, $url) ;
curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT, $timeout) ;
$response = curl_exec($ch) ;
curl_close($ch) ;
//Write out the response
die($response);
}
}
然后就这样运行http://xxxx.com/codeigniter/sms