阿里雲短信驗證碼API接口


阿里雲短信驗證碼接口網站:https://market.aliyun.com/products/57124001/cmapi00037170.html?spm=5176.2020520132.101.20.1e047218HnYIPU#sku=yuncode3117000001

請求參數:

 

 

 隨機四位數驗證碼源碼

import urllib, sys
import ssl
import urllib.request as urllib2
import random

def messageAPI(phone):
    host = 'https://dfsns.market.alicloudapi.com'
    path = '/data/send_sms'
    method = 'POST'
    appcode = '這里填你的code,購買后會有'
    querys = ''
    bodys = {}
    url = host + path
    # 隨機生成四位數驗證碼
    code=random.randint(1000,9999)
    bodys['content'] = '''code:{},expire_at:5'''.format(code)
    bodys['phone_number'] = phone
    bodys['template_id'] = '''TPL_0001'''
    post_data = urllib.parse.urlencode(bodys).encode("utf-8")
    request = urllib2.Request(url, post_data)
    request.add_header('Authorization', 'APPCODE ' + appcode)
    # //根據API的要求,定義相對應的Content-Type
    request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    response = urllib2.urlopen(request, context=ctx)
    content = response.read()
    if (content):
        print("發送手機號為:{},驗證碼為:{}".format(phone,code))
        return phone,code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM