fix utf8 chars in sms and add tool to quota to check if a text is gsm0338 compatible
This commit is contained in:
parent
a39c9577b1
commit
d826762e9d
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace adapters;
|
||||
|
||||
use controllers\internals\Quota;
|
||||
use controllers\internals\Tool;
|
||||
use descartes\Router;
|
||||
|
||||
|
@ -25,6 +26,10 @@ class KannelAdapter implements AdapterInterface
|
|||
const KANNEL_SENDSMS_HTTP_CODE_ACCEPTED = 202;
|
||||
const KANNEL_SENDSMS_HTTP_CODE_QUEUED = 202;
|
||||
|
||||
const KANNEL_CODING_7_BITS = 0;
|
||||
const KANNEL_CODING_8_BITS = 1;
|
||||
const KANNEL_CODING_UCS_2 = 2;
|
||||
|
||||
/**
|
||||
* DLR mask to transmit to kannel
|
||||
*
|
||||
|
@ -285,6 +290,13 @@ class KannelAdapter implements AdapterInterface
|
|||
'dlr-url' => $forged_dlr_url,
|
||||
];
|
||||
|
||||
//If necessary, use utf8 sms to represent special chars
|
||||
$use_utf8_sms = !Quota::is_gsm0338($text);
|
||||
if ($use_utf8_sms)
|
||||
{
|
||||
$data['coding'] = self::KANNEL_CODING_8_BITS;
|
||||
}
|
||||
|
||||
if ($this->smsc)
|
||||
{
|
||||
$data['smsc'] = $this->smsc;
|
||||
|
|
|
@ -108,14 +108,13 @@ class Quota extends StandardController
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute how many credit a message represent
|
||||
* this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8.
|
||||
* Check if a message can be encoded as gsm0338 or if it must be UTF8
|
||||
*
|
||||
* @param string $text : Message to send
|
||||
*
|
||||
* @return int : Number of credit to send this message
|
||||
* @return bool : True if gsm0338, false if UTF8
|
||||
*/
|
||||
public static function compute_credits_for_message($text)
|
||||
public static function is_gsm0338($text)
|
||||
{
|
||||
//Gsm 03.38 charset to detect if message is compatible or must use utf8
|
||||
$gsm0338 = [
|
||||
|
@ -144,12 +143,26 @@ class Quota extends StandardController
|
|||
{
|
||||
if (!in_array(mb_substr($text, $i, 1), $gsm0338))
|
||||
{
|
||||
$is_gsm0338 = false;
|
||||
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute how many credit a message represent
|
||||
* this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8.
|
||||
*
|
||||
* @param string $text : Message to send
|
||||
*
|
||||
* @return int : Number of credit to send this message
|
||||
*/
|
||||
public static function compute_credits_for_message($text)
|
||||
{
|
||||
$len = mb_strlen($text);
|
||||
$is_gsm0338 = self::is_gsm0338($text);
|
||||
|
||||
return $is_gsm0338 ? ceil($len / 160) : ceil($len / 70);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue