【问题标题】:How can i send a sms to a user for verification using infobip api (php)?如何使用 infobip api (php) 向用户发送短信以进行验证?
【发布时间】:2016-03-06 07:39:06
【问题描述】:

我尝试了here 的以下代码 但是有一个错误,称为找不到 HttpRequest 类。我正在使用 php 版本 5.6.8(xampp v3.2.1)。任何人请帮助我。

<?php
$request = new HttpRequest();
$request->setUrl('https://api.infobip.com/sms/1/text/single');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'accept' => 'application/json',
  'content-type' => 'application/json',
  'authorization' => 'Basic sfdsdf=='  // name&password
));

$request->setBody('{  
   "from":"test",  //from
   "to":"000", // number
   "text":your verification code is = 000."
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

【问题讨论】:

    标签: php sms infobip infobip-api


    【解决方案1】:
    $mob_no="mobile number";
    $msg="Your message";
    $sender_id='your sender id eg:VJPOTPYTL';
    $str = trim(str_replace(' ', '%20', $msg));
    
    $url="http://dnd.9starabs.com/app/smsapi/index.php?key=55942cc305ef6&type=text&contacts=".$mob_no."&senderid=".$sender_id."&msg=".$str."";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_exec($ch);
    curl_close($ch);
    

    【讨论】:

      【解决方案2】:

      由于您使用的是 php 5.4 或更高版本,因此您的扩展库中似乎没有包含 php_http.dll 文件(除非有人能找到我错过的一个??)。

      在更新 php.ini 配置文件以包含扩展名后,我发现在启动 Apache 服务器时生成错误的唯一一个。

      检查this link。保存它。
      然后试试这个程序:

      include_once('HttpRequest.php'); //where HttpRequest.php is the saved file
      $url= 'http://www.google.com/';
      $r = new HttpRequest($url, "POST");
      var_dump($r->send());  
      

      如果它不起作用,那么您可能需要自己编译 HTTP 包。你can find more here.

      【讨论】:

      • 我之前尝试过这个 HttpRequest 类,但它产生了一些错误,例如..// 警告:在 C:\xampp\htdocs\Training\sms 中调用的 HttpRequest::__construct() 缺少参数 1 \smsinfo.php 在第 3 行并在 C:\xampp\htdocs\Training\sms\HttpRequest.php 在第 26 行定义 注意:未定义的变量:url 在 C:\xampp\htdocs\Training\sms\HttpRequest.php 在行28 注意:未定义的索引:第 33 行 C:\xampp\htdocs\Training\sms\HttpRequest.php 中的主机......对此感到抱歉。我是 stackoverflow 的新手,也是这个主题。
      【解决方案3】:

      解决方案是安装 PECL php 扩展。堆栈溢出时给出了多次答案,就像在这个线程上一样:

      "PHP Fatal error: Class 'HttpRequest' not found"

      您可以使用 CURL 而不是 PECL 通过 Web 应用程序发送 SMS。 Infobip 的博客 对此进行了很好的解释和描述。我建议尝试一下:

      http://www.infobip.com/blog/step-by-step-php-tutorial/

      【讨论】:

        猜你喜欢
        • 2023-03-27
        • 1970-01-01
        • 1970-01-01
        • 2017-01-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-06
        相关资源
        最近更新 更多