简体   繁体   English

如何将我的脚本从仅使用美国电话号码更改为使用美国和国际或至少英国号码

[英]How to change my script from using only US telephone number to use US and international or at least UK numbers

I have a script that gathers a phone numbers and sends it out through a URL into another script. 我有一个收集电话号码并通过URL发送到另一个脚本的脚本。 The script works fine for US numbers but I cannot get it to work with UK numbers and I have tried to figure it out with no luck. 该脚本适用于美国号码,但我无法使其与英国号码一起使用,并且我尝试自己没有运气。 Any help would be appreciated. 任何帮助,将不胜感激。

This is the code I am using. 这是我正在使用的代码。

<?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.";
    }
  }

  ?>

As philnash has pointed out, UK numbers start 44. Depending on the interface you are using you might need to simply set the number prefix to 44, +44 or you might need to set the Number Plan Indicator. 正如philnash指出的那样,英国号码以44开头。根据所使用的界面,您可能需要简单地将数字前缀设置为44 +44,或者可能需要设置号码计划指示器。 The + commonly preceding international numbers is a shortcut for mobile devices to set the NPI and does not normally have any relevance in messaging protocols otherwise... so you will need to consult with your SMS provider. 常用的国际号码+是移动设备设置NPI的快捷方式,否则通常与消息传递协议没有任何关系...因此,您需要咨询SMS提供商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM