Please take a look at the http://dev.csdn.net/article/49/49606.shtm before reading this article
This article only describes what I understood wrong when I checked the web page for Engineering. I hope it will help you.
1: Each text message can contain 160 English letters or 70 Chinese characters.
The command to send 160 English letters is
At + cmgs = 175
175 = 15 + 160; 15 is the length of the Information header, and 160 is the number of characters
At + cmgs = 175
> Logging
+ Cmgs: 132 OK
The command for sending 70 characters is
At + cmgs = 155
155 = 15 + 140 140 = 70*2
At + cmgs = 155
> Logging
+ Cmgs: 137 OK
2: Calculation of A0 and 8c in 2017a7a0 and 0008a78c
This bit is calculated based on the length of the string without encode, but not the length after encode.
When the character is ASCII, use strlen directly.
Use strlen * 2 when the character is Unicode
The previous incorrect calculation is that the length after encode is divided by 2
3: The modified send () function
After the following modifications, you can support Chinese characters.
Long cgsmphone: Send (char * PNO, char * PMSG, bool breport, bool bhandfree, bool basyn)
{
If (isopened () = false) Return (-4 );
If (PNO = NULL) Return (-5 );
If (PMSG = NULL) Return (-5 );
If (m_strsmcenter.isempty () Return (-1 );
Char szsendbuf [1024] = {0 };
Char sztemp [20] = {0 };
Char * preceivedata = NULL;
Int Len = 0;
Bool iswidechar = true;
Iswidechar = ischinese (PMSG );
If (iswidechar & strlen (PMSG)> 140) // control the length of Chinese Characters
Memset (PMSG + 140, '/0', 1 );
Apsaradb for memset (szsendbuf, '/0', 1024 );
Char * P = numberencode (char *) (lpctstr) m_strsmcenter); // Short Message Center
Len = 0;
Memcpy (szsendbuf, "0891", 4); // 91 stands for international and ISDN/telephone numbers, and there is no need to select other values
Len + = 4;
If (strncmp (P, "68", 2 )! = 0) {// not starting with 86
If (strlen (p )! = 12) Return (-5); // The Short Message Center settings are incorrect.
Memcpy (szsendbuf + Len, "68", 2); // Add 86
Len + = 2;
}
Else {
If (strlen (p )! = 14) Return (-5); // starts with 86
}
Memcpy (szsendbuf + Len, P, strlen (p); // Add a short message center
Len + = strlen (P );
Delete [] P;
If (strncmp (PNO, "86", 2 )! = 0) // not starting with 86
{Memcpy (szsendbuf + Len, "11000d9168", 10 );
Len + = 10;
}
Else
{Memcpy (szsendbuf + Len, "11000d91", 8 );
Len + = 8;
}
P = numberencode (PNO );
Memcpy (szsendbuf + Len, P, strlen (p ));
Len + = strlen (P );
Delete [] P;
If (bhandfree) {// 00 indicates the tp_pid value, 18 or 08 indicates tp_dcs, and A7 indicates that the short message is saved for 24 hours.
If (iswidechar) {memcpy (szsendbuf + Len, "0018a7", 6 );}
Else {memcpy (szsendbuf + Len, "0010a7", 6 );}
}
Else {
If (iswidechar) {memcpy (szsendbuf + Len, "0008a7", 6 );}
Else {memcpy (szsendbuf + Len, "2017a7", 6 );}
}
Len + = 6;
DWORD dw;
If (iswidechar) {DW = pduencodechn (PMSG, P );}
Else {DW = pduencodeeng (PMSG, P)/2 ;}
If (iswidechar) sprintf (sztemp, "%. 2x", DW );
Else {sprintf (sztemp, "%. 2x", strlen (PMSG ));}
Memcpy (szsendbuf + Len, sztemp, 2 );
Len + = 2;
Memcpy (szsendbuf + Len, P, DW * 2 );
Len + = DW * 2;
Delete [] P;
/*
Char AA [5];
Memset (AA, '/0', 5 );
Sprintf (AA, "% d", DW );
MessageBox (null, AA, "DW", mb_ OK );
*/
Char cmd [20];
Memset (CMD, '/0', 20 );
Sprintf (CMD, "At + cmgs = % d/R/N", 15 + strlen (PMSG ));
Isposting = true;
Submit (CMD, strlen (CMD ));
Sleep (20 );
Szsendbuf [Len] = 0x1a; // 1A indicates that the short message ends.
Len + = 1;
Memcpy (szsendbuf + Len, "/R", 1 );
Len + = 1;
Submit (szsendbuf, Len );
Isposting = false;
Return 0;
}