Home Backend Development PHP Tutorial 转一个手机开发的帖子(来自开发者俱乐部)_PHP

转一个手机开发的帖子(来自开发者俱乐部)_PHP

Jun 01, 2016 pm 12:39 PM
information club Post develop Developer cell phone coding

代码:--------------------------------------------------------------------------------
目前手机短信息的应用越来越广泛,互联网上提供短信息发送的站点也越来越多,但一些站点的服务并不尽如人意,往往发出去的短信息石沉大海。最可靠的发送方法当然是用手中的手机了,如果设置了状态报告,更能确切知道对方是否收到了此条信息。手机发送尽管比较可靠, 但也存在输入麻烦、效率低的问题。本文介绍一种方法,只要手机能够与电脑相连(通过红外端口或用手机数据线连接串行口,同时手机支持GSM AT指令集),就可以通过自行编制的短信息发送软件,实现短信息的发送。
现在市场上的大多数手机均支持类似于Modem控制的GSM AT指令集,该指令集是由诺基亚、爱立信、摩托罗拉和HP等厂家共同为GSM系统研制的,其中包含了对SMS(Short Message Service)的控制。
GSM AT相关指令的介绍
与SMS有关的GSM AT指令如表1所示:

表1 相关的GSM AT指令
对SMS的控制共有三种实现途径:
Block Mode;
基于AT命令的Text Mode;
基于AT命令的PDU Mode。
Text Mode比较简单,多款诺基亚手机均支持该模式。西门子的手机大多只支持PDU模式,PDU模式是发送或接收手机SMS信息的一种方法,短信息正文经过十六进制编码后被传送。目前,PDU已取代Block Mode,因此本文主要探讨PDU模式的发送。
计算机和手机的通信
本文以西门子 S3568i为例,介绍如何实现短信息的发送。
数据线连接
首先,通过S35/25数据线将手机与电脑串行口相连。然后,打开超级终端,选择直接串行口连接,端口参数设为19200速率、无校验、数据位8、停止位1。
红外线连接
如果使用带红外端口的计算机,可以设置与手机的无线连接。首先确认计算机红外端口已打开,并将手机的红外线和收传真/数据功能打开,对接红外端口,计算机系统托盘上应当出现一个红外设备西门子S35(如果没有安装红外监视器,则不显示)。然后,打开超级终端,选择IrDa上的串行口。
连接测试
点击超级终端工具条上的呼叫按钮,输入AT并回车,屏幕上如果出现OK则表明计算机与手机的连接成功,这时就可以输入各类GSM AT指令了。
如:查询手机厂家,输入AT+CGMI=,屏幕显示Siemens。
通常情况下,执行测试命令AT+CMGS=?,如果返回OK,表明手机支持此指令。该指令的完整语法格式如下:
If PDU mode (+CMGF=0)+CMGS=PDU is given
如果短信息格式指令AT+CMGF返回的是0,则SMS格式为PDU模式,再执行AT+CMGS=命令后,手机返回“>”符号并等待输入,输入PDU数据并以^Z或Esc键结束。
如果信息发送成功,则返回OK,并显示信息号:
+CMGS:
如果发送失败,则返回如下信息:
+CMS ERROR:
PDU数据格式的分析
下面通过对存储在手机中的待发信息的分析,来介绍SMS PDU的数据格式。首先,用手机写一条短信息,发送手机号码为13605696031,信息内容为“Hello World!”。通过执行AT+CMGL=2可以读出此条信息。
操作过程如下(斜体字符为响应信息,{}内为注释):
AT
OK
AT+CMGL=2 {读未发短信息}
+CMGL: 1,2,,24 {1表示信息个数,2表示未发信息,24表示信息总容量}
08 91 683108501505F0 11 00 0B 81 3106656930F1 0000A7 0B E8329BFD06DDDF723619
OK 
下面分析这条信息:
08:短信息中心地址长度。
91:短信息中心号码类型,91是TON/NPI。TON/NPI遵守International/E.164标准,指在号码前需加‘+’号;此外还可有其他数值,但91最常用。
683108501505F0:短信息号码,是所使用的服务中心地址。由于位置上略有处理,实际号码应为:8613805515500(字母F意指长度减1),这是作者所在地GSM短信息中心的号码。
11:文件头字节(header byte,是一种bitmask)。这里11指正常地发送短信息。
00:信息类型。
0B:被叫号码长度。
81:被叫号码类型。
3106656930F1:被叫号码,也经过了移位处理,实际号码为13605696031。
0000A7:短信息编码类型GSM Default Alphabet,如为中文则是000010。
0B:短信息长度。
E8329BFD06DDDF723619:短信息内容“Hello World!”。
短信息的编码方法及编程实现
下面我们介绍纯英文和纯中文的信息编码方法。通过测试我们发现,每条发送的短信息前面部分均相同,只是被叫号码和短信息内容有变化。
1.英文编码
参见表2,设短信息内容为“Hello World!”。缺省的GSM 字符集为7位编码,可以简单地理解为ASCII码(ASCII值小于80Hex,因此,Bit8被忽略),依次将下一7位编码的后几位逐次移至前面,形成新的8位编码,参见表2箭头指示。需要注意的是第9行,移位计数已达7位,则直接将本编码前加0。GSM并非支持所有的ASCII字符显示。
表2 英文编码的实现过程

