A method for splitting and reassembling long text messages in multiple encoding formats

By identifying and processing two bytes of Chinese characters as a unit during the SMS splitting process, combined with UCS2 encoding and protocol headers, the problem of garbled long SMS messages under multiple encoding formats is solved, correct splitting and reorganization is achieved, and the reduction of Save money on sending text messages.

CN118075701BActive Publication Date: 2024-10-22HAINAN SINOHOPE NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410224107.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-29
Publication Date
2024-10-22
Estimated Expiration
2044-02-29

AI Technical Summary

Technical Problem

When the existing technology handles long text messages containing multiple encoding formats, it cannot effectively split and reorganize them, causing two bytes of Chinese characters to be allocated to different text messages, resulting in garbled characters and affecting the user experience.

Method used

By defining the encoding format and length of the text message, the text message content is split into a custom byte object array, and Chinese characters are identified during the splitting process to ensure that the two bytes of each Chinese character are processed as a unit to avoid being allocated to different In text messages, UCS2 encoding and protocol headers are used to ensure orderly reception.

Benefits of technology

It achieves the correct splitting and reorganization of long text message content containing Chinese and English, reduces the number of text message splits, improves user experience, and reduces text message sending expenses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118075701B_ABST
    Figure CN118075701B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for processing the splitting and reassembling of long short messages in various encoding formats. Firstly, a judgment is made on whether the short message content contains a Chinese character string. If the Chinese character string is not contained, the byte length of each short message is defined as 160, otherwise it is defined as 140. The method can process various situations when the short message content contains all Chinese, all English, and a mixture of Chinese and English. A method for converting short message content compatible with multiple encoding formats into a byte stream and converting a byte stream into short message content is provided, and the method can be compatible with the splitting and reassembling of short message content in various encoding formats at the same time. The present invention provides an algorithm for reasonably allocating the number of split short messages, and can reduce the number of short message splits as much as possible while meeting the requirements of short message-related specifications and the readability of short messages, thereby achieving the effect of reducing the user's expenses on short message sending. The present invention is reasonably designed and worthy of vigorous promotion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of short message service (SMS), and in particular to a method for processing the splitting and reassembly of long short messages in multiple coding formats. Background Art

[0002] Short Message Service (SMS) is a widely used communication method, and its history can be traced back to the 1980s. With the development of mobile communication technology, SMS services have been widely used in many industries such as banking and securities, transportation, trade and logistics, administrative management and public services. SMS data is generated by the service provider and forwarded to the user's mobile terminal through the Internet connection to the industry gateway of the telecom operator. According to the relevant SMS specifications, the amount of information in a single mobile SMS is limited to 160 English characters, or 140 bytes of binary information, that is, 70 Chinese characters (including punctuation marks). If you need to send an extra-long SMS with a length of more than 140 bytes (70 Chinese characters), there are generally two solutions for processing: one is to divide the long SMS into multiple separate SMS and send it, so that the mobile phone will receive multiple SMS. The disadvantage is that the order in which the SMS arrives at the mobile phone may be out of order or lost, and the user needs to check all the SMS to know the full content of the SMS, which has a poor user experience; the other is to divide it into multiple SMS and send it through the UDHI mechanism, which is displayed as a long SMS combined in order at the receiving end, so that the user experience will be better.

[0003] There are many implementation methods based on the second solution on the market, but most of them only consider the scenario where the string is all English or all Chinese. If there are multiple character encoding formats in the text message content, for example, the text message content contains both Chinese and English, because for English letters, 7-bit ASCII encoding is generally used, which occupies 1 byte, while Chinese is 8-bit UCS-2 encoding, which takes up two bytes. In the process of splitting long text messages, since it is unknown whether the character belongs to Chinese or English, it is very likely that the two bytes corresponding to a Chinese character will be allocated to the previous text message, and the next byte will be allocated to the next text message. This will cause the text message display content to be garbled, thus affecting the user's experience of using text messages.

[0004] Therefore, a method for splitting and reassembling long text messages that can handle multiple encoding formats has become an urgent problem to be solved. Summary of the invention

[0005] The technical problem to be solved by the present invention is that there are many implementation methods based on the second solution on the market, but most of them only consider the scenario where the character string is all English or all Chinese. If there are multiple character encoding formats in the text message content, for example, the text message content contains both Chinese and English, because for English letters, 7-bit ASCII encoding is generally used, which occupies 1 byte, while Chinese is 8-bit UCS-2 encoding, which takes up two bytes. In the process of splitting long text messages, since it is not known whether the character belongs to Chinese or English, it is very likely that there will be two bytes corresponding to a Chinese character, and the first byte is allocated to the previous text message, and the next byte is allocated to the next text message. This will cause the text message display content to be garbled, thereby affecting the user's experience of using text messages.

[0006] In order to solve the above technical problems, the present invention provides a method for splitting and reassembling long text messages for processing a variety of encoding formats. The main feature of the method is that it can reasonably split and reassemble the long text message content containing Chinese and English, avoiding the garbled code problem caused in the process of splitting the long text message content. Ultimately, the receiving end can correctly receive the long text message content, and can reduce the number of text message splitting as much as possible while meeting the relevant text message specifications, thereby achieving the effect of reducing the user's expenses on text message sending.

