php - 如何使用 textlocal sms api 在 Codeigniter 中发送 OTP?
问题描述
我已经编写了代码以使用 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;
}
解决方案
推荐阅读
- api - 如何按字母顺序对 Github 用户 API 进行排序
- java - 为什么@PostConstruct 方法中实际上只能启动一个线程?
- c# - Aspnet Core Identity 登录和注册谷歌浏览器不起作用
- azure-logic-apps - 为什么 gmail 连接器触发器会跳过新的传入电子邮件
- python - 为什么我的代码打印出我尚未分配的值?
- java - 供应商
> 不能多次迭代 - git - 有没有办法让 GitHub CI 构建 PR 的测试合并,而不是 PR 分支的负责人?
- java - 如何在java中访问类之外的静态块变量
- android - Jetpack 导航:在工具栏中隐藏标签
- python - 基数为 10 的 int() 的无效文字:-django