我已经编写了代码,通过使用textlocalapi在codeigniter中发送OTP,并使用require函数在控制器中加载了类文件(textlocal.class.php),但是每当我输入手机号码时,它都不会向该号码发送任何otp。 >
<?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');
} ?>
这是textlocal.class.php文件的文件夹结构
在模型中编写的用于发送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;
}