python http服务器

异网短信模拟器,太高并发支持不好。

# -*- coding: utf-8 -*-
#本地模拟器
import random

from flask import Flask
import json

app = Flask(__name__)


@app.route('/',methods=['post'])
def woVerificationCode():
	msgId = str(random.randint(1000000000000, 15287919338179215534922))
	re = {"code": "0", "description": "", "msgId": msgId}
	#time.sleep(6)
	result=json.dumps(re)
	httpcode=200
	respheaders={
		'Content-Type':    'application/json; charset=UTF-8',
		"Content-Length":  len(result),
		'Server':          'Apache-Coyote/1.1'
	}
	return result, httpcode, respheaders

@app.route('/login',methods=['get'])
def woVerificationCode2():

	result2={"resultMsg":"处理中","resultCode":"022","orderId":"4"}
	#time.sleep(6)
	result=json.dumps(result2)
	httpcode=200
	respheaders={
		'Content-Type':    'application/json; charset=UTF-8',
		"Content-Length":  len(result),
		'Server':          'Apache-Coyote/1.1'
	}
	return result, httpcode, respheaders
if __name__ == '__main__':
	#0.0.0.0表示监听所有地址,这样就可以在本机访问了
	app.run(host="0.0.0.0",port=5000, debug=True,threaded=True)
根据监听端口的不同访问目录,处理不同的业务。

猜你喜欢

转载自blog.csdn.net/witto_sdy/article/details/81035174