首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用infobip api (php)发送短信给用户进行验证?

如何使用infobip api (php)发送短信给用户进行验证?
EN

Stack Overflow用户
提问于 2015-12-02 14:36:48
回答 3查看 713关注 0票数 0

我尝试了here中的以下代码,但出现了一个名为“找不到HttpRequest类”的错误。我使用的是php版本5.6.8(xampp v3.2.1)。任何人请帮帮我。

代码语言:javascript
复制
<?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;
}
EN

回答 3

Stack Overflow用户

发布于 2015-12-02 14:51:12

代码语言:javascript
复制
$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);
票数 0
EN

Stack Overflow用户

发布于 2015-12-02 15:01:16

由于你使用的是php 5.4或更高版本,似乎没有php_http.dll文件可以包含在你的扩展库中(除非有人能找到我遗漏的文件??)。

我能找到的唯一一个错误是在更新php.ini配置文件以包含扩展后启动Apache服务器时产生的错误。

检查this link。省省吧。

然后尝试这个程序:

代码语言:javascript
复制
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包。You can find more here.

票数 0
EN

Stack Overflow用户

发布于 2015-12-03 00:04:03

解决方案是安装PECL php扩展。在堆栈溢出问题上给出了几次答案,比如在这个线程上:

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

你可以使用CURL代替PECL通过web应用程序发送短信。在Infobip的博客上有很好的解释和描述。我建议你试一试:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34036380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档