【问题标题】:How to send bulk messages using twillo notify API via CURL in php?如何通过 php 中的 CURL 使用 twilio 通知 API 发送批量消息?
【发布时间】:2018-12-21 16:03:43
【问题描述】:

我想使用 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 twilio-api twilio-php


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    ToBinding 要求将数据编码为 JSON。请尝试以下操作:

    $data['ToBinding'] =  json_encode(array("binding_type"=>"sms", "address"=>"+12013318779"));
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-03
      • 2021-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多