[0007] The technical solution provided by the present invention is: a method for splitting and reassembling long text messages in various coding formats, and the method for splitting and reassembling long text messages in various coding formats is as follows:

[0008] Step 1: Define the encoding format and length of the SMS. First, judge the incoming SMS content and SMS signature to see if the SMS signature and content contain Chinese characters. If they do, the SMS encoding format is GB2312 encoding, and the length of each SMS is 140 bytes. Otherwise, the SMS encoding format is ASCII encoding, and the length of each SMS is 160 bytes.

[0009] Step 2: Call the method to split the SMS content into a custom byte object array, and pass in the SMS content and the corresponding encoding format as parameters; the custom byte object encapsulates the following three attributes: whether it is a Chinese character, a Chinese byte identifier, and a single byte data; the process of splitting the SMS content into an object array is mainly to perform a series of processing on the byte data corresponding to each character of the SMS content, and finally form a custom byte object array;

[0010] Step 3: Perform the operation of step 2 again on the SMS signature to split the SMS signature content into a custom byte object array;

[0011] Step 4: Calculate the maximum byte length that can be stored in the first message. Subtract the byte object length of the message signature from the message length to get the maximum byte length that can be stored in the first message.

[0012] Step 5: Determine whether it is a long message. First, define a flag to indicate whether it is a long message. The default value is False. If the maximum byte length that can be stored in the first message is less than the length of the custom byte array corresponding to the message content, it means that the message is a long message. Then set the flag to True. Then change the current message encoding format to UCS2 encoding, change the length of each message to 133 bytes, and then calculate the maximum length of the first message, that is, the maximum length of each message minus the length of the custom byte object array of the message signature. Finally, re-execute step 2 on the message content to obtain a new custom byte object array.

[0013] Step 6: Initialize a text message content array to store the contents of multiple text messages after splitting, and then initialize a text message byte data array to store the byte data of multiple text messages after splitting;

[0014] Step 7: If the indicator of whether it is a long message is False, that is, it is not a long message, then convert the custom byte array obtained in step 5 into a string, and then add the string to the SMS content array initialized in step 6, and then add the byte data in the custom byte array to the SMS byte data array initialized in step 6;

[0015] Step 8: If the indicator of whether it is a long message is True, it is a long message; then the long message splitting process is entered;

[0016] Step 9: Finally, return the two arrays defined in step 6 and the number of split SMS messages;

[0017] Step 10: Enter the SMS reassembly process. The SMS reassembly here uses the long SMS 7-byte method for processing. Three parameters need to be passed in, including the byte array of the current SMS, the total number of SMS in this batch, and the sequence number of the current SMS in this batch.

[0018] Furthermore, the Chinese byte identifier described in step 2 is used to indicate the start bit and end bit of the current byte. Since a single Chinese character corresponds to two bytes, the start bit 0 is used here to indicate the first byte corresponding to Chinese, and the end bit 1 is used to indicate the second byte corresponding to Chinese.

[0019] Furthermore, the reason why the length of each SMS is changed to 133 bytes in step 5 is that in long SMS, in order to ensure that the SMS recipient can receive the SMS in order and after the SMS is merged, a protocol header needs to be added to each SMS, and the protocol header is 7 bits; therefore, this requires that the encoding format of the SMS can only use UCS2 encoding, and UCS2 encoding has a total of 140 bytes, minus the 7 bytes of the protocol header, so the length of each SMS is 133 bytes.

[0020] Furthermore, the process of forming a custom byte object array described in step 2 mainly includes the following steps:

[0021] Step 2-1: Initialize an empty custom byte object array and judge the incoming SMS encoding format. Different SMS encoding formats enter the corresponding processing method. If it is US_ASCII encoding, the processing logic is relatively simple. Just split the SMS content into byte arrays according to the encoding format, then traverse the byte array and assign it to the byte data field of the custom byte object. If it is a Chinese character field, set it to False, and finally add it to the custom byte object array. For other encoding formats, continue with the following steps:

[0022] Step 2-2: Split the SMS content into character arrays;

[0023] Step 2-3: Traverse the character array and convert a single character into a byte array of the corresponding encoding format;

[0024] Step 2-4: Determine the length of the byte array. If the length is greater than 1, it is the byte array corresponding to Chinese characters; otherwise, it is the byte array corresponding to non-Chinese characters.

[0025] Step 2-5: If it is a byte array corresponding to Chinese characters, loop through the byte array, assemble the custom byte object data, set the field "Whether it is a Chinese character" to True, and put the currently traversed byte data into the single byte data field of the object. If the currently traversed byte is the first byte in the byte array, the Chinese byte identification field of the byte object is set to 0. If the currently traversed byte is the second byte in the byte array, the Chinese byte identification field of the byte object is set to 1. Finally, the custom byte object is added to the custom byte object array.

[0026] Step 2-6: If it is a byte array corresponding to non-Chinese characters, the custom byte object data is also assembled, the Chinese character field is set to False, and the currently traversed byte data is placed into the single byte data field of the object, and finally the custom byte object is added to the custom byte object array.

[0027] Furthermore, the process of converting the custom byte array into a string described in step 7 mainly includes the following steps:

[0028] Step 7-1: Get the input custom byte array and SMS encoding format parameters;

[0029] Step 7-2: Initialize a byte array with the same length as the passed custom byte array;

