【问题标题】:How to integrate sms gateway in codeigniter如何在codeigniter中集成短信网关
【发布时间】:2018-04-14 13:06:53
【问题描述】:

我有一个 codeigniter 项目。已经有像 clickatell 和 twilio 这样的短信网关。我想在我的项目中再包含一个名为lifetimesms.com 的短信网关。这是lifetimesms网关的代码。

<?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 ;

 ?>

在 codeigniter 中应该为此做什么?

【问题讨论】:

  • CI应该就是这样
  • 你到底有什么问题?

标签: php codeigniter curl sms


【解决方案1】:

为什么不直接将它添加到控制器文件(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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2016-10-19
    相关资源
    最近更新 更多