记第一次使用网易云短信api

# coding: utf-8
import time
import random
import string
import hashlib
import requests

def send_sms():
    api = 'https://api.netease.im/sms/sendcode.action'
    AppKey = '********'
    ctime = str(time.time())
    Nonce = ''.join(random.sample(string.ascii_letters + string.digits, 20))
    Sumstr = '*******'+Nonce+ctime
    sha = hashlib.sha1(Sumstr.encode())
    CheckSum = sha.hexdigest()
    headers = {
        "Content-Type":"application/x-www-form-urlencoded",
        "charset":"utf-8",
        "AppKey":AppKey,
        "CurTime":ctime,
        "Nonce":Nonce,
        "CheckSum":CheckSum
    }
    data = {"mobile":'*******'}
    r = requests.post(url=api, headers=headers,data=data)
    print(r)

if __name__ == '__main__':
    send_sms()

你可能感兴趣的:(记第一次使用网易云短信api)