[0030] Step 7-3: Traverse the custom byte array object, take out the byte data in the custom byte array object, and convert it into a string according to the incoming SMS encoding format.

[0031] Furthermore, the long message splitting process described in step 8 mainly includes the following two steps:

[0032] Step 8-1: Add the first SMS content;

[0033] Step 8-2: Adding subsequent SMS content;

[0034] Step 8-1 is mainly the process of adding a long message to split the first piece of data. Because the first long message contains a message signature, it needs special processing. The addition of the first message content mainly includes the following steps:

[0035] Step 8-1-1: Define an index number for recording the location of the currently processed byte, initialize it to 0, and then initialize an array for storing the first SMS custom byte object;

[0036] Step 8-1-2: Add the first SMS data. First, loop through the custom byte object array. Each time the loop body is entered, the index number is increased by 1. When the index number starts to be equal to the maximum length of the first SMS, the loop stops. Then, each time the loop takes out the custom byte object corresponding to the current index number from the custom byte object array. If the current index number is not equal to the maximum length of the first SMS, the custom byte object corresponding to the current index number is added to the custom byte object array initialized in step 8-1. If the current index number is equal to the maximum length of the first SMS, that is, the last byte at the end of the first SMS has been processed, then determine whether the Chinese byte identification field corresponding to the byte object is 0. If not, add the byte object to the custom byte object array initialized in step 8-1. If it is 0, exit the loop. Finally, convert the array of the SMS custom byte objects defined in step 8-1 into a string and add it to the SMS content array defined in step 6. Add the byte data of the SMS custom byte object defined in step 8-1 to the SMS byte data array defined in step 6.

[0037] The main process of step 8-2 includes:

[0038] Step 8-2-1: Start adding each subsequent SMS data. First, define a moving cursor to define the position of the currently processed byte object in each subsequent SMS. The default value is 0 and the maximum value is the length of each SMS. Then define a custom byte object array for storing subsequent SMS data.

[0039] Step 8-2-2: Then continue to traverse the custom byte object array corresponding to the entire SMS content. Each time the loop body is entered, the cursor will be incremented by 1;

[0040] Step 8-2-3: Determine whether the modulo value of the moving cursor to the length of each SMS is equal to 0 or whether the current index number is equal to the last digit of the SMS content;

[0041] Step 8-2-4: If the conditions of step 8-2-3 are met, determine whether the currently processed custom byte object belongs to the start byte corresponding to the Chinese character, that is, whether the Chinese byte identification field is 0;

[0042] Step 8-2-5: If the identification field is 0, convert the custom byte object array storing the subsequent SMS data into a string and add it to the SMS content array defined in step 6, and take out the byte data from the custom byte object array storing the subsequent SMS data and add it to the SMS byte data array defined in step 6, then convert the custom byte object array storing the subsequent SMS data back to an empty array, add the currently processed custom byte object, and reset the moving cursor to 1;

[0043] Step 8-2-6: If the identification field is not 0, add the currently processed custom byte object to the custom byte object array storing the subsequent SMS data, then convert the custom byte object array storing the subsequent SMS data into a string and add it to the SMS content array defined in step 6, and take out the byte data from the custom byte object array storing the subsequent SMS data and add it to the SMS byte data array defined in step 6, then convert the custom byte object array storing the subsequent SMS data back to an empty array. Unlike step 8-2-5, the moving cursor is set to 0 here;

[0044] Step 8-2-7: When the condition of step 8-2-3 is not met, the currently processed custom byte object is added to the custom byte object array defined in step 8-2-1.

[0045] Furthermore, the SMS reassembly process described in step 10 includes the following steps:

[0046] Step 10-1: Initialize a byte array with a length of 7 and a byte array with a length of 7 plus the current SMS byte array. The byte array with a length of 7 is used to store the protocol header, and the other array is used to store the byte data after the protocol header is encapsulated in the original byte array.

[0047] Step 10-2: Assign values ​​to the byte array storing the protocol header, where the 0-4 bits of the byte array are default values. The first byte defaults to 0x06, indicating the length of the remaining protocol header; the second byte defaults to 0x08, which is specified in GSM03.40 specification 9.2.3.24.1, indicating that the length of the identification bit of the following batch of super-long text messages is 2; the third byte defaults to 0x04, which indicates the length of the remaining text message identification; the fourth and fifth bytes indicate the unique mark of this batch of text messages. In fact, after SME merges the messages, it records them again, so whether this mark is unique is not very important; the sixth byte is the number of this batch of text messages, and the seventh byte is the sequence number of the current text message in this batch of text messages;

[0048] Step 10-3: Add the byte array of the protocol header to the first 7 bits of the byte array defined in step 10-1, and then copy the original byte array to the back of the protocol header of the byte array defined in step 10-1, and return the byte data after the protocol header is encapsulated.

[0049] The advantages of the present invention over the prior art are as follows: the present invention provides a solution to the problem of splitting a long text message when the text message contains both Chinese and English, and identifies the two bytes corresponding to the Chinese characters, so that in the process of splitting the long text message, the two bytes of the Chinese characters will not be split into two text messages respectively, thereby avoiding the problem of garbled characters from the root;

