dongsonghen9931 2018-06-20 07:21
浏览 53

如何使用textlocal sms api在Codeigniter中发送OTP?

I have written code to send OTP in codeigniter by using textlocalapi and loading class file(textlocal.class.php) in controller using require function but whenever I enter my mobile number it is not sending any otp to that number.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require ('./textlocal.class.php');

class User extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model('User_Model');
        $this->load->helper('string');

    }  ?>

this my folder structure for textlocal.class.php file

Below code written in model for sending otp

public function send_otp(){
        $data['otp'] = random_string('numeric',6);
        $data['otp_id'] = random_string('alnum',6);
        $this->db->insert('otp',$data);

        // Account details
    $apiKey = urlencode('xyz');// My API key

    // Message details
    $numbers = 911234567894;
    $sender = urlencode('ABCDEF');//This my six digit sender name
    $message = rawurlencode('This is your message');



    // Prepare data for POST request
    $data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/send/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    // Process your response here
    return $response;


    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 arduino控制ps2手柄一直报错
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题