如何将 Twilio 查找 cURL 代码传输到 PHP cURL

How to transfer Twilio lookup cURL code to PHP cURL

我有这个 curl 代码:

curl -X GET https://lookups.twilio.com/v1/PhoneNumbers/(919) 410-7522\
-d "Type=carrier"
-u "{AccountSid}:{AuthToken}"

我尝试在 PHP cURL 中进行转换,但我在研究如何发送 AccountSidAuthToken

我只需要此代码 check if number is valid and mobile or landline

怎么做?谢谢!

只需使用CURLOPT_USERPWD选项

$ch = curl_init("https://lookups.twilio.com/v1/PhoneNumbers/(919)%20410-7522");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_POSTFIELDS, "Type=carrier");
curl_setopt($ch, CURLOPT_USERPWD, "{AccountSid}:{AuthToken}");
$response = curl_exec($ch);

我没有收到运营商的回应,所以我改为 shell_exec 使用 twilio 上列出的 curl xget 命令,它工作正常

<?php

echo time()."<br/>";


$cmd="curl -XGET 'https://lookups.twilio.com/v1/PhoneNumbers/+19999999999?Type=carrier&Type=caller-name' -u 'YOURUSERACCOUNT:YOURAUTHTOKEN' ";
$result=shell_exec($cmd);



$response           =       json_decode($result);
echo "country_code is ".$response->country_code."<br/>";    
echo "<pre>";   print_r($response); echo "</pre><br/>";

echo "country_code is ".$response->country_code."<br/><br/>";

echo "phone number is ".$response->phone_number."<br/>";
echo "national_format ".$response->national_format."<br/><br/>";


$carrier=json_decode($response->carrier);   

echo "Carrier name is ".$response->carrier->name."<br/>";
echo "Carrier type is ".$response->carrier->type."<br/>";
echo "Carrier error_code is ".$response->carrier->error_code."<br/>";
echo "Carrier mobile_network_code ".$response->carrier->mobile_network_code."<br/>";
echo "Carrier mobile_country_code is ".$response->carrier->mobile_country_code."<br/><br/>";

$caller_name=json_decode($response->caller_name);
echo "caller_name is ".$response->caller_name->caller_name."<br/>";
echo "caller_name error_code is ".$response->caller_name->error_code."<br/>";






?>

    enter code here