3.3 接口开发案例讲解
本节主题:3.3 接口开发案例讲解
课程讲师:Charlie
观看地址:点我进入
1 本节要点
- 上期作业讲解
- 接口开发案例(数据处理)
- 接口开发案例(函数调研)
2 课前准备
无
3 课程内容
3.1 接口开发案例(数据处理)
from flask import Flask, request
import json
app = Flask(__name__)
@app.route('/test/', methods=['POST']) #因为简道云只接收POST请求
def hello_world():
alldata = json.loads(request.data)
x = alldata['data']['x']
y = alldata['data']['y']
z = alldata['data']['z']
if x==10:
print(x*y*z)
return 'success',200
if __name__ == '__main__':
app.run(host='0.0.0.0',port=3100)
3.2 接口开发案例(函数调用)
from flask import Flask, request
import json
import requests
import threading
app = Flask(__name__)
def voice_message(mobile,tpl):
url = "http://yuyintz.market.alicloudapi.com/ts/voiceNotifySms?mobile=" + mobile + "&tpl_id=" + tpl
payload = {}
headers = {
'Authorization': 'APPCODE c467a7fd7cf4400a8ac6b6b43504fa75'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text)
@app.route('/test/', methods=['POST']) #因为简道云只接收POST请求
def hello_world():
alldata = json.loads(request.data)
x = alldata['data']['x']
y = alldata['data']['y']
threading.Thread(target=voice_message,args=(x,y,)).start()
return 'success',200
if __name__ == '__main__':
app.run(host='0.0.0.0',port=3100)