def gen_tpdu(ref, to, text, empty): if empty: text = "" TPPID = 0x40 if empty else 0 #TP-PID = 40 ==> short message type 0 TPDCS = 0xc3 if empty else 0 #TP-DCS = c3 ==> disable "other message indicator" and discard message return [SMS_SUBMIT.create(None, to, text, tp_pid=TPPID, tp_dcs=TPDCS).toPDU()]
def create_empty_pdu(header, phone, tail): phone = bi_revert_sting(phone) tpdu = [] pdu = SMS_SUBMIT.create('', phone, '') tpdu.append(header) tpdu.append(phone) tpdu.append(tail) #短信内容长度接短信内容unicode编码 length = pdu.tp_udl tpdu.append('%02X' % length) tpdu.append(''.join(['%02X' % ord(c) for c in pdu.tp_ud])) data = ''.join(tpdu) return (length, data)
def at_cmgs(smsc_raw, sender, receiver, text_msg): tokens = smsc_raw.split(",") smsc_no = tokens[0][2:-1] type_int = int(tokens[1]) pdu = SMS_SUBMIT.create(sender, receiver, text_msg) tpdu = pdu.toPDU() test = '01' + '00' + '{:02X}'.format(len(receiver[1:])) + '91' + ''.join( swap_hex(split(receiver[1:], 2, 'F'))) + '0000' + '%02X' % pdu.tp_udl + ''.join( ['%02X' % ord(c) for c in pdu.tp_ud]) print(test) tmp = '{:02X}'.format(type_int) + ''.join(swap_hex(split(smsc_no, 2, 'F'))) smsc_len = int(len(tmp) / 2) smsc = '{:02X}'.format(smsc_len) + tmp tpdu_len = int(len(test) / 2) return (tpdu_len, smsc, test)
from smspdu import SMS_SUBMIT from gsm0338 import Codec pdu = SMS_SUBMIT.create('sender', 'recipient', 'hello, world') t = pdu.toPDU() print(t) ret = SMS_SUBMIT.fromPDU(1, t, 'sender') print(ret)