Send Hindi SMS using API is not that easy as it look like. While working on a project i have to send Hindi SMS and when i write hindi in message and send it to the mobile. It shows me ?????????????? ???????? ????? like this. So i figured out if we use unicode to send the message than we can send the SMS in Hindi or other language. This tutorial is about to send SMS in Hindi.
In this tutorial we are using the Bulk SMS API form Simply IT Solutions Pvt Ltd. They are providing fast and perfect delivery.
So here is the magical function to change your message to the UNICODE message.
$str="98XXXXXXXX 100 रु का रीचार्ज किया गया है|"; // Our SMS $msg=str_replace('%u', '',$smsClass->utf8_to_unicode($str));//it will convert the normal message to the unicode
Above line will change the message to the Unicode By using the below function.
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); }
After change the SMS to Unicode it will look like a list of many numbers. Now next part is to send the sms. As i told you earlier that we are using an API so we create a function and passing mobile no and message to that function.
public function shootUnicodeSMS($mobileno,$message){ $username="your username"; $password="your password"; $Senderid="your sender it"; $url ="http://tsms.simplyitsols.com/bulksms/bulksms?username=$username&password=$password&type=2&dlr=1&destination=$mobileno&source=$Senderid&message=$message"; $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $ab=curl_exec($ch); curl_close($ch); return $ab.",".$url; }
It will send the SMS in Hindi. Hope you like it if you have any advice or comment than please write in the comment box.
Sir mein company ka referer link bahut saare customers ko bhejna chahta hu lekin 100 sms bhejne ke baad msg aata hai ki ab aapke paise ktenge. Aisa free sms wala koi system nhi hai jisse mein customers ko sms bhej sku. Api samajh nhi aa rha kya hai ye
Can you show the random number generated I implemented logic in java but the message is not sending
I have developed an application using VB 6.0 in which I usually send the sms using the code but when Try to send sms in hindi it displays like ????? ????? . Sir can I use the above convert function in my CV script?
If you can change it according to the VB 6.0 then surely it will work.
after using Unicode function in sms script I’m getting Chinese language in sms. ( after full stop in in one sentence . its taking another line in Chinese language.
Please reply !!!
Have you checked that your sms gateway supports the unicode. As many gateway provider put some type on the URL so that the gateway understand the actual characters encoding
I used the code which is given above, but i m getting unicode number instead of hindi msg
For using the unicode message your provider should provide you the Unicode message method in your sms API
Thanks .. this article is very useful .. I am a C# developer and implemented your logic in my code .. it worked 🙂 .. Here is the code.. hope this may help others ..
public string Utf8ToUnicode(string str)
{
var unicode = new List();
var values = new List();
var lookingFor = 1;
var ascii = Encoding.UTF8.GetBytes(str);
for (var i = 0; i < ascii.Length; i++)
{
var thisValue = ascii[i];
if(thisValue == 32)
{
unicode.Add("%20");
}
else
if (thisValue < 128)
{
var uniStr = ConvertToHex(thisValue);
unicode.Add((uniStr.Length == 1) ? "%u000" + uniStr : "%u00" + uniStr);
}
else
{
if (values.Count == 0)
lookingFor = (thisValue < 224) ? 2 : 3;
values.Add(thisValue);
if (values.Count == lookingFor)
{
var number = (lookingFor == 3) ?
((values[0] % 16) * 4096) + ((values[1] % 64) * 64) + (values[2] % 64) :
((values[0] % 32) * 64) + (values[1] % 64
);
var uniStr = number.ToString("X");
unicode.Add((uniStr.Length == 3) ? "%u0" + uniStr : "%u" + uniStr);
values = new List();
lookingFor = 1;
} // if
} // if
}
return string.Join(“”, unicode.ToArray());
}
Thank You very much for your kind support. It will be really helpful for other’s.
can you convert it in vb6.0
Sorry dont know vb6.0
Sir am creating a mock test portal for SSC and given the questions in English only but there are so many students who prefer Hindi instead of english and I don’t want to re-type the all questions and options in Hindi, is there any way to display all English typed along with Hindi translation without handling it twice?