[0050] The present invention provides a method for converting short message content compatible with multiple encoding formats into a byte stream and converting a byte stream into short message content, which can realize the splitting and reorganization of short messages in multiple encoding formats and improve the scalability of the program;

[0051] The present invention provides an algorithm for reasonably allocating the number of split SMS messages, which can reduce the number of SMS splits as much as possible while meeting the requirements of SMS-related specifications and SMS readability, thereby achieving the effect of reducing the user's expenses on SMS sending; the present invention is reasonably designed and worthy of vigorous promotion. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 The present invention is a process flow chart of a custom byte object array for implementing a method for processing long text message splitting and reassembly in multiple encoding formats.

[0053] Figure 2The present invention is a flowchart of adding the first text message content of a method for implementing the splitting and reassembly of long text messages in various encoding formats. DETAILED DESCRIPTION

[0054] The following is a further detailed description of a method for splitting and reassembling long text messages in various encoding formats according to the present invention in conjunction with the accompanying drawings.

[0055] Combined with Figure 1-2 , the present invention is introduced in detail.

[0056] A method for splitting and reassembling long text messages in various encoding formats is provided. The method for splitting and reassembling long text messages in various encoding formats is as follows:

[0057] Step 1: Define the encoding format and length of the SMS. First, judge the incoming SMS content and SMS signature to see if the SMS signature and content contain Chinese characters. If they do, the SMS encoding format is GB2312 encoding, and the length of each SMS is 140 bytes. Otherwise, the SMS encoding format is ASCII encoding, and the length of each SMS is 160 bytes.

[0058] Step 2: Call the method to split the SMS content into a custom byte object array, and pass in the SMS content and the corresponding encoding format as parameters; the custom byte object encapsulates the following three attributes: whether it is a Chinese character, a Chinese byte identifier, and a single byte data; the process of splitting the SMS content into an object array is mainly to perform a series of processing on the byte data corresponding to each character of the SMS content, and finally form a custom byte object array;

[0059] Step 3: Perform the operation of step 2 again on the SMS signature to split the SMS signature content into a custom byte object array;

[0060] Step 4: Calculate the maximum byte length that can be stored in the first message. Subtract the byte object length of the message signature from the message length to get the maximum byte length that can be stored in the first message.

[0061] Step 5: Determine whether it is a long message. First, define a flag to indicate whether it is a long message. The default value is False. If the maximum byte length that can be stored in the first message is less than the length of the custom byte array corresponding to the message content, it means that the message is a long message. Then set the flag to True. Then change the current message encoding format to UCS2 encoding, change the length of each message to 133 bytes, and then calculate the maximum length of the first message, that is, the maximum length of each message minus the length of the custom byte object array of the message signature. Finally, re-execute step 2 on the message content to obtain a new custom byte object array.

[0062] Step 6: Initialize a text message content array to store the contents of multiple text messages after splitting, and then initialize a text message byte data array to store the byte data of multiple text messages after splitting;

[0063] Step 7: If the indicator of whether it is a long message is False, that is, it is not a long message, then convert the custom byte array obtained in step 5 into a string, and then add the string to the SMS content array initialized in step 6, and then add the byte data in the custom byte array to the SMS byte data array initialized in step 6;

[0064] Step 8: If the indicator of whether it is a long message is True, it is a long message; then the long message splitting process is entered;

[0065] Step 9: Finally, return the two arrays defined in step 6 and the number of split SMS messages;

[0066] Step 10: Enter the SMS reassembly process. The SMS reassembly here uses the long SMS 7-byte method for processing. Three parameters need to be passed in, including the byte array of the current SMS, the total number of SMS in this batch, and the sequence number of the current SMS in this batch.

[0067] The Chinese byte identifier described in step 2 is used to indicate the start bit and end bit of the current byte. Since a single Chinese character corresponds to two bytes, the start bit 0 is used here to indicate the first byte corresponding to Chinese, and the end bit 1 is used to indicate the second byte corresponding to Chinese.

[0068] The reason why the length of each SMS is changed to 133 bytes in step 5 is that in long SMS, in order to ensure that the SMS recipient can receive the SMS in order and after the SMS is merged, a protocol header needs to be added to each SMS, and the protocol header is 7 bits; therefore, this requires that the encoding format of the SMS can only use UCS2 encoding, and UCS2 encoding has a total of 140 bytes, minus the 7 bytes of the protocol header, so the length of each SMS is 133 bytes.

[0069] The process of forming a custom byte object array described in step 2 mainly includes the following steps:

[0070] Step 2-1: Initialize an empty custom byte object array and judge the incoming SMS encoding format. Different SMS encoding formats enter the corresponding processing method. If it is US_ASCII encoding, the processing logic is relatively simple. Just split the SMS content into byte arrays according to the encoding format, then traverse the byte array and assign it to the byte data field of the custom byte object. If it is a Chinese character field, set it to False, and finally add it to the custom byte object array. For other encoding formats, continue with the following steps:

[0071] Step 2-2: Split the SMS content into character arrays;

[0072] Step 2-3: Traverse the character array and convert a single character into a byte array of the corresponding encoding format;

[0073] Step 2-4: Determine the length of the byte array. If the length is greater than 1, it is the byte array corresponding to Chinese characters; otherwise, it is the byte array corresponding to non-Chinese characters.

