我使用的是在PHP中称为文本本地的SMS API。有一个主textlocal.class.php文件。这就是代码。
include "textlocal.class.php";
$textlocal = new Textlocal('Username', 'API KEY');
$numbers = array(MOBILE NUMBER);
$sender = 'Testing';
$message = "Your Download image link is available now";
$textlocal->sendSms($numbers, $message, $sender);如何将其包含在Codigniter控制器中?请帮帮我
发布于 2017-02-06 18:48:09
Codeigniter helper在这种情况下很有用。最大的好处是Helper函数将在任何需要的地方可用。
将以下文件保存在Application/Heplers/sendsms_helper.php中
/*Start sendsms_helper.php file */
function sendsms($number, $message_body, $return = '0'){
$sender = 'SEDEMO'; // Need to change
$smsGatewayUrl = 'http://springedge.com';
$apikey = '62q3z3hs49xxxxxx'; // Change
$textmessage = urlencode($textmessage);
$api_element = '/api/web/send/';
$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$mobileno.
'&message='.$textmessage;
$smsgatewaydata = $smsGatewayUrl.$api_params;
$url = $smsgatewaydata;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
if(!$output){
$output = file_get_contents($smsgatewaydata);
}
if($return == '1'){
return $output;
}else{
echo "Sent";
}
}
/* * End sendsms_helper.php file */使用方法:
将sendsms helper作为$this->load->helper('sendsms_helper');
发布于 2017-01-19 10:33:49
在codeigniter中,总是在application/libraries folder.Then中保留额外的类,只需将这些类加载到您想要的位置,如下所示:
$this->load->library(libaray_name);以为例:将您的文件保存在application/libraries中作为Textlocal.php.Then加载到控制器中,如下所示:
$this->load->library('textlocal');然后调用像$this->textlocal->method_name();这样的库函数
$numbers = array(MOBILE NUMBER);
$sender = 'Testing';
$message = "Your Download image link is available now";
$this->textlocal->sendSms($numbers, $message, $sender);https://stackoverflow.com/questions/41727077
复制相似问题