python 调用接口发短信

Lexan 2020-03-08

调用接口发送短信

此处接口是移动云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)

相关推荐