利用PYTHON快速MOCK你的接口

以下是PYTHON源码,已调试通过,根据注释替换你需要的值就可以。

from fastapi import FastAPI  #需要在PY环境安装fastapi包
import uvicorn  #需要在PY环境安装uvicorn包

app = FastAPI() #别管,你照抄下来就是

@app.get('/config/pushlist') #括号里写URL路径,app.get表示这是个可以接收get请求的方法
def getJson_config_pushlist(): #起一个你喜欢的方法名
    res_config_pushlist = {"response":{"pushAddr":"18.16.29.19:5111","udpAddr":"18.16.29.19:5111","alternativePush":[]},"responseHeader":{"status":200,"version":"1.0"}}#表达式右侧写你希望返回的内容
    return res_config_pushlist # 方法的出口,通过这里返回你前面定义的变量值


@app.get('/contact/getlist')
def getJson_contact_getlist():
    res_contact_getlist = {"response":{"mtime":1648132939062,"ver":67,"friends":["C9OYzmSno","C9O43mUBm"],"friends_account":["9U5yVReYqaiIlDw8/P/gcZ8B1J0XB42eubfpWxvViyRnVPPdeGNVx23qrOs","mjzLYXuM7fk9sYkOYP3MNfBMAMf6bbl/smJzF9uB13FnmHNGzn+ccjXdmeAM"],"friends_h_id":["EpXPXVJ06b4uv5ankoDmHIKckSHKIvpAXlp/xc9z+otwOxZw20T1Omuy0Yd","NzWK/b+CFJdal0ILkSX001rz9KT6I4zZy1lFcLh1B8X7KMrvl3FOJuWvofmn"],"friends_h_sip_number":["dD2YhCDNesXAV1BGJ0+VyzRjskBGQs9O6pG4wq8=","p69+kgmHSrHkkMl1nXjYbmIakK8J1YZnipQM6Zn="]},"responseHeader":{"status":200,"version":"1.0"}}
    return res_contact_getlist


@app.post('/company/status') #括号里写URL路径,app.post表示这是个可以接收post请求的方法
def postJson_company_status():
    res_company_status = {"response":[{"uid":8521927667225596,"hid":"C9OYzmSno","mobile":{"status":0,"enterpriseId":"UAE-971-1000000"},"desktop":{"status":0,"enterpriseId":"UAE-971-1000000"},"os":"windows"}],"responseHeader":{"status":200,"version":"1.0"}}
    return res_company_status


@app.post('/hwm/getMeetings')
def postJson_hwm_getMeetings():
    res_hwm_getMeetings = {"response":{"data":[],"count":0},"responseHeader":{"status":200,"version":"1.0"}}
    return res_hwm_getMeetings


if __name__ == '__main__':
    uvicorn.run(app=app,
                host="127.0.0.1", #这里写你的MOCK的IP地址,知道机器地址就写实际地址,本地调试就写127.0.0.1
                port=8080, #这里写你的MOCK发布出来的端口号,喜欢什么写什么,别和已有的端口冲突就行
                workers=1)

你可能感兴趣的:(利用PYTHON快速MOCK你的接口)