一、swagger-ui中
二、python中调用接口,出现的问题:
解决办法:
import requests # 还款试算接口 ur1='http://10.253.43.83:8399/repayment/order/repaymentTrial' headers = {'Content-Type':'application/json','Accept': '*/*'} Value = { "accountNo": "ZH20220202071059", "channelNo": "0014", "endPeriod": 1, "isSettle": "0", "loanCode": "JKSQ20220208048780DK", "payCode": "5815042292859904", "period": 1, "repayWay": "2" } r = requests.post(url=ur1,json=Value,headers=headers) repones = r.text repones2 =r.json() print('1',r.json()) print('2',r.status_code) print('3',r.headers)
三、json中文输出的问题,输出的不是中文:
修改后
import requests import json # 还款试算接口 ur1='http://10.253.43.83:8399/repayment/order/repaymentTrial' headers = {'Content-Type':'application/json','Accept': '*/*'} Value = { "accountNo": "ZH20220202071059", "channelNo": "0014", "endPeriod": 1, "isSettle": "0", "loanCode": "JKSQ20220208048780DK", "payCode": "5815042292859904", "period": 1, "repayWay": "2" } r = requests.post(url=ur1,json=Value,headers=headers) repones = r.text repones2 =r.json() repones3=json.dumps(repones2,indent=4,ensure_ascii=False) print('1',repones3) print('2',r.status_code) print('3',r.headers)
四、添加金额的判断逻辑
import requests import json import pymysql ''' # 还款试算接口 ''' ur1='http://10.253.43.83:8399/repayment/order/repaymentTrial' headers = {'Content-Type':'application/json','Accept': '*/*'} Value = { "accountNo": "ZH20220202071059", "channelNo": "0014", "endPeriod": 1, "isSettle": "0", "loanCode": "JKSQ20220208048780DK", "payCode": "5815042292859904", "period": 1, "repayWay": "2" } r = requests.post(url=ur1,json=Value,headers=headers) repones2 =r.json() repones3=json.dumps(repones2,indent=4,ensure_ascii=False)#ensure_ascii=False将返回的json汉字化 print('1',repones3) print('2',r.status_code) print('3',r.headers) repones = r.text print('11',repones) print(type(repones))#<class 'str'> s=repones s_dic=eval(s) print('s_dic的类型为:',type(s_dic))#自发一串转换为字典 print('s_dic:',s_dic) payBen=s_dic['data']['payBen']#打印字典中的某个值 payIni=s_dic['data']['payIni']#打印字典中的某个值 payFee=s_dic['data']['payFee']#打印字典中的某个值 payMoney=s_dic['data']['payMoney']#打印字典中的某个值 orderId=s_dic['data']['orderId']#打印字典中的某个值 print('payBen:',payBen,'类型为:',type(payBen)) print('payIni:',payIni,'类型为:',type(payIni)) print('payFee:',payFee,'类型为:',type(payFee)) print('payMoney:',payMoney,'类型为:',type(payMoney)) print('orderId:',orderId,'类型为:',type(orderId)) #判断payMoney的值是否为payBen、payIni、payFee的和 payMoneytotal=payBen+payIni+payFee print(payMoneytotal) payMoneytotal2=round(payMoneytotal,2)#取小数点后两位数 print(payMoneytotal2) if payMoneytotal2==payMoney: print('payMoney的值,PASS:','payBen+payIni+payFee=payMoney') else: print('呵呵哒...')