常州大学/企业微信/电费查询脚本

企业微信 电费查询脚本

博客 https://blog.nanshaobit.top/106

仓库

其他所有接口汇总:

https://blog.nanshaobit.top/104

account 为用户id, 可抓包获得(随机也可,存在就行)。
aid 应用id 两个校区不同

获取楼栋接口

  • url: http://wxxy.cczu.edu.cn/wechat/callinterface/queryElecBuilding.html
  • method: POST
  • data: 具体见 main.py:get_area()
{
    "aid": area["aid"], // 应用ID
    "account": "100000", // 用户id
    "area": area["value"] // 区域
}
  • 数据位置: 返回数据 json["buildingtab"]

查询电费接口

  • url: http://wxxy.cczu.edu.cn/wechat/callinterface/queryElecRoomInfo.html
  • method: POST
  • data: 具体见 main.py:get_data()
// 除有注释外,其他内容正常情况不需要修改。
{
    "aid": area["aid"], // 应用ID
    "account": "100000", // 用户id
    "area": area["value"] // 区域
    
    "building": str(building), // 楼栋信息
    "floor": '{"floorid":"","floor":""}', // 置空
    "room": f'{{"room":"","roomid":"{rid}"}}'} // 房间id
}
  • 数据位置: 返回数据 json["errmsg"] (可能出错, 提示也在该位置,需要判断)

脚本

依赖库: requests

[脚本]main.py 使用控制台输入方式交互, 可修改为其他方式交互 如:web、机器人

# @DateTime     : 2021-10-20 12:57
# @Author       : Nanshao
# @Mail         : Nanshao@n-s.fun
# @Description  :

import requests

"""
所有输入 均未做容错处理。
"""

s = requests.Session()


def get_input_from_ls(ls, k):
    for i, v in enumerate(ls):
        print(f"{i}: -> {v[k]}")

    return ls[int(input("输入序号即可:"))]


def get_area():
    ls_area = [{
        "title": "西太湖校区(1-9号楼)",
        "value": '{"area":"西太湖校区","areaname":"西太湖校区"}',
        "aid": "0030000000002501"
    }, {
        "title": "武进校区及西太湖校区(10-11号楼)",
        "value": '{"area":"武进校区","areaname":"武进校区"}',
        "aid": "0030000000002502"
    }]
    return get_input_from_ls(ls_area, "title")


def get_building(area):
    with s.post("http://wxxy.cczu.edu.cn/wechat/callinterface/queryElecBuilding.html", data={
        "aid": area["aid"],
        "account": "100000",
        "area": area["value"],
    }) as resp:
        ls_building = resp.json().get("buildingtab")
        return get_input_from_ls(ls_building, "building")


def get_data(area, building, rid):
    print("query")
    print("*" * 50)
    url = "http://wxxy.cczu.edu.cn/wechat/callinterface/queryElecRoomInfo.html"
    with s.post(url, data={
        "aid": area["aid"],
        "account": "100000",
        "area": area["value"],
        "building": str(building),
        "floor": '{"floorid":"","floor":""}',
        "room": f'{{"room":"","roomid":"{rid}"}}'}) as resp:
        print(resp.json())
        print(resp.json()["errmsg"])


def query():
    area = get_area()
    building = get_building(area)
    rid = input("输入房间号:")
    get_data(area, building, rid)


if __name__ == '__main__':
    query()
posted @ 2021-10-20 14:28  楠少科技  阅读(190)  评论(0编辑  收藏  举报