检测短信发送文本数量的最佳方式 [英] best way to detect number of SMS needed to send a text

查看:212
本文介绍了检测短信发送文本数量的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个php中的代码/ lib,我将其称之为文本,并传递给它,它会告诉我:


  1. 为了以SMS(7,8,16位)的形式发送此文本,我需要使用什么编码?

  2. 我将用于发送此文本的短信数量(在 http://ozekisms.com/index.php中计算segmenation信息一定很聪明?owpn = 612

你有什么想法可以为我做这个吗?



再次,我不是在寻找发送短信或转换短信,只是给我关于文本的信息



更新:



确定我做了下面的代码,似乎工作正常,让我知道如果你有更好的/优化的代码/解决方案/ lib

  $ text ='\ @£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ-./0123456789:;<=>? ¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖ Ü§¿abcdefghijklmnopqrstuvwxyzäöñüà^ {} [〜] |€; // \\。 //''; //''; 

打印$文本\\\
;
打印isGsm7bit($ text)\\\
;
打印getNumberOfSMSsegments($ text)。\\\
;




函数getNumberOfSMSsegments($ text,$ MaxSegments = 6){
/ *
http://en.wikipedia.org/wiki/SMS

可以使用多个消息发送更大的内容(连接的短信,多部分或分段短信或长短信),
在这种情况下,每个消息将以包含分段信息的用户数据头(UDH)开始
由于UDH是有效负载的一部分,因此每个段的可用字符数较少:
153对于7位编码,
134用于8位编码,
67用于16位编码
然后接收手机负责重新组装消息并将其呈现给用户长消息
虽然标准理论上允许多达255个段,[35] 6到8段消息是实际的最大值,
和长消息通常被收取为相当于多个短信。有关更多信息,请参阅连接短信。
一些提供商为消息提供了面向长度的定价方案,但是这种现象正在消失。
* /
$ TotalSegment = 0;
$ textlen = mb_strlen($ text);
if($ textlen == 0)return false; //我可以看到大多数移动设备不会允许您发送空短信,通过此检查,我们确保我们不允许空的短信

if(isGsm7bit($ text)){// 7 -bit
$ SingleMax = 160;
$ ConcatMax = 153;
} else {// UCS-2 Encoding(16-bit)
$ SingleMax = 70;
$ ConcatMax = 67;
}

if($ textlen< = $ SingleMax){
$ TotalSegment = 1;
} else {
$ TotalSegment = ceil($ textlen / $ ConcatMax);
}

if($ TotalSegment> $ MaxSegments)return false; //短信很大
return $ TotalSegment;
}

函数isGsm7bit($ text){
$ gsm7bitChars =\\\ @£\ $¥èéùìòÇ\\\
Øø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ!\ #¤%​​&'()* +, - 。/ 0123456789:< =>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^ {} [〜] |€;
$ textlen = mb_strlen );
($ i = 0; $ i <$ textlen; $ i ++){
if((strpos($ gsm7bitChars,$ text [$ i])== false)&& ; $($ text [$ i]!=\\)){return false;} // strpos无法检测字符串中的\
}
返回true;
}


解决方案

p $ $ $ $ $ $ $ $ $ $ $ ^ {} [〜] |€'; //\\。//''; //'';

打印$文本。 \\\
;
打印isGsm7bit($ text)。 \\\
;
打印getNumberOfSMSsegments($ text)。 \\\
;

函数getNumberOfSMSsegments($ text,$ MaxSegments = 6){
/ *
http://en.wikipedia.org/wiki/SMS

可以使用多个消息
发送更大的内容(连接的短信,多部分或分段短信或长短信),在这种情况下,每个消息将以包含分段信息的用户数据头(UDH)开头。
由于UDH是有效负载的一部分,每个段的可用字符数较少:
153用于7位编码,
134位用于8位编码,
67表示16位编码。
然后,接收手机负责重新组装消息并将其作为一个长消息呈现给用户。
虽然标准理论上允许多达255个段,[35] 6到8段消息是实际的最大值,
和长消息通常被收取等同于多个SMS消息。有关更多信息,请参阅连接短信。
一些提供商为消息提供了面向长度的定价方案,但是这种现象正在消失。
* /
$ TotalSegment = 0;
$ textlen = mb_strlen($ text);
if($ textlen == 0)return false; //我可以看到大多数移动设备不会允许您发送空短信,通过此检查,我们确保我们不允许空的短信

if(isGsm7bit($ text)){// 7 -bit
$ SingleMax = 160;
$ ConcatMax = 153;
} else {// UCS-2 Encoding(16-bit)
$ SingleMax = 70;
$ ConcatMax = 67;
}

if($ textlen< = $ SingleMax){
$ TotalSegment = 1;
} else {
$ TotalSegment = ceil($ textlen / $ ConcatMax);
}

if($ TotalSegment> $ MaxSegments)return false; //短信很大
return $ TotalSegment;
}

