/// <summary> /// 解析号码 /// </summary> /// <param name="number"></param> /// <returns></returns> private static string DecodeNumber(string number) { StringBuilder sb = new StringBuilder(); StringReader reader = new StringReader(number, 0); string str = reader.NextString(2); if (str == "91") { sb.Append("+"); } while (reader.HasNext()) { char one = reader.NextChar(); char two = reader.NextChar(); sb.Append(two); sb.Append(one); } if (sb[sb.Length - 1] == 'F' || sb[sb.Length - 1] == 'f') { sb.Remove(sb.Length - 1, 1); } return sb.ToString(); }
/// <summary> /// 解析时间 /// </summary> /// <param name="pduReader"></param> /// <returns></returns> private static string ParseCenterTime(StringReader pduReader) { //14 位长日期格式 return pduReader.NextString(14); }
/// <summary> /// 解析用户数据 /// </summary> /// <param name="pduReader"></param> /// <returns></returns> private static string ParseUserData(StringReader pduReader) { //获得信息内容长度 int length = Int32.Parse(pduReader.NextString(2), NumberStyles.HexNumber); string userData = pduReader.NextString(length * 2); return userData; }
/// <summary> /// 解析数据编码 /// </summary> /// <param name="pduReader"></param> /// <returns></returns> private static string ParseCharsetEncoding(StringReader pduReader) { return pduReader.NextString(2); }
/// <summary> /// 解析协议 /// </summary> /// <param name="pduReader"></param> /// <returns></returns> private static string ParseProtocol(StringReader pduReader) { return pduReader.NextString(2); }
/// <summary> /// 解析发送方号码 /// </summary> /// <param name="pduReader"></param> /// <returns></returns> private static string ParseSenderNumber(StringReader pduReader) { string str = pduReader.NextString(2); if (str == "FF" || str == "00") { str = pduReader.NextString(2); } int length = Int32.Parse(str, NumberStyles.HexNumber); if (length % 2 != 0) { //如果长度不是偶数位 添加 'F' 补齐 length += 1; } //取回区域类型 '91'.length = 2 return pduReader.NextString(2 + length); }
/// <summary> /// 解析 FirstOctet /// </summary> /// <param name="pduReader"></param> /// <returns></returns> private static string ParseFirstOctet(StringReader pduReader) { return pduReader.NextString(2); }
/// <summary> /// 解析短信中心号码 /// </summary> /// <param name="pduReader">PDUReader 读取器</param> /// <returns>短信中心号码(编码)</returns> private static string ParseCenterNumber(StringReader pduReader) { string str = pduReader.NextString(2); //取回地址信息长度(str * 2 = length) int length = Int32.Parse(str, NumberStyles.HexNumber) * 2; //偏移 2 //读取号码 pduReader.Offset = 2; //短信中心号码 *编码 return pduReader.NextString(length); }