下面是实现英文编码的部分Delphi 5代码:
//英文格式编码,s为String
function Encode1(var s:String):String;
var
i,j,len:Integer;
cur:Integer;
t:String;
begin
Result:=‘’;
len:=Length(s);
//j 用于移位计数
i:=1;j:=0;
while ibegin
if i//数据变换
cur:=(ord(s[i]) shr j) or ((ord(s[i+1]) shl (7-j)) and $ff)
else
cur:=(ord(s[i]) shr j) and $7f;
FmtStr(t,‘%2.2X’,[cur]);
Result:=Result+t;
inc(i);
//移位计数达到7位的特别处理
j:=(j+1) mod 7;if j=0 then inc(i);
end;
end;  
2.中文编码
参见表3,设短信息内容为“中文短信息”。中文短信息的实现较简单,只需将??????的中文编码转换为代码页为CP936的Unicode编码即可。
表3 中文编码的实现过程

通过Delphi的WideString类型转换,可以巧妙地实现??????到Unicode的编码转换(注意代码页和操作系统相关联)。下面是实现中文编码的部分Delphi 5代码:
// 中文格式编码,s为Unicode String
function Encode2(var s:WideString):String;
var
i,len:Integer;
cur:Integer;
t:String;
begin
Result:=‘’;
len:=Length(s);
i:=1;
while ibegin
cur:=ord(s[i]);
//BCD转换
FmtStr(t,‘%4.4X’,[cur]);
Result:=Result+t;
inc(i);
end;
end;
小 结
以上介绍了PDU格式的短信息编码。建议英文信息长度不超过140个字符,中文信息不要超过54个汉字。如果使用能够支持文本方式的手机进行发送,实现起来更简单。如发送“Hello World!”,用如下的AT指令即可:
AT+CGMF=1AT+CGMS=“13605696031”,129
>Hello World!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Samsung Galaxy S25 Ultra mobile phone leaked: 6.86 inches, horizontal screen-to-body ratio 94.1% Samsung Galaxy S25 Ultra mobile phone leaked: 6.86 inches, horizontal screen-to-body ratio 94.1% Aug 17, 2024 pm 01:49 PM

According to news on August 17, the source @ibinguniverse posted on Weibo today, stating that the exact size of Apple iPhone 16 Pro Max is 6.88 inches, and the exact size of Galaxy S25 Ultra is 6.86 inches. Both can be regarded as 6.9 inches. Sources indicate that the Samsung Galaxy S25 Ultra has a narrower body and a wider screen than the S24 Ultra, with a horizontal screen-to-body ratio of 94.1%, while the S24 Ultra’s horizontal screen-to-body ratio is 91.5%. Fenye checked the relevant Weibo of the source. He also commented on the newly exposed photos of iPhone 16 Pro Max and believed that it was wrong to be close to a micro-curve. The phone is actually a straight screen + 2.5D glass.

'Tandem OLED' has been popularized by Apple. How is it better than OLED? 'Tandem OLED' has been popularized by Apple. How is it better than OLED? Aug 19, 2024 am 04:42 AM

Although Apple has been criticized for its lack of innovation in recent years, Apple has not always stood still. At least in terms of hardware design, with the support of the high unit prices of Apple products, its engineers can easily try some new technologies without having to consider too much cost issues. For example, iPad Pro, as Apple's favorite "display technology" test field, iPad Pro has been at the forefront of display technology for portable smart devices from miniLED in 2021 to tandem OLED in 2024. Although the iPad Pro is not the first portable smart device equipped with a miniLED screen (MSI released a miniLED laptop a year earlier than Apple), when you compare the parameters of the two, you will quickly realize that they are not the same

Hynix is ​​the first to demonstrate UFS 4.1 flash memory: based on V9 TLC NAND particles Hynix is ​​the first to demonstrate UFS 4.1 flash memory: based on V9 TLC NAND particles Aug 09, 2024 pm 03:33 PM

According to news on August 9, at the FMS2024 Summit, SK Hynix demonstrated its latest storage products, including UFS4.1 universal flash memory that has not yet officially released specifications. According to the official website of the JEDEC Solid State Technology Association, the latest UFS specification currently announced is UFS4.0 in August 2022. Its theoretical interface speed is as high as 46.4Gbps. It is expected that UFS4.1 will further improve the transmission rate. 1. Hynix demonstrated 512GB and 1TBUFS4.1 general-purpose flash memory products, based on 321-layer V91TbTLCNAND flash memory. SK Hynix also exhibited 3.2GbpsV92TbQLC and 3.6GbpsV9H1TbTLC particles. Hynix shows off V7-based

