如何将我的脚本从仅使用美国电话号码更改为使用美国和国际或至少英国号码
问题描述:
我有一个脚本收集电话号码并通过URL将其发送到另一个脚本中。该脚本适用于美国的数字,但我无法让它与英国的数字一起工作,我试图找出它没有运气。任何帮助,将不胜感激。如何将我的脚本从仅使用美国电话号码更改为使用美国和国际或至少英国号码
这是我正在使用的代码。
<?php
session_start();
function post_to_sms($url,$post_string)
{
// post form to SMS API
$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
// note - set HOST where your API resides
curl_setopt($ch, CURLOPT_HTTPHEADER, array("POST /cgi-bin/webscr HTTP/1.1",
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: " . strlen($post_string),
"Host: yourdomain.com",
"Connection: close"));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLINFO_HEADER_OUT , 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = @curl_exec($ch);
// 2 lines of debug (comment for production)
// print_r(curl_getinfo($ch));
// echo "<br /> error = " . $curl_err = curl_error($ch);
curl_close($ch);
return $curl_result;
} // end of CURL function
// URL for your SMS API
$url = "yourdomain.com/sms/sms_controlling.php";
if(isset($_REQUEST['telNumber']))
{
if(is_numeric($_REQUEST['telNumber']) && ($_REQUEST['telNumber'] > '1000000000') && ($_REQUEST['telNumber'] < '9999999999'))
{
// create array of form variables
// 'From' is input - 'To' and 'Body' is hard-coded
$post_data['From'] = $_REQUEST['telNumber'];
$post_data['To'] = "%2b17204447777"; //Enter Twilio Phone number
$post_data['Body'] = "keyword Here"; //Enter The Keyword to your SMS Campaign.
foreach ($post_data as $key => $value)
{
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
post_to_sms($url, $post_string);
} else {
$_SESSION['errmessage'] = "Sorry. All 10 Digits of Phone Number (incl Area Code) are required.";
}
}
?>
答
由于philnash指出,英国的电话号码开始44取决于不同界面使用的是你可能需要简单的编号前缀设置为44,+44或您可能需要设置的号码计划指标。 +国际通用号码是移动设备设置NPI的捷径,通常在消息传递协议中没有任何相关性,否则......所以您需要咨询您的SMS提供商。
你能告诉我们为什么你使用这些if-conditions吗? '$ _REQUEST ['telNumber']>'1000000000'和'$ _REQUEST ['telNumber'] Titanoboa
对于国际号码,您需要确保您使用的是国家代码前缀(在英国是+ 44)。你在做那个吗?这是否与Titanoboa询问的条件有关? – philnash
嗨,我不是程序员,这是我能弄清楚如何在美国工作的唯一方法。我将%2b1更改为+44,并正确发送信息,但是当我的应用程序收到url字符串时,它不会将其发送给twilio。所以它必须位于我的申请中,而不是形式。感谢您的回应。 – MichaelP