我使用GSMComm Lib开发SMS Gateway应用程序。阅读消息时
SmsDeliverPdu data = (SmsDeliverPdu)pdu;
Output("Message: " + data.UserDataText);
它包含特殊字符(使用BlackBerry手机的自动文本发送) 并抛出System.ArgumentException类型的异常发生并被捕获
以下是日志文件:
Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The value 105 is not part of the 7-bit default alphabet extension table.
Source : PDUConverter
Help link :
ParamName :
Data : System.Collections.ListDictionaryInternal
TargetSite : Char SevenBitExtensionToChar(Byte)
Stack Trace : at GsmComm.PduConverter.TextDataConverter.SevenBitExtensionToChar(Byte b)
at GsmComm.PduConverter.TextDataConverter.SevenBitToString(String s, Boolean throwExceptions)
at GsmComm.PduConverter.PduParts.DecodeText(Byte[] userData, Byte dataCodingScheme)
at GsmComm.PduConverter.SmsPdu.get_UserDataText()
at GTMP.PresentationTier.Win.SMSGateway.frmSMSGateway.ShowMessage(SmsPdu pdu)
at GTMP.PresentationTier.Win.SMSGateway.frmSMSGateway.ReadMessage()
at GTMP.PresentationTier.Win.SMSGateway.frmSMSGateway.frmSMSGateway_Load(Object sender, EventArgs e)
如何解决这个案子?
答案 0 :(得分:1)
解决。 我使用这个正则表达式检查字符串是否包含7位字符集:
"^[A-Za-z0-9 \\r\\n@£$¥èéùìòÇØøÅå\u0394_\u03A6\u0393\u039B\u03A9\u03A0\u03A8\u03A3\u0398\u039EÆæßÉ!\"#$%&'()*+,\\-./:;<=>?¡ÄÖÑܧ¿äöñüà^{}\\\\\\[~\\]|\u20AC]*$";
代码:
public static bool IsInputContainNonGSM7BitCharacterSet(string value)
{
string GSM_7_BIT_CHARACTER_SET = " @£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞ^{}\\[~]|€ÆæßÉ!\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà";
char letter = default(char);
for (int i = 0; i < value.Length; i++)
{
letter = value[i];
if (GSM_7_BIT_CHARACTER_SET.IndexOf(letter) == -1)
{
return true;
}
}
}
答案 1 :(得分:-1)
我没有使用data.UserDataText
,而是使用了
TextDataConverter.SevenBitToString(TextDataConverter.OctetsToSeptetsStr((message.Data as SmsDeliverPdu).UserData), false)