You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.3 KiB

5 days ago
import requests, json, sys
BASE='http://localhost:8080'
UID='739564171091247104'
s=requests.Session()
def tok():
r=s.get(f'{BASE}/api/auth/debug/token',params={'userId':UID},timeout=15)
return r.json()['data']
T=tok()
H={'Authorization':'Bearer '+T}
def g(path,**pp):
return s.get(BASE+path,headers=H,params=pp,timeout=15)
def p(path,**data):
hh=dict(H); hh['Content-Type']='application/x-www-form-urlencoded'
return s.post(BASE+path,headers=hh,data=data,timeout=15)
out={}
# 1) dict enabled-list: customer_role + customer_type
for grp in ['customer_role','customer_type']:
r=g('/api/dict/item/enabled-list',groupCode=grp)
j=r.json()
items=j.get('data') or []
out[f'dict:{grp}']={'http':r.status_code,'success':j.get('success'),'count':len(items),
'names':[i.get('name') for i in items]}
# 2) candidate customer search (need an oppId). find one via page
r=p('/api/opportunity/page',viewType='MINE',pageNum=1,pageSize=5)
recs=(r.json().get('data') or {}).get('content') or []
oppId=recs[0].get('id') if recs else None
out['pick_opp']={'http':r.status_code,'oppId':oppId,'total':(r.json().get('data') or {}).get('total')}
if oppId:
r=p('/api/opportunity/customer/search',oppId=oppId,keyword='',pageNum=1,pageSize=5)
j=r.json(); data=j.get('data') or {}
cand=data.get('content') or data.get('records') or []
out['customer_search']={'http':r.status_code,'success':j.get('success'),'count':len(cand),
'sample':cand[:2]}
# 3) contacts stub for first candidate (or any customerId)
cid=cand[0].get('customerId') if cand else 1
r=g('/api/opportunity/customer/contacts', customerId=cid)
j=r.json()
out['contacts_stub']={'http':r.status_code,'success':j.get('success'),
'data_is_list':isinstance(j.get('data'),list),'count':len(j.get('data') or [])}
# contacts for a non-existent customer -> should still be empty list, not error
r=g('/api/opportunity/customer/contacts', customerId=999999999)
j=r.json()
out['contacts_nonexistent']={'http':r.status_code,'success':j.get('success'),
'data_is_list':isinstance(j.get('data'),list),'count':len(j.get('data') or [])}
print(json.dumps(out,ensure_ascii=False,indent=2))