Apple and Huawei both wanted to make a buttonless phone, but Xiaomi made it first? Apple and Huawei both wanted to make a buttonless phone, but Xiaomi made it first? Aug 29, 2024 pm 03:33 PM

According to a report from Smartprix, Xiaomi is developing a buttonless mobile phone codenamed "Suzaku". According to this news, this mobile phone codenamed Zhuque will be designed with an integrated concept, use an under-screen camera, and be equipped with Qualcomm Snapdragon 8gen4 processor. If the plan does not change, we are likely to see its arrival in 2025. When I saw this news, I thought I was back in 2019 - at that time, Xiaomi released the Mi MIX Alpha concept phone, and the surround-screen button-less design was quite amazing. This is the first time I have seen the charm of a buttonless mobile phone. If you want a piece of "magic glass", you must first kill the buttons. In "The Biography of Steve Jobs", Jobs once expressed that he hoped that the mobile phone could be like a piece of "magic glass".

Released on August 1, physical photos of Xiaomi POCO M6 Plus 5G mobile phone and POCO Buds X1 headphones exposed Released on August 1, physical photos of Xiaomi POCO M6 Plus 5G mobile phone and POCO Buds X1 headphones exposed Jul 30, 2024 pm 02:29 PM

According to news on July 30, source Yogesh Brar posted a tweet on the X platform yesterday (July 29), sharing physical photos of Xiaomi POCOM6 Plus 5G mobile phone and POCO Buds X1 headphones. The official announcement of the two products will be released on August 1. Xiaomi POCOM6 Plus 5G mobile phone sources said that Xiaomi POCOM6 Plus 5G mobile phone will be equipped with a 6.8-inch LCD screen, equipped with Qualcomm Snapdragon 4Gen2AE processor, equipped with a 108-megapixel camera on the back, and a 5030mAh capacity battery. As previously reported, this phone is available in three colors: purple, black, and silver. It is roughly the same as the standard POCOM6 phone, but the LED flash ring is relatively more prominent. POCOB

The first 1.5K under-screen camera! Nubia Z70 Ultra is here: the world's first Snapdragon 8 Gen4 true full-screen phone The first 1.5K under-screen camera! Nubia Z70 Ultra is here: the world's first Snapdragon 8 Gen4 true full-screen phone Aug 19, 2024 pm 03:47 PM

According to news on August 19, Nubia has been adhering to the true full-screen design since the release of Z50 Ultra, and has been continuously exploring the field of proactive photography under high-pixel screens. Today, digital blogger Wisdom Pikachu broke the news that the Nubia Z70 Ultra, which will be released in the second half of this year, will debut with 1.5K under-screen camera technology, which is the highest-resolution UDC solution in the industry so far. It is reported that ZTE’s under-screen proactive solution has advanced to the sixth generation. The latest under-screen proactive solution is available in the Nubia Z60 Ultra and Red Magic 9S Pro series. The screen resolution is 2480x1116, which is between 1080P and 1.5K resolution. This time Nubia will break through the limitations of existing resolutions and set a new benchmark in the industry.

To run Google's Gemini Nano AI model locally, the Samsung Galaxy S25 Ultra phone was revealed to be equipped with 16GB of memory To run Google's Gemini Nano AI model locally, the Samsung Galaxy S25 Ultra phone was revealed to be equipped with 16GB of memory Jul 31, 2024 pm 05:55 PM

According to news on July 31, the source @ibinguniverse posted a tweet on the Equipped with 16GB of memory. Samsung mobile phone memory capacity update Samsung has launched 16GB memory on Galaxy S20 Ultra and Galaxy S21 Ultra mobile phones. Starting from Galaxy S22 Ultra, including the latest flagship Galaxy S24 Ultra mobile phone, the memory capacity of Samsung mobile phones is capped at 12GB. It is reported that the upcoming Samsung Galaxy S25 and Galaxy S25+ will use 12GB LPDD

Huawei Mate 70 series configuration leaked: All series have 1.5K screens and super large batteries Huawei Mate 70 series configuration leaked: All series have 1.5K screens and super large batteries Aug 08, 2024 pm 10:21 PM

According to news on August 8, the detailed configuration information of Huawei Mate70 series mobile phones has been recently exposed. This series of mobile phones is expected to be released in the fourth quarter of 2024. 1. According to reports, the entire Mate70 series will use customized top-level 1.5K resolution screens to meet users’ requirements for screen clarity. It is expected that Huawei Mate70Pro and the extra-large cup version will be equipped with fourth-depth screens, while the standard Mate70 may adopt a slightly smaller straight-screen design. In addition to screen upgrades, the Huawei Mate70 series will also be equipped with ultra-large-capacity batteries with new base materials, which heralds a breakthrough in the battery life of Huawei Mate series mobile phones. Although Huawei is developing ultrasonic fingerprint unlocking technology, this year’s Mate70 series will not be equipped with this feature. this

See all articles