twilio - 如何通过 php 中的 CURL 使用 twillo 通知 API 发送批量消息?
问题描述
我想使用 twillio 通知 API 在 php 中使用 CURL 发送批量消息我正在尝试以下代码:
$data = [];
$data['ToBinding'] = array("binding_type"=>"sms", "address"=>"+12013318779");
$data['Body'] ="test";
$ch = curl_init("https://notify.twilio.com/v1/Services/ISXXXXXXXXXXXXXXXXXX/Notifications");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERPWD,'XXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXX');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resultData = curl_exec($ch);
我认为我做错了什么,CURLOPT_POSTFIELDS
但我尝试了每一件事来改变它,但每次我得到以下回复:
{"code": 20001,
"message": "At least one parameter among Identity, Tag, and ToBinding must be specified",
"more_info": "https://www.twilio.com/docs/errors/20001",
"status": 400}
你们能帮帮我吗?
谢谢
解决方案
Twilio 开发人员布道者在这里。
ToBinding
要求将数据编码为 JSON。尝试以下操作:
$data['ToBinding'] = json_encode(array("binding_type"=>"sms", "address"=>"+12013318779"));
希望有帮助。
推荐阅读
- javascript - 如何渲染一个
从 react-route-dom 使用对象而不是组件/函数 - ruby-on-rails - 在 Ruby 中使用 Amazon transcribe 流式转录
- docker - 如何将 dockerfile(并运行命令)重写为 docker-compose.yaml
- mysql - 以错误的排序规则连接到 mysql 服务器?
- python - 如何解决此“TypeError:序列项 0:预期的 str 实例,找到浮点数”
- python - 在 Anaconda 之外使用 Python 包
- c - 我得到了意想不到的输出
- angular - 在angular7中禁用以前日期的ng-bootstrap日期和时间
- spring - 如何让用户发送电子邮件?
- javascript - 控制台说注册表单不存在 onsubmit 功能,尽管它显然存在