亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home php教程 php手冊 轉(zhuǎn)一個(gè)手機(jī)開發(fā)的帖子(來自開發(fā)者俱樂部)

轉(zhuǎn)一個(gè)手機(jī)開發(fā)的帖子(來自開發(fā)者俱樂部)

Jun 21, 2016 am 09:14 AM
lt pdu string

代碼:--------------------------------------------------------------------------------
目前手機(jī)短信息的應(yīng)用越來越廣泛,互聯(lián)網(wǎng)上提供短信息發(fā)送的站點(diǎn)也越來越多,但一些站點(diǎn)的服務(wù)并不盡如人意,往往發(fā)出去的短信息石沉大海。最可靠的發(fā)送方法當(dāng)然是用手中的手機(jī)了,如果設(shè)置了狀態(tài)報(bào)告,更能確切知道對方是否收到了此條信息。手機(jī)發(fā)送盡管比較可靠, 但也存在輸入麻煩、效率低的問題。本文介紹一種方法,只要手機(jī)能夠與電腦相連(通過紅外端口或用手機(jī)數(shù)據(jù)線連接串行口,同時(shí)手機(jī)支持GSM AT指令集),就可以通過自行編制的短信息發(fā)送軟件,實(shí)現(xiàn)短信息的發(fā)送。
現(xiàn)在市場上的大多數(shù)手機(jī)均支持類似于Modem控制的GSM AT指令集,該指令集是由諾基亞、愛立信、摩托羅拉和HP等廠家共同為GSM系統(tǒng)研制的,其中包含了對SMS(Short Message Service)的控制。
GSM AT相關(guān)指令的介紹
與SMS有關(guān)的GSM AT指令如表1所示:

表1 相關(guān)的GSM AT指令
對SMS的控制共有三種實(shí)現(xiàn)途徑:
Block Mode;
基于AT命令的Text Mode;
基于AT命令的PDU Mode。
Text Mode比較簡單,多款諾基亞手機(jī)均支持該模式。西門子的手機(jī)大多只支持PDU模式,PDU模式是發(fā)送或接收手機(jī)SMS信息的一種方法,短信息正文經(jīng)過十六進(jìn)制編碼后被傳送。目前,PDU已取代Block Mode,因此本文主要探討PDU模式的發(fā)送。
計(jì)算機(jī)和手機(jī)的通信
本文以西門子 S3568i為例,介紹如何實(shí)現(xiàn)短信息的發(fā)送。
數(shù)據(jù)線連接
首先,通過S35/25數(shù)據(jù)線將手機(jī)與電腦串行口相連。然后,打開超級終端,選擇直接串行口連接,端口參數(shù)設(shè)為19200速率、無校驗(yàn)、數(shù)據(jù)位8、停止位1。
紅外線連接
如果使用帶紅外端口的計(jì)算機(jī),可以設(shè)置與手機(jī)的無線連接。首先確認(rèn)計(jì)算機(jī)紅外端口已打開,并將手機(jī)的紅外線和收傳真/數(shù)據(jù)功能打開,對接紅外端口,計(jì)算機(jī)系統(tǒng)托盤上應(yīng)當(dāng)出現(xiàn)一個(gè)紅外設(shè)備西門子S35(如果沒有安裝紅外監(jiān)視器,則不顯示)。然后,打開超級終端,選擇IrDa上的串行口。
連接測試
點(diǎn)擊超級終端工具條上的呼叫按鈕,輸入AT并回車,屏幕上如果出現(xiàn)OK則表明計(jì)算機(jī)與手機(jī)的連接成功,這時(shí)就可以輸入各類GSM AT指令了。
如:查詢手機(jī)廠家,輸入AT+CGMI=,屏幕顯示Siemens。
通常情況下,執(zhí)行測試命令A(yù)T+CMGS=?,如果返回OK,表明手機(jī)支持此指令。該指令的完整語法格式如下:
If PDU mode (+CMGF=0)+CMGS=PDU is given
如果短信息格式指令A(yù)T+CMGF返回的是0,則SMS格式為PDU模式,再執(zhí)行AT+CMGS=命令后,手機(jī)返回“>”符號(hào)并等待輸入,輸入PDU數(shù)據(jù)并以^Z或Esc鍵結(jié)束。
如果信息發(fā)送成功,則返回OK,并顯示信息號(hào):
+CMGS:
如果發(fā)送失敗,則返回如下信息:
+CMS ERROR:
PDU數(shù)據(jù)格式的分析
下面通過對存儲(chǔ)在手機(jī)中的待發(fā)信息的分析,來介紹SMS PDU的數(shù)據(jù)格式。首先,用手機(jī)寫一條短信息,發(fā)送手機(jī)號(hào)碼為13605696031,信息內(nèi)容為“Hello World!”。通過執(zhí)行AT+CMGL=2可以讀出此條信息。
操作過程如下(斜體字符為響應(yīng)信息,{}內(nèi)為注釋):
AT
OK
AT+CMGL=2 {讀未發(fā)短信息}
+CMGL: 1,2,,24 {1表示信息個(gè)數(shù),2表示未發(fā)信息,24表示信息總?cè)萘縸
08 91 683108501505F0 11 00 0B 81 3106656930F1 0000A7 0B E8329BFD06DDDF723619
OK 
下面分析這條信息:
08:短信息中心地址長度。
91:短信息中心號(hào)碼類型,91是TON/NPI。TON/NPI遵守International/E.164標(biāo)準(zhǔn),指在號(hào)碼前需加‘+’號(hào);此外還可有其他數(shù)值,但91最常用。
683108501505F0:短信息號(hào)碼,是所使用的服務(wù)中心地址。由于位置上略有處理,實(shí)際號(hào)碼應(yīng)為:8613805515500(字母F意指長度減1),這是作者所在地GSM短信息中心的號(hào)碼。
11:文件頭字節(jié)(header byte,是一種bitmask)。這里11指正常地發(fā)送短信息。
00:信息類型。
0B:被叫號(hào)碼長度。
81:被叫號(hào)碼類型。
3106656930F1:被叫號(hào)碼,也經(jīng)過了移位處理,實(shí)際號(hào)碼為13605696031。
0000A7:短信息編碼類型GSM Default Alphabet,如為中文則是000010。
0B:短信息長度。
E8329BFD06DDDF723619:短信息內(nèi)容“Hello World!”。
短信息的編碼方法及編程實(shí)現(xiàn)
下面我們介紹純英文和純中文的信息編碼方法。通過測試我們發(fā)現(xiàn),每條發(fā)送的短信息前面部分均相同,只是被叫號(hào)碼和短信息內(nèi)容有變化。
1.英文編碼
參見表2,設(shè)短信息內(nèi)容為“Hello World!”。缺省的GSM 字符集為7位編碼,可以簡單地理解為ASCII碼(ASCII值小于80Hex,因此,Bit8被忽略),依次將下一7位編碼的后幾位逐次移至前面,形成新的8位編碼,參見表2箭頭指示。需要注意的是第9行,移位計(jì)數(shù)已達(dá)7位,則直接將本編碼前加0。GSM并非支持所有的ASCII字符顯示。
表2 英文編碼的實(shí)現(xiàn)過程