[0074] Step 2-5: If it is a byte array corresponding to Chinese characters, loop through the byte array, assemble the custom byte object data, set the field "Whether it is a Chinese character" to True, and put the currently traversed byte data into the single byte data field of the object. If the currently traversed byte is the first byte in the byte array, the Chinese byte identification field of the byte object is set to 0. If the currently traversed byte is the second byte in the byte array, the Chinese byte identification field of the byte object is set to 1. Finally, the custom byte object is added to the custom byte object array.

[0075] Step 2-6: If it is a byte array corresponding to non-Chinese characters, the custom byte object data is also assembled, the Chinese character field is set to False, and the currently traversed byte data is placed into the single byte data field of the object, and finally the custom byte object is added to the custom byte object array.

[0076] The process of converting the custom byte array to a string described in step 7 mainly includes the following steps:

[0077] Step 7-1: Get the input custom byte array and SMS encoding format parameters;

[0078] Step 7-2: Initialize a byte array with the same length as the passed custom byte array;

[0079] Step 7-3: Traverse the custom byte array object, take out the byte data in the custom byte array object, and convert it into a string according to the incoming SMS encoding format.

[0080] The long message splitting process described in step 8 mainly includes the following two steps:

[0081] Step 8-1: Add the first SMS content;

[0082] Step 8-2: Adding subsequent SMS content;

[0083] Step 8-1 is mainly the process of adding a long message to split the first piece of data. Because the first long message contains a message signature, it needs special processing. The addition of the first message content mainly includes the following steps:

[0084] Step 8-1-1: Define an index number for recording the location of the currently processed byte, initialize it to 0, and then initialize an array for storing the first SMS custom byte object;

[0085] Step 8-1-2: Add the first SMS data. First, loop through the custom byte object array. Each time the loop body is entered, the index number is increased by 1. When the index number starts to be equal to the maximum length of the first SMS, the loop stops. Then, each time the loop takes out the custom byte object corresponding to the current index number from the custom byte object array. If the current index number is not equal to the maximum length of the first SMS, the custom byte object corresponding to the current index number is added to the custom byte object array initialized in step 8-1. If the current index number is equal to the maximum length of the first SMS, that is, the last byte at the end of the first SMS has been processed, then determine whether the Chinese byte identification field corresponding to the byte object is 0. If not, add the byte object to the custom byte object array initialized in step 8-1. If it is 0, exit the loop. Finally, convert the array of the SMS custom byte objects defined in step 8-1 into a string and add it to the SMS content array defined in step 6. Add the byte data of the SMS custom byte object defined in step 8-1 to the SMS byte data array defined in step 6.

[0086] The main process of step 8-2 includes:

[0087] Step 8-2-1: Start adding each subsequent SMS data. First, define a moving cursor to define the position of the currently processed byte object in each subsequent SMS. The default value is 0 and the maximum value is the length of each SMS. Then define a custom byte object array for storing subsequent SMS data.

[0088] Step 8-2-2: Then continue to traverse the custom byte object array corresponding to the entire SMS content. Each time the loop body is entered, the cursor will be incremented by 1;

[0089] Step 8-2-3: Determine whether the modulo value of the moving cursor to the length of each SMS is equal to 0 or whether the current index number is equal to the last digit of the SMS content;

[0090] Step 8-2-4: If the conditions of step 8-2-3 are met, determine whether the currently processed custom byte object belongs to the start byte corresponding to the Chinese character, that is, whether the Chinese byte identification field is 0;

[0091] Step 8-2-5: If the identification field is 0, convert the custom byte object array storing the subsequent SMS data into a string and add it to the SMS content array defined in step 6, and take out the byte data from the custom byte object array storing the subsequent SMS data and add it to the SMS byte data array defined in step 6, then convert the custom byte object array storing the subsequent SMS data back to an empty array, add the currently processed custom byte object, and reset the moving cursor to 1;

[0092] Step 8-2-6: If the identification field is not 0, add the currently processed custom byte object to the custom byte object array storing the subsequent SMS data, then convert the custom byte object array storing the subsequent SMS data into a string and add it to the SMS content array defined in step 6, and take out the byte data from the custom byte object array storing the subsequent SMS data and add it to the SMS byte data array defined in step 6, then convert the custom byte object array storing the subsequent SMS data back to an empty array. Unlike step 8-2-5, the moving cursor is set to 0 here;

[0093] Step 8-2-7: When the condition of step 8-2-3 is not met, the currently processed custom byte object is added to the custom byte object array defined in step 8-2-1.

[0094] The SMS reassembly process described in step 10 includes the following steps:

[0095] Step 10-1: Initialize a byte array with a length of 7 and a byte array with a length of 7 plus the current SMS byte array. The byte array with a length of 7 is used to store the protocol header, and the other array is used to store the byte data after the protocol header is encapsulated in the original byte array.

[0096] Step 10-2: Assign values ​​to the byte array storing the protocol header, where the 0-4 bits of the byte array are default values. The first byte defaults to 0x06, indicating the length of the remaining protocol header; the second byte defaults to 0x08, which is specified in GSM03.40 specification 9.2.3.24.1, indicating that the length of the identification bit of the following batch of super-long text messages is 2; the third byte defaults to 0x04, which indicates the length of the remaining text message identification; the fourth and fifth bytes indicate the unique mark of this batch of text messages. In fact, after SME merges the messages, it records them again, so whether this mark is unique is not very important; the sixth byte is the number of this batch of text messages, and the seventh byte is the sequence number of the current text message in this batch of text messages;

