计算SMSC的方法 (附带Py小工具)

早上小青蛙 @hexchain 发不了短信找俺要SMSC号码, 于是…嗯…
于是…步骤就用代码里的注释描述算了, 直接上代码:

#!/usr/bin/env python2
#coding:utf-8
import sys

# 获取短信中心号码
if len(sys.argv) > 1:
    orig = sys.argv[1]
else:
    print "输入短信中心号码:",
    orig = raw_input()
    
# 去掉+号
if orig[0] == "+":
    orig = orig[1:]

# 不是偶数在后面加F
if len(orig) % 2 == 1:
    orig = orig + "F"

# 把奇位和偶位互换
orig = "".join(["".join(x) for x in zip(orig[1::2],orig[::2])])

# 在号码前加91(国际化)+字符长度/2
orig = "91" + orig
orig = "%02d" % (len(orig)/2) + orig

print orig

参考资料: http://read.pudn.com/downloads179/sourcecode/embed/835292/new/SMSTABLE.h__.htm

3 thoughts on “计算SMSC的方法 (附带Py小工具)”

Leave a Reply

Your email address will not be published. Required fields are marked *

QR Code Business Card