duanli9591 2019-05-04 06:50
浏览 80

如何使用PHP在印地文发送短信

i have successfully integrated the bulk sms gateway and its sending the message too. But,now i am trying to send the sms in hindi. When i put hindi message like

$message = 'बधाई हो! मेरी वेबसाइट में आपका स्वागत है, अब आप हमारे सदस्य हैं। आपका url है '.$url.' ';

It shows me ?????????????? ???????? ????? like this.

Here is my php code:

<?php
include 'config.php';
if(isset($_POST['save'])){
    $user = "xxxxxxxxxxxx";
    $password = "xxxxxxxxxxxxx";
    $senderid = "xxxxxxxxxxxxxx";
    $checkbox = $_POST['check'];
    for($i=0;$i<count($checkbox);$i++){
    $del_id = $checkbox[$i]; 
    mysqli_query($conn,"UPDATE inventory_details SET status='0' WHERE id='".$del_id."'");
}
}

$smsurl = "http://kit19.com/ComposeSMS.aspx?";

function httpRequest($url){
    $pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
    preg_match($pattern,$url,$args);
    $in = "";
    $fp = fsockopen($args[1],80, $errno, $errstr, 30);
    if (!$fp) {
       return("$errstr ($errno)");
    } else {
        $args[3] = "C".$args[3];
        $out = "GET /$args[3] HTTP/1.1
";
        $out .= "Host: $args[1]:$args[2]
";
        $out .= "User-agent: Website
";
        $out .= "Accept: */*
";
        $out .= "Connection: Close

";

        fwrite($fp, $out);
        while (!feof($fp)) {
           $in.=fgets($fp, 128);
        }
    }
    fclose($fp);
    return($in);
}

function SMSSend($phone, $msg, $debug=false){
      global $user,$password,$senderid,$smsurl;

      $url = 'username='.$user;
      $url.= '&password='.$password;
      $url.= '&sender='.$senderid;
      $url.= '&to='.urlencode($phone);
      $url.= '&message='.urlencode($msg);
      $url.= '&priority=1';
      $url.= '&dnd=1';
      $url.= '&unicode=0';


      $urltouse =  $smsurl.$url;
      if ($debug) { echo ""; }

      $response = httpRequest($urltouse);
      if ($debug) {

        str_replace(array("<",">"),array("&lt;","&gt;"),$response).
           "</pre><br>"; }

      return($response);
}

$checkbox = $_POST['check'];
    for($i=0;$i<count($checkbox);$i++){
    $del_id = $checkbox[$i]; 
    $PrimaryMobile = mysqli_query($conn,"SELECT * FROM inventory_details WHERE id='".$del_id."'");
    while($row = mysqli_fetch_array($PrimaryMobile)) {
        $PrimaryMobile_no = $row['PrimaryMobile_no'];
        $firm_name = $row['firm_name'];

        $firm_name = urldecode($firm_name);  
        $firm_name = str_replace(' ', '-', $firm_name); 
        $firm_name = str_replace('&', '-', $firm_name); 
        $firm_name = str_replace('(', '-', $firm_name); 
        $firm_name = str_replace(')', '-', $firm_name); 

                        # are you missing a / here ???
        $url = 'http://www.example.com/' . urlencode($del_id) . '-' . urlencode($firm_name);

        $message = 'बधाई हो! मेरी वेबसाइट में आपका स्वागत है, अब आप हमारे सदस्य हैं। आपका url है '.$url.' ';
    }

$debug = true;
SMSSend($PrimaryMobile_no,$message,$debug);

}
?>

I have tried the script :

public function utf8_to_unicode($str) {
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i = 0; $i < strlen($str); $i++) {
    $thisValue = ord($str[$i]);
    if ($thisValue < 128) {
        $number = dechex($thisValue);
        $unicode[] = (strlen($number) == 1) ? '%u000' . $number : "%u00" . $number;
    } else {
        if (count($values) == 0)
            $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
        $values[] = $thisValue;
        if (count($values) == $lookingFor) {
            $number = ( $lookingFor == 3 ) ?
                    ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ) :
                    ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64
                    );
            $number = dechex($number);
            $unicode[] =
                    (strlen($number) == 3) ? "%u0" . $number : "%u" . $number;
            $values = array();
            $lookingFor = 1;
        } // if
    } // if
}
return implode("", $unicode);
}

but its not working. Please help me out. Thanks

  • 写回答

1条回答 默认 最新

  • dongxian2863 2019-07-12 11:53
    关注

    First, you need to know, that not all Bulk SMS provider support or allow Unicode Message. There are different encoding for each SMS format. So far I found SMS.to allow Unicode SMS sending, which mean you can send SMS in Hindi or any other regional language.

    Transcoding Option

    They count 70 Unicode characters as 1 SMS, which is far better from most of the Bulk SMS providers, which will allow only 30 characters in 1 SMS. They also offer REST API: https://sms.to/api-docs so it's easy to integrate.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!