[0097] Step 10-3: Add the byte array of the protocol header to the first 7 bits of the byte array defined in step 10-1, and then copy the original byte array to the back of the protocol header of the byte array defined in step 10-1, and return the byte data after the protocol header is encapsulated.

[0098] The specific implementation process of the method for splitting and reassembling long text messages in various encoding formats of the present invention is as follows: The method for splitting and reassembling long text messages in various encoding formats is as follows:

[0099] Step 1: Define the encoding format and length of the SMS. First, judge the incoming SMS content and SMS signature to see if the SMS signature and content contain Chinese characters. If they do, the SMS encoding format is GB2312 encoding, and the length of each SMS is 140 bytes. Otherwise, the SMS encoding format is ASCII encoding, and the length of each SMS is 160 bytes.

[0100] Step 2: Call the method to split the SMS content into a custom byte object array, and pass in the SMS content and the corresponding encoding format as parameters; the custom byte object encapsulates the following three attributes: whether it is a Chinese character, a Chinese byte identifier, and a single byte data; the process of splitting the SMS content into an object array is mainly to perform a series of processing on the byte data corresponding to each character of the SMS content, and finally form a custom byte object array;

[0101] Step 3: Perform the operation of step 2 again on the SMS signature to split the SMS signature content into a custom byte object array;

[0102] Step 4: Calculate the maximum byte length that can be stored in the first message. Subtract the byte object length of the message signature from the message length to get the maximum byte length that can be stored in the first message.

[0103] Step 5: Determine whether it is a long message. First, define a flag to indicate whether it is a long message. The default value is False. If the maximum byte length that can be stored in the first message is less than the length of the custom byte array corresponding to the message content, it means that the message is a long message. Then set the flag to True. Then change the current message encoding format to UCS2 encoding, change the length of each message to 133 bytes, and then calculate the maximum length of the first message, that is, the maximum length of each message minus the length of the custom byte object array of the message signature. Finally, re-execute step 2 on the message content to obtain a new custom byte object array.

[0104] Step 6: Initialize a text message content array to store the contents of multiple text messages after splitting, and then initialize a text message byte data array to store the byte data of multiple text messages after splitting;

[0105] Step 7: If the indicator of whether it is a long message is False, that is, it is not a long message, then convert the custom byte array obtained in step 5 into a string, and then add the string to the SMS content array initialized in step 6, and then add the byte data in the custom byte array to the SMS byte data array initialized in step 6;

[0106] Step 8: If the indicator of whether it is a long message is True, it is a long message; then the long message splitting process is entered;

[0107] Step 9: Finally, return the two arrays defined in step 6 and the number of split SMS messages;

[0108] Step 10: Enter the SMS reassembly process. The SMS reassembly here uses the long SMS 7-byte method for processing. Three parameters need to be passed in, including the byte array of the current SMS, the total number of SMS in this batch, and the sequence number of the current SMS in this batch.

[0109] In the embodiment of the present invention, the text message content is first judged whether it contains a Chinese character string. If it does not contain a Chinese character string, the byte length of each text message is defined as 160, otherwise it is defined as 140. This can handle various situations where the text message content contains all Chinese, all English, or a mixture of Chinese and English.

[0110] In an embodiment of the present invention, a method for converting SMS content compatible with multiple encoding formats into a byte stream and converting a byte stream into SMS content is provided, which can simultaneously be compatible with the splitting and reassembly of SMS content in multiple encoding formats;

[0111] In the embodiment of the present invention, a custom byte object is encapsulated, which includes whether it is a Chinese character and a Chinese byte identifier, and a method for splitting the SMS content into the custom byte object is provided, so that when the SMS is subsequently split, it is convenient to know which byte belongs to the English character and which byte belongs to the Chinese character, thereby avoiding the garbled SMS content caused by splitting the two bytes of the same Chinese character into two SMS messages respectively during the splitting;

[0112] In an embodiment of the present invention, two different processing flows are adopted for the first SMS data and the subsequent SMS data, because the first SMS data needs to save the SMS signature information, while the subsequent SMS data does not need to save the SMS signature. However, the two processing flows are similar in that the byte data at the SMS splitting point will be judged to determine whether it belongs to the first byte of the Chinese character. If it is the first byte, it will not be placed separately in the previous SMS, but in the next SMS. After the algorithm is optimized, the number of SMS splits can be reduced as much as possible while meeting the requirements of SMS-related specifications and SMS readability, thereby achieving the effect of reducing the user's expenses on SMS sending.

[0113] The present invention provides a solution to the problem of splitting a long text message when the text message contains both Chinese and English. The two bytes corresponding to the Chinese characters are marked, so that in the process of splitting the long text message, the two bytes of the Chinese characters will not be split into two text messages respectively, thereby avoiding the problem of garbled characters from the root.

[0114] The present invention provides a method for converting short message content compatible with multiple encoding formats into a byte stream and converting a byte stream into short message content, which can realize the splitting and reorganization of short messages in multiple encoding formats and improve the scalability of the program;

