首页 » 技术分享 » python对接60码平台

python对接60码平台

 

60码平台是一个短信接码平台,(http://www.60ma.net/)

看了下文档,

发现没有python对接的

那就自己写。

话不多说直接上代码:

import re,requests,time
import hashlib
userName ="xxx"
passWord ="xxx"
Docks = "xxxxxx"
hl = hashlib.md5()
hl.update(passWord.encode(encoding='utf-8'))
def login():#登录
    url = "http://sms.60ma.net/loginuser?cmd=login&encode=utf-8&dtype=json&username=" +userName +"&password="+hl.hexdigest()
    print(url)
    page = requests.get(url).text
    print(page)
    dic = eval(page)
    print(dic)
    return dic["Return"]["UserID"],dic["Return"]["UserKey"]
# 获取手机号
def getNumber(UserID,UserKey,Docks):
    url = "http://sms.60ma.net/newsmssrv?cmd=gettelnum&encode=utf-8&dtype=json&userid="+UserID+"&userkey="+UserKey+"&docks="+Docks
    page = requests.get(url).text
    print(page)
    dic = eval(page)
    print(dic)
    return dic["Return"]["Telnum"]
#获取短信
def getCode(UserID,UserKey,Docks,Telnum):
    url = "http://sms.60ma.net/newsmssrv?cmd=getsms&encode=utf-8&dtype=json&userid=" + UserID + "&userkey=" + UserKey + "&dockcode=" + Docks + "&telnum=" + Telnum
    page = requests.get(url).text
    code = "null"
    while True:
        if page.find("成功")!= -1:
            dic = eval(page.replace("\r","").replace("\n","").replace("\r\n",""))
            code = re.findall("([0-9]{6})",dic["Return"]["SmsContent"])[0]
            break
        time.sleep(5)
        page = requests.get(url).text
        print(page)
    return code
def delNumber(UserID,UserKey,Docks,Telnum):#释放手机号
    url = "http://sms.60ma.net/newsmssrv?cmd=freetelnum&encode=utf-8&dtype=json&userid="+UserID+"&userkey="+UserKey+"&docks="+Docks+"&telnum="+Telnum
    requests.get(url)


if __name__=="__main__":
    UserID,UserKey = login()
    print(UserID,UserKey)
    Telnum = getNumber(UserID,UserKey,Docks)
    print(Telnum)
    code  = getCode(UserID, UserKey, Docks, Telnum)
    print("验证码:",code)
    delNumber(UserID, UserKey, Docks, Telnum)

userName是注册60码的账号

passWord是注册60码的密码

先login()拿到用户的UserID和UserKey

然后获取手机号,其次获取验证码。

Docks是你要取得平台的项目号。

欢迎进(Q)群,帮你解决问题

 

转载自原文链接, 如需删除请联系管理员。

原文链接:python对接60码平台,转载请注明来源!

0