gpt4 book ai didi

php - Twilio rest api,发送短信

转载 作者:可可西里 更新时间:2023-11-01 00:48:35 24 4
gpt4 key购买 nike

<分区>

我正在尝试(并且必须)使用 twilio rest api to send sms并且不使用 helper php 库。下面是我的代码: 我面临的问题是,它给我的错误是 91xxxxxxxxxx 不是有效的电话号码。但是我将电话号码传递给前缀为“+”的 rest api。

我使用的是试用账户,号码已通过 twilio 验证,并使用帮助程序库进行了测试。

<?php
$url = "https://api.twilio.com/2010-04-01/Accounts/MYID/SMS/Messages.json";
$from = "MY_TWILIO_NUMBER without + prefix";
$to = "+91xxxxxxxxxx"; // twilio trial verified number
$body = "using twilio rest api";
$id = "MY_ID";
$token = "MY_TOKEN";
$data = array (
'From' => $from,
'To' => $to,
'Body' => $body,

);
$post = '';
foreach ($data as $parameter => $value)
{
$post .= "&$parameter=$value";
}
$x = curl_init($url );
curl_setopt($x, CURLOPT_POST, true);
curl_setopt($x, CURLOPT_RETURNTRANSFER, true);
curl_setopt($x, CURLOPT_USERPWD, "$id:$token");
curl_setopt($x, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($x, CURLOPT_POSTFIELDS, $post);
$y = curl_exec($x);
var_dump($y);
curl_close($x);
?>

curl 请求的完整转储

string(157) "{"status":400,"message":"The 'To' number  91xxxxxxxxxx is not a valid phone number.","code":21211,"more_info":"http://www.twilio.com/docs/errors/21211"}"

它确实显示了错误的数字(缺少“+”),但我不明白。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com