Twilio Verify API: "Requested URL was not found"



我正在使用 curl 按照此处的说明执行对 Twilio Verify API 的请求:https://www.twilio.com/verify/api

使用这些说明,我创建了两个 php 文件来执行 curl 请求 - 一个用于获取验证码 (get_code.php(,另一个用于检查验证码 (check_code.php(。这些脚本是使用 ajax post 来发送参数的,这两个脚本几乎相同,除了 URL("/start" vs. "/check"(。

我相信我指定了正确的 URL,并且get_code.php工作,但check_code.php抛出以下错误:

找不到请求的 URL。请检查 http://docs.authy.com/以查看有效的 URL。

get_code.php

<?php
$USER_PHONE = htmlspecialchars($_POST["phone"]);
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL            => "https://api.authy.com/protected/json/phones/verification/start",
CURLOPT_POST           => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS     => array(
'country_code' => '1',
'via' => 'sms',
'phone_number' => $USER_PHONE,
),
CURLOPT_HTTPHEADER => array('X-Authy-API-Key: MY_KEY')
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

check_code.php

<?php
$USER_PHONE = htmlspecialchars($_POST["phone"]);
$VERIFY_CODE = htmlspecialchars($_POST["code"]);    
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL            => "https://api.authy.com/protected/json/phones/verification/check",
CURLOPT_POST           => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS     => array(
'country_code' => '1',
'phone_number' => $USER_PHONE,
'verification_code' => $VERIFY_CODE
),
CURLOPT_HTTPHEADER => array('X-Authy-API-Key: MY_KEY')
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

我使用相同的 URL 和参数在终端中手动执行了 curl,它奏效了。

curl "https://api.authy.com/protected/json/phones/verification/check?phone_number=MY_PHONE&country_code=1&verification_code=MY_CODE" -H "X-Authy-API-Key: MY_KEY"

我不知道我可能做错了什么?

好吧,我不知道为什么这有效,但我让它工作,也许其他人可以解释为什么。我将 CURL URL 构建为字符串,并删除了CURLOPT_RETURNTRANSFERCURLOPT_POST参数。

<?php
$USER_COUNTRY = "1";
$USER_PHONE = htmlspecialchars($_POST["phone"]);
$VERIFY_CODE = htmlspecialchars($_POST["code"]);
$URL = "https://api.authy.com/protected/json/phones/verification/check?country_code=1&phone_number=".$USER_PHONE."&verification_code=".$VERIFY_CODE;
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL            => $URL,
CURLOPT_HTTPHEADER => array('X-Authy-API-Key: MY_KEY')
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

🤷

相关内容

最新更新