下面是實(shí)現(xiàn)英文編碼的部分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 用于移位計(jì)數(shù)
i:=1;j:=0;
while ibegin
if i//數(shù)據(jù)變換
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);
//移位計(jì)數(shù)達(dá)到7位的特別處理
j:=(j+1) mod 7;if j=0 then inc(i);
end;
end;  
2.中文編碼
參見表3,設(shè)短信息內(nèi)容為“中文短信息”。中文短信息的實(shí)現(xiàn)較簡單,只需將??????的中文編碼轉(zhuǎn)換為代碼頁為CP936的Unicode編碼即可。
表3 中文編碼的實(shí)現(xiàn)過程

通過Delphi的WideString類型轉(zhuǎn)換,可以巧妙地實(shí)現(xiàn)??????到Unicode的編碼轉(zhuǎn)換(注意代碼頁和操作系統(tǒng)相關(guān)聯(lián))。下面是實(shí)現(xiàn)中文編碼的部分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轉(zhuǎn)換
FmtStr(t,‘%4.4X’,[cur]);
Result:=Result+t;
inc(i);
end;
end;
小 結(jié)
以上介紹了PDU格式的短信息編碼。建議英文信息長度不超過140個(gè)字符,中文信息不要超過54個(gè)漢字。如果使用能夠支持文本方式的手機(jī)進(jìn)行發(fā)送,實(shí)現(xiàn)起來更簡單。如發(fā)送“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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

PHP Tutorial
1488
72
Convert basic data types to strings using Java's String.valueOf() function Convert basic data types to strings using Java's String.valueOf() function Jul 24, 2023 pm 07:55 PM

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

How to convert char array to string How to convert char array to string Jun 09, 2023 am 10:04 AM

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

Use Java's String.replace() function to replace characters (strings) in a string Use Java's String.replace() function to replace characters (strings) in a string Jul 25, 2023 pm 05:16 PM

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

Use java's String.length() function to get the length of a string Use java's String.length() function to get the length of a string Jul 25, 2023 am 09:09 AM

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

Use Java's String.startsWith() function to determine whether a string starts with a specified prefix Use Java's String.startsWith() function to determine whether a string starts with a specified prefix Jul 25, 2023 pm 02:27 PM

Use Java's String.startsWith() function to determine whether a string starts with a specified prefix. In Java programming, we often need to process and determine strings. One common operation is to determine whether a string begins with a specified prefix. Java provides the startsWith() function of the String class, which can easily implement this function. String's startsWith() function The String class is the most commonly used class in Java

2w words detailed explanation String, yyds 2w words detailed explanation String, yyds Aug 24, 2023 pm 03:56 PM

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.

How to use java's String class How to use java's String class Apr 19, 2023 pm 01:19 PM

1. Understanding String1. String in JDK First, let’s take a look at the source code of the String class in the JDK. It implements many interfaces. You can see that the String class is modified by final. This means that the String class cannot be inherited and there is no subclass of String. class, so that all people using JDK use the same String class. If String is allowed to be inherited, everyone can extend String. Everyone uses different versions of String, and two different people Using the same method shows different results, which makes it impossible to develop the code. Inheritance and method overriding not only bring flexibility, but also cause many subclasses to behave differently.

Convert a string to lowercase using java's String.toLowerCase() function Convert a string to lowercase using java's String.toLowerCase() function Jul 24, 2023 pm 11:52 PM

The String.toLowerCase() function is a very useful and common string processing function in Java, which can convert a string to lowercase. In this article, we will introduce how to use this function and give some related code examples. First, let's take a look at the basic syntax of the String.toLowerCase() function. It doesn't have any parameters, just call it. Here is the sample code: Stringstr="Hel

See all articles