python 调用接口发短信
调用接口发送短信
此处接口是移动云nas
""" Create_of_date:2020-03-08 Author:nod description: 调用移动云mas接口 exchange_date author exchange """ from flask import request, Flask, jsonify import hashlib import base64 import json import requests url=‘http://112.XXX.XXX:5992/sms/norsubmit‘ app = Flask(__name__) app.config[‘JSON_AS_ASCII‘] = False @app.route(‘/test‘, methods=[‘POST‘]) def post_Data(): #接收传递进来的mobiles & content参数 如果第三方接口调用参数指定了这里mobile content可以进行修改 mobile = request.form[‘mobile‘] content = request.form[‘content‘] #传递进来的参数构造字典 dicinfo = {‘mobiles‘: mobile, ‘content‘: content} mob=dicinfo[‘mobiles‘] con=dicinfo[‘content‘] #取值转换成字符串---> md5 小写 mes=‘常州市XX****cz**1cz****3‘+mob+con+‘439I8a8aR‘ m=hashlib.md5() m.update(mes.encode(‘utf-8‘)) md5_info=m.hexdigest() #构造转换前的base64字典 base64_before={"ecName":"常州市XXX院1", "apId":"czxx1", "secretKey":"czxxxx23", "mobiles":mob, "content":con, "sign":"43xxxaR", "addSerial":"", "mac":md5_info} #字典转json base_json=json.dumps(base64_before) base64_end=base64.b64encode(base_json.encode(‘utf-8‘)) #### 去除byte byte_end=str(base64_end,‘utf-8‘) print(byte_end) req = requests.post(url, data=byte_end) return jsonify(dicinfo), 201 if __name__ == ‘__main__‘: app.run(debug=False, host=‘127.0.0.1‘, port=9999)
相关推荐
浪味仙 2020-08-17
pythonjw 2020-11-17
hedongli 2020-09-01
IT兄弟团 2020-08-01
凉白开 2020-07-19
kjh00abc 2020-07-08
Skyline 2020-06-28
苦咖啡flask 2020-06-18
万物weiyi 2020-06-16
半纸药笺 2020-06-14
chenhaimeimeng 2020-06-13
JF0 2020-06-13
逍遥友 2020-06-02
kyelu 2020-06-02
northwindx 2020-05-31
tengyuan 2020-05-30
singer 2020-05-30
GreatZhou 2020-05-28
coolhty 2020-05-20