python調(diào)用API接口實(shí)現(xiàn)登陸短信驗(yàn)證
API說(shuō)明
調(diào)用地址:http://yzxyzm.market.alicloudapi.com/yzx/verifySms
請(qǐng)求方式:POST
返回類型:JSON
請(qǐng)求參數(shù)(Query)
名稱 | 類型 | 是否必選 | 描述 |
---|---|---|---|
phone | STRING | 必選 | 需要發(fā)送的手機(jī)號(hào)碼 |
templateId | STRING | 必選 | 模板id,聯(lián)系客服人員申請(qǐng)成功的模板ID |
variable | STRING | 可選 | 模板中變量參數(shù)名,參數(shù)值有多個(gè)時(shí)使用","隔開(kāi),例如"num:1234,money:888" |
正常返回示例
{ "return_code": "00000", "order_id": "YZXV15........825" }
失敗返回示例
{ " return_code": "10000" }
錯(cuò)誤碼定義
錯(cuò)誤碼 | 錯(cuò)誤信息 | 描述 |
---|---|---|
10000 | 參數(shù)異常 | 必傳參數(shù)有空值() |
python實(shí)現(xiàn)
創(chuàng)建GetSms.py
import requests import json def send_single_sms(apikey, code, mobile): # 定義函數(shù)傳遞三個(gè)值分別為API密匙,驗(yàn)證碼,手機(jī)號(hào) url_part1 = "http://yzxyzm.market.alicloudapi.com/yzx/verifySms?" url_part2 = "phone={0}&templateId=TP18040314&variable=code%3A{1}".format(mobile,code) url = url_part1 + url_part2 #傳遞參數(shù)手機(jī)號(hào)及驗(yàn)證碼,拼接兩部分鏈接, headers = { 'Authorization': 'APPCODE ' + apikey } #使用headers添加報(bào)頭 res = requests.post(url, headers=headers) re_json = json.loads(res.text) return re_json if __name__ == "__main__": res = send_single_sms("75e8e13sc0454bf594974a15cc2f4caf", "12344","13500031234") #參數(shù):API密匙,驗(yàn)證碼,手機(jī)號(hào) print(res) code = res['return_code'] print(type(code)) print(code) if code == '00000': print("發(fā)送成功") else: print("發(fā)送失敗: {}".format(code))
CURL實(shí)現(xiàn)
curl -i -X POST 'http://yzxyzm.market.alicloudapi.com/yzx/verifySms?phone=135XXXX9999&templateId=TP18040314&variable=code%3A1234' -H 'Authorization:APPCODE 你自己的AppCode'
到此這篇關(guān)于python調(diào)用API接口實(shí)現(xiàn)登陸短信驗(yàn)證的文章就介紹到這了,更多相關(guān)python實(shí)現(xiàn)登陸短信驗(yàn)證實(shí)例內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
linux下python使用sendmail發(fā)送郵件
這篇文章主要為大家詳細(xì)介紹了linux下python使用sendmail發(fā)送郵件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05python/golang實(shí)現(xiàn)循環(huán)鏈表的示例代碼
這篇文章主要介紹了python/golang如何實(shí)現(xiàn)循環(huán)鏈表,幫助大家更好的理解和學(xué)習(xí)循環(huán)鏈表的實(shí)現(xiàn)方法,感興趣的朋友可以了解下2020-09-09Pytorch數(shù)據(jù)讀取與預(yù)處理該如何實(shí)現(xiàn)
這篇文章主要介紹了Pytorch數(shù)據(jù)讀取與預(yù)處理該如何實(shí)現(xiàn),幫助大家更好的理解和學(xué)習(xí)使用Pytorch,感興趣的朋友可以了解下2021-03-03python 類對(duì)象和實(shí)例對(duì)象動(dòng)態(tài)添加方法(分享)
下面小編就為大家分享一篇python 類對(duì)象和實(shí)例對(duì)象動(dòng)態(tài)添加方法。具有很的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12Python標(biāo)準(zhǔn)庫(kù)datetime?date模塊的詳細(xì)介紹
這篇文章主要介紹了Python標(biāo)準(zhǔn)庫(kù)datetime?date模塊的詳細(xì)介紹,datetime是Python提供的操作日期和時(shí)間的標(biāo)準(zhǔn)庫(kù),主要有datetime.date模塊、datetime.time模塊及datetime.datetime模塊2022-07-07基于Python實(shí)現(xiàn)通過(guò)微信搜索功能查看誰(shuí)把你刪除了
這篇文章主要介紹了基于Python實(shí)現(xiàn)微信搜索查看誰(shuí)把你刪除了的相關(guān)資料,需要的朋友可以參考下2016-01-01