import json, subprocess, tempfile, os from urllib.parse import quote def q(text): return quote(text, encoding='utf-8') def kw(value): # 这次必须带参数名前缀:漏了前缀就成了「有键无值」的参数,筛选被忽略、返回全量第一页, # 上一轮就是因此把 上海(id=100) 当成临时城市给禁用了 return 'params%5Bkeyword%5D=' + q(value) def api(method, url, body=None): cmd = ['sh', '.tmp_api.sh', method, url] tmp = None if body is not None: fd, tmp = tempfile.mkstemp(suffix='.json') with os.fdopen(fd, 'w', encoding='utf-8') as f: json.dump(body, f, ensure_ascii=False) cmd.append(tmp) out = subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8').stdout.strip() if tmp: os.remove(tmp) try: return json.loads(out) except Exception: return {'raw': out[:300]} def res(tag, r): print(f'{tag}: code={r.get("code")} msg={r.get("msg")}') rows = api('GET', '/account/user/city/list?pageNum=1&pageSize=50')['rows'] print('当前禁用中的城市:', [(x['id'], x['province'], x['cityName']) for x in rows if x['status'] == '1']) print('当前临时城市:', [(x['id'], x['province'], x['cityName']) for x in rows if x['cityName'] == '临时测试市']) print() print('=== 修复 ===') sh = [x for x in rows if x['cityName'] == '上海'] if sh and sh[0]['status'] == '1': res('R1 恢复上海为正常', api('PUT', '/account/user/city/changeStatus', {'id': sh[0]['id'], 'status': '0'})) else: print('R1 上海本就是正常,无需恢复') tmp_city = [x for x in rows if x['cityName'] == '临时测试市'] if tmp_city: tid = tmp_city[0]['id'] print('R2 删除临时城市 id =', tid, end=' -> ') res('', api('DELETE', '/account/user/city/%s' % tid)) else: print('R2 无临时城市') print() print('=== 复核 ===') rows = api('GET', '/account/user/city/list?pageNum=1&pageSize=50')['rows'] print('R3 城市(未删除)total =', len(rows), '(期望 28)') print('R4 启用城市数 =', sum(1 for x in rows if x['status'] == '0'), '| 禁用城市 =', [(x['cityName'], x['id']) for x in rows if x['status'] == '1'], '(期望 禁用只有 西宁/127)') print('R5 上海 =', [(x['id'], x['status']) for x in rows if x['cityName'] == '上海'], '(期望 0=正常)') c = api('GET', '/account/user/company/list?pageNum=1&pageSize=50') print('R6 公司档案 total =', c['total'], '| 最大档案号 =', max(x['id'] for x in c['rows']), '(期望 7 / 33140006)') opts = api('GET', '/account/user/city/options')['data'] print('R7 options 启用城市数 =', len(opts), '(期望 27)')