[0115] The present invention provides an algorithm for reasonably allocating the number of split SMS messages, which can reduce the number of SMS splits as much as possible while meeting the requirements of SMS-related specifications and SMS readability, thereby achieving the effect of reducing the user's expenses on SMS sending; the present invention is reasonably designed and worthy of vigorous promotion.

[0116] The present invention and its implementation methods are described above, and such description is not restrictive. In short, if ordinary technicians in the field are inspired by it, without departing from the purpose of the invention, they can design structures and embodiments similar to the technical solution without creativity, which should all fall within the protection scope of the present invention.

Claims

1. A method for splitting and reassembling long text messages in various encoding formats, characterized in that: The method for processing the splitting and reassembly of long text messages in various encoding formats is as follows: Step 1: Define the encoding format and length of the SMS. First, judge the incoming SMS content and SMS signature to see if the SMS signature and content contain Chinese characters. If they do, the SMS encoding format is GB2312 encoding, and the length of each SMS is 140 bytes. Otherwise, the SMS encoding format is ASCII encoding, and the length of each SMS is 160 bytes. Step 2: Call the method to split the SMS content into a custom byte object array, and pass in the SMS content and the corresponding encoding format as parameters; the custom byte object encapsulates the following three attributes: whether it is a Chinese character, a Chinese byte identifier, and a single byte data; the process of splitting the SMS content into an object array is mainly to perform a series of processing on the byte data corresponding to each character of the SMS content, and finally form a custom byte object array; Step 3: Perform the operation of step 2 again on the SMS signature to split the SMS signature content into a custom byte object array; Step 4: Calculate the maximum byte length that can be stored in the first message. Subtract the byte object length of the message signature from the message length to get the maximum byte length that can be stored in the first message. Step 5: Determine whether it is a long message. First, define a flag to indicate whether it is a long message. The default value is False. If the maximum byte length that can be stored in the first message is less than the length of the custom byte array corresponding to the message content, it means that the message is a long message. Then set the flag to True. Then change the current message encoding format to UCS2 encoding, change the length of each message to 133 bytes, and then calculate the maximum length of the first message, that is, the maximum length of each message minus the length of the custom byte object array of the message signature. Finally, re-execute step 2 on the message content to obtain a new custom byte object array. Step 6: Initialize a text message content array to store the contents of multiple text messages after splitting, and then initialize a text message byte data array to store the byte data of multiple text messages after splitting; Step 7: If the indicator of whether it is a long message is False, that is, it is not a long message, then convert the custom byte array obtained in step 5 into a string, and then add the string to the SMS content array initialized in step 6, and then add the byte data in the custom byte array to the SMS byte data array initialized in step 6; Step 8: If the indicator of whether it is a long message is True, it is a long message; then the long message splitting process is entered; Step 9: Finally, return the two arrays defined in step 6 and the number of split SMS messages; Step 10: Enter the SMS reassembly process. The SMS reassembly here uses the long SMS 7-byte method for processing. Three parameters need to be passed in, including the byte array of the current SMS, the total number of SMS in this batch, and the sequence number of the current SMS in this batch.

2. According to claim 1, a method for splitting and reassembling long text messages in multiple encoding formats, characterized in that: The Chinese byte identifier described in step 2 is used to indicate the start bit and end bit of the current byte. Since a single Chinese character corresponds to two bytes, the start bit 0 is used here to indicate the first byte corresponding to Chinese, and the end bit 1 is used to indicate the second byte corresponding to Chinese.

3. The method for splitting and reassembling long text messages in various encoding formats according to claim 1, characterized in that: The reason why the length of each SMS is changed to 133 bytes in step 5 is that in long SMS, in order to ensure that the SMS recipient can receive the SMS in order and after the SMS is merged, a protocol header needs to be added to each SMS, and the protocol header is 7 bits; therefore, this requires that the encoding format of the SMS can only use UCS2 encoding, and UCS2 encoding has a total of 140 bytes, minus the 7 bytes of the protocol header, so the length of each SMS is 133 bytes.

4. The method for splitting and reassembling long text messages in various encoding formats according to claim 2, characterized in that: The process of forming a custom byte object array described in step 2 mainly includes the following steps: Step 2-1: Initialize an empty custom byte object array and judge the incoming SMS encoding format. Different SMS encoding formats enter the corresponding processing method. If it is US_ASCII encoding, the processing logic is relatively simple. Just split the SMS content into byte arrays according to the encoding format, then traverse the byte array and assign it to the byte data field of the custom byte object. If it is a Chinese character field, set it to False, and finally add it to the custom byte object array. For other encoding formats, continue with the following steps: Step 2-2: Split the SMS content into character arrays; Step 2-3: Traverse the character array and convert a single character into a byte array of the corresponding encoding format; Step 2-4: Determine the length of the byte array. If the length is greater than 1, it is the byte array corresponding to Chinese characters; otherwise, it is the byte array corresponding to non-Chinese characters. Step 2-5: If it is a byte array corresponding to Chinese characters, loop through the byte array, assemble the custom byte object data, set the field "Whether it is a Chinese character" to True, and put the currently traversed byte data into the single byte data field of the object. If the currently traversed byte is the first byte in the byte array, the Chinese byte identification field of the byte object is set to 0. If the currently traversed byte is the second byte in the byte array, the Chinese byte identification field of the byte object is set to 1. Finally, the custom byte object is added to the custom byte object array. Step 2-6: If it is a byte array corresponding to non-Chinese characters, the custom byte object data is also assembled, the Chinese character field is set to False, and the currently traversed byte data is placed into the single byte data field of the object, and finally the custom byte object is added to the custom byte object array.