函数isGsm7bit($ text){
$ gsm7bitChars =\\\ @£\ $¥èéùìòÇ\\\
Øø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ!\ #¤%​​&'()* +, - 。/ 0123456789:< =>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^ {} [〜] |€;
$ textlen = mb_strlen );
($ i = 0; $ i <$ textlen; $ i ++){
if((strpos($ gsm7bitChars,$ text [$ i])== false)&& ; $($ text [$ i]!=\\)){return false;} // strpos无法检测字符串中的\
}
返回true;
}


I'm looking for a code/lib in php that I will call it and pass a text to it and it will tell me:

  1. What is the encode I need to use in order to send this text as SMS (7,8,16 bit)
  2. How many SMS message I will use to send this text (it must be smart to count "segmenation information" like in http://ozekisms.com/index.php?owpn=612)

do you have any idea of any code/lib exists that will do this for me?

Again I'm not looking for sending SMS or converting SMS, just to give me information about the text

Update:

Ok I did the below code and it seems to be working fine, let me know if you have better/optimized code/solution/lib

$text = '\@£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ -./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^{}[~]|€' ; //"\\". //'"';//' ';

print $text . "\n";
print isGsm7bit($text). "\n";
print getNumberOfSMSsegments($text). "\n";




function getNumberOfSMSsegments($text,$MaxSegments=6){
/*
http://en.wikipedia.org/wiki/SMS

Larger content (concatenated SMS, multipart or segmented SMS, or "long SMS") can be sent using multiple messages, 
in which case each message will start with a user data header (UDH) containing segmentation information. 
Since UDH is part of the payload, the number of available characters per segment is lower: 
153 for 7-bit encoding, 
134 for 8-bit encoding and 
67 for 16-bit encoding. 
The receiving handset is then responsible for reassembling the message and presenting it to the user as one long message. 
While the standard theoretically permits up to 255 segments,[35] 6 to 8 segment messages are the practical maximum, 
and long messages are often billed as equivalent to multiple SMS messages. See concatenated SMS for more information. 
Some providers have offered length-oriented pricing schemes for messages, however, the phenomenon is disappearing.
*/
$TotalSegment=0;
$textlen = mb_strlen($text);
if($textlen==0) return false; //I can see most mobile devices will not allow you to send empty sms, with this check we make sure we don't allow empty SMS

if(isGsm7bit($text)){ //7-bit
    $SingleMax=160;
    $ConcatMax=153;
}else{ //UCS-2 Encoding (16-bit)
    $SingleMax=70;
    $ConcatMax=67;
}

if($textlen<=$SingleMax){
    $TotalSegment = 1;
}else{
    $TotalSegment = ceil($textlen/$ConcatMax);
}

if($TotalSegment>$MaxSegments) return false; //SMS is very big.
return $TotalSegment;
}

function isGsm7bit($text){
$gsm7bitChars = "\\\@£\$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^{}[~]|€";
$textlen = mb_strlen($text);
for ($i = 0;$i < $textlen; $i++){
    if ((strpos($gsm7bitChars, $text[$i])==false) && ($text[$i]!="\\")){return false;} //strpos not able to detect \ in string
}
return true;
}

解决方案

The best solution I have so far:

$text = '\@£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ -./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^{}[~]|€' ; //"\\". //'"';//' ';

print $text . "\n";
print isGsm7bit($text). "\n";
print getNumberOfSMSsegments($text). "\n";

function getNumberOfSMSsegments($text,$MaxSegments=6){
/*
http://en.wikipedia.org/wiki/SMS

Larger content (concatenated SMS, multipart or segmented SMS, or "long SMS") can be sent using multiple messages, 
in which case each message will start with a user data header (UDH) containing segmentation information. 
Since UDH is part of the payload, the number of available characters per segment is lower: 
153 for 7-bit encoding, 
134 for 8-bit encoding and 
67 for 16-bit encoding. 
The receiving handset is then responsible for reassembling the message and presenting it to the user as one long message. 
While the standard theoretically permits up to 255 segments,[35] 6 to 8 segment messages are the practical maximum, 
and long messages are often billed as equivalent to multiple SMS messages. See concatenated SMS for more information. 
Some providers have offered length-oriented pricing schemes for messages, however, the phenomenon is disappearing.
*/
$TotalSegment=0;
$textlen = mb_strlen($text);
if($textlen==0) return false; //I can see most mobile devices will not allow you to send empty sms, with this check we make sure we don't allow empty SMS

if(isGsm7bit($text)){ //7-bit
    $SingleMax=160;
    $ConcatMax=153;
}else{ //UCS-2 Encoding (16-bit)
    $SingleMax=70;
    $ConcatMax=67;
}

if($textlen<=$SingleMax){
    $TotalSegment = 1;
}else{
    $TotalSegment = ceil($textlen/$ConcatMax);
}

if($TotalSegment>$MaxSegments) return false; //SMS is very big.
return $TotalSegment;
}

function isGsm7bit($text){
$gsm7bitChars = "\\\@£\$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^{}[~]|€";
$textlen = mb_strlen($text);
for ($i = 0;$i < $textlen; $i++){
    if ((strpos($gsm7bitChars, $text[$i])==false) && ($text[$i]!="\\")){return false;} //strpos not     able to detect \ in string
}
return true;
}

这篇关于检测短信发送文本数量的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