5. The method for splitting and reassembling long text messages in various encoding formats according to claim 1, characterized in that: The process of converting the custom byte array to a string described in step 7 mainly includes the following steps: Step 7-1: Get the input custom byte array and SMS encoding format parameters; Step 7-2: Initialize a byte array with the same length as the passed custom byte array; Step 7-3: Traverse the custom byte array object, take out the byte data in the custom byte array object, and convert it into a string according to the incoming SMS encoding format.

6. The method for splitting and reassembling long text messages in various encoding formats according to claim 1, characterized in that: The long message splitting process described in step 8 mainly includes the following two steps: Step 8-1: Add the first SMS content; Step 8-2: Adding subsequent SMS content; Step 8-1 is mainly the process of adding a long message to split the first piece of data. Because the first long message contains a message signature, it needs special processing. The addition of the first message content mainly includes the following steps: Step 8-1-1: Define an index number for recording the location of the currently processed byte, initialize it to 0, and then initialize an array for storing the first SMS custom byte object; Step 8-1-2: Add the first SMS data. First, loop through the custom byte object array. Each time the loop body is entered, the index number is increased by 1. When the index number starts to be equal to the maximum length of the first SMS, the loop stops. Then, each time the loop takes out the custom byte object corresponding to the current index number from the custom byte object array. If the current index number is not equal to the maximum length of the first SMS, the custom byte object corresponding to the current index number is added to the custom byte object array initialized in step 8-1. If the current index number is equal to the maximum length of the first SMS, that is, the last byte at the end of the first SMS has been processed, then determine whether the Chinese byte identification field corresponding to the byte object is 0. If not, add the byte object to the custom byte object array initialized in step 8-1. If it is 0, exit the loop. Finally, convert the array of the SMS custom byte objects defined in step 8-1 into a string and add it to the SMS content array defined in step 6. Add the byte data of the SMS custom byte object defined in step 8-1 to the SMS byte data array defined in step 6. The main process of step 8-2 includes: Step 8-2-1: Start adding each subsequent SMS data. First, define a moving cursor to define the position of the currently processed byte object in each subsequent SMS. The default value is 0 and the maximum value is the length of each SMS. Then define a custom byte object array for storing subsequent SMS data. Step 8-2-2: Then continue to traverse the custom byte object array corresponding to the entire SMS content. Each time the loop body is entered, the cursor will be incremented by 1; Step 8-2-3: Determine whether the modulo value of the moving cursor to the length of each SMS is equal to 0 or whether the current index number is equal to the last digit of the SMS content; Step 8-2-4: If the conditions of step 8-2-3 are met, determine whether the currently processed custom byte object belongs to the start byte corresponding to the Chinese character, that is, whether the Chinese byte identification field is 0; Step 8-2-5: If the identification field is 0, convert the custom byte object array storing the subsequent SMS data into a string and add it to the SMS content array defined in step 6, and take out the byte data from the custom byte object array storing the subsequent SMS data and add it to the SMS byte data array defined in step 6, then convert the custom byte object array storing the subsequent SMS data back to an empty array, add the currently processed custom byte object, and reset the moving cursor to 1; Step 8-2-6: If the identification field is not 0, add the currently processed custom byte object to the custom byte object array storing the subsequent SMS data, then convert the custom byte object array storing the subsequent SMS data into a string and add it to the SMS content array defined in step 6, and take out the byte data from the custom byte object array storing the subsequent SMS data and add it to the SMS byte data array defined in step 6, then convert the custom byte object array storing the subsequent SMS data back to an empty array. Unlike step 8-2-5, the moving cursor is set to 0 here; Step 8-2-7: When the condition of step 8-2-3 is not met, the currently processed custom byte object is added to the custom byte object array defined in step 8-2-1.

7. The method for splitting and reassembling long text messages in various encoding formats according to claim 1, characterized in that: The SMS reassembly process described in step 10 includes the following steps: Step 10-1: Initialize a byte array with a length of 7 and a byte array with a length of 7 plus the current SMS byte array. The byte array with a length of 7 is used to store the protocol header, and the other array is used to store the byte data after the protocol header is encapsulated in the original byte array. Step 10-2: Assign values ​​to the byte array storing the protocol header, where the 0-4 bits of the byte array are default values. The first byte defaults to 0x06, indicating the length of the remaining protocol header; the second byte defaults to 0x08, which is specified in GSM03.40 specification 9.2.3.24.1, indicating that the length of the identification bit of the following batch of super-long text messages is 2; the third byte defaults to 0x04, which indicates the length of the remaining text message identification; the fourth and fifth bytes indicate the unique identifier of this batch of text messages; the sixth byte is the number of this batch of text messages, and the seventh byte is the sequence number of the current text message in this batch of text messages; Step 10-3: Add the byte array of the protocol header to the first 7 bits of the byte array defined in step 10-1, and then copy the original byte array to the back of the protocol header of the byte array defined in step 10-1, and return the byte data after the protocol header is encapsulated.