一、还款试算、还款接口,

1、只传入参数loan_Code

2、还款接口参数化以下:

"loanCode": loanCode1,
"orderId": orderId1,
"payMoney": payMoneytotal2,

import requests
import json
import pymysql loanCode1="JKSQ20220610049084DK"
'''
# 还款试算接口
'''
ur1='http://10.253.43.83:8399/repayment/order/repaymentTrial'
headers = {'Content-Type':'application/json','Accept': '*/*'}
Value = {
"accountNo": "ZH20220202071059",
"channelNo": "",
"endPeriod": 1,
"isSettle": "",
"loanCode": loanCode1,
"payCode": "",
"period": 1,
"repayWay": ""
}
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('',repones3)
print('',r.status_code)
print('',r.headers) repones = r.text
print('',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']#打印字典中的某个值
orderId1=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:',orderId1,'类型为:',type(orderId1)) #判断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('呵呵哒...') # 连接数据判断接口返回的值是否和数据表中的一致
mydb = pymysql.connect(host="172.31.20.2", port=3306, user="root", passwd="sjroot", db="user", charset='utf8')
mycursor = mydb.cursor()
sql = "select must_amt from repay.t_external_borrow_repay where loan_code = 'JKSQ20220208048780DK' and period=1"
mycursor.execute(sql)
myresult =mycursor.fetchall()
for x in myresult:
# print(x,type(x))
print(x[0]) sql2 = "select must_amt from repay.t_external_borrow_fee_asset where loan_code = 'JKSQ20220208048780DK' and period=1"
mycursor.execute(sql2)
myresult =mycursor.fetchall()
for x in myresult:
# print(x,type(x))
print(x[0]) '''
还款接口
'''
ur12='http://10.253.43.83:8399/repayment/order/repaymentRequest'
headers2 = {'Content-Type':'application/json','Accept': '*/*'}
Value2 = {
"accountNo": "ZH20220202071059",
"accountType": "capital",
"channelNo": "",
"endPeriod": 1,
"loanCode": loanCode1,
"orderId": orderId1,
"payCode": "",
"payMoney": payMoneytotal2,
"period": 1,
"repayWay": "",
"settleStatus": ""
}
r = requests.post(url=ur12,json=Value2,headers=headers2)
repones2 =r.json()
repones3=json.dumps(repones2,indent=4,ensure_ascii=False)#ensure_ascii=False将返回的json汉字化
print('',repones3)
print('',r.status_code)
print('',r.headers) repones = r.text
print('',repones)
print(type(repones))#<class 'str'>

 

运行结果:

D:\Python3\python.exe E:/python/20190221接口/还款试算与还款接口.py
1 {
    "msg": "成功",
    "data": {
        "loanCode": "JKSQ20220610049084DK",
        "payBen": 1146.34,
        "payIni": 49.59,
        "payFee": 245.03,
        "payMoney": 1440.96,
        "payTime": "2022-07-10 09:01:55",
        "period": 1,
        "endPeriod": 1,
        "repayWay": "2",
        "settleStatus": "4",
        "payCode": "5815042292859904",
        "accountNo": "ZH20220202071059",
        "channelNo": "0014",
        "orderId": "101002_2022071009015429687561453",
        "feeList": [
            {
                "feeName": "jlgA首金服务费(期收)",
                "feeCode": "FC20181214163415006",
                "feeMoney": 245.03
            }
        ]
    },
    "code": 20000
}
2 200
3 {'X-Application-Context': 'repayment-asset-order-web:pre:8399', 'X-Request-Id': 'x-9d45dfbc-90e1-4950-9dc4-e121a68aa30f', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Sun, 10 Jul 2022 01:01:55 GMT'}
11 {"msg":"成功","data":{"loanCode":"JKSQ20220610049084DK","payBen":1146.34,"payIni":49.59,"payFee":245.03,"payMoney":1440.96,"payTime":"2022-07-10 09:01:55","period":1,"endPeriod":1,"repayWay":"2","settleStatus":"4","payCode":"5815042292859904","accountNo":"ZH20220202071059","channelNo":"0014","orderId":"101002_2022071009015429687561453","feeList":[{"feeName":"jlgA首金服务费(期收)","feeCode":"FC20181214163415006","feeMoney":245.03}]},"code":20000}
<class 'str'>
s_dic的类型为: <class 'dict'>
s_dic: {'msg': '成功', 'data': {'loanCode': 'JKSQ20220610049084DK', 'payBen': 1146.34, 'payIni': 49.59, 'payFee': 245.03, 'payMoney': 1440.96, 'payTime': '2022-07-10 09:01:55', 'period': 1, 'endPeriod': 1, 'repayWay': '2', 'settleStatus': '4', 'payCode': '5815042292859904', 'accountNo': 'ZH20220202071059', 'channelNo': '0014', 'orderId': '101002_2022071009015429687561453', 'feeList': [{'feeName': 'jlgA首金服务费(期收)', 'feeCode': 'FC20181214163415006', 'feeMoney': 245.03}]}, 'code': 20000}
payBen: 1146.34 类型为: <class 'float'>
payIni: 49.59 类型为: <class 'float'>
payFee: 245.03 类型为: <class 'float'>
payMoney: 1440.96 类型为: <class 'float'>
orderId: 101002_2022071009015429687561453 类型为: <class 'str'>
1440.9599999999998
1440.96
payMoney的值,PASS: payBen+payIni+payFee=payMoney
1146.34
49.59
245.0300
11 {
    "msg": "成功",
    "data": {
        "msg": "还款申请已提交",
        "code": 20000
    },
    "code": 20000
}
22 200
33 {'X-Application-Context': 'repayment-asset-order-web:pre:8399', 'X-Request-Id': 'x-09755d11-ebd3-4c4a-ae83-7c68d06e70ce', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Sun, 10 Jul 2022 01:01:57 GMT'}
11 {"msg":"成功","data":{"msg":"还款申请已提交","code":20000},"code":20000}
<class 'str'>

Process finished with exit code 0

二、优化

解决只传loan_code调用试算接口、还款接口

需要参数化:

"accountNo": "ZH20220202071059",
"payCode": "5815042292859904",
这两个值从"select user_id,account_no from repay.t_asset_core where loan_code =‘JKSQ20220710049184DK’取出

以下调试取出accountNo、payCode

import requests
import json
import pymysql
loanCode1='JKSQ20220710049184DK'
'''
# 还款试算接口
''' mydb = pymysql.connect(host="172.31.20.2", port=3306, user="root", passwd="sjroot", db="user", charset='utf8')
mycursor = mydb.cursor()
sql = "select user_id,account_no from repay.t_asset_core where loan_code = '{0}';".format(loanCode1)
# sql = "select user_id,account_no from repay.t_asset_core where loan_code = 'JKSQ20220711049208DK'"
mycursor.execute(sql)
myresult =mycursor.fetchall()
for x in myresult:
print('user_id,account_no:',x,type(x)) user_id2=x[0]
account_no2=x[1]
print('user_id2:',user_id2)
print('account_no2:',account_no2)
# user_id3='"'+user_id2+'"'
# account_no3='"'+account_no2+'"'
# print('user_id3:',user_id3)
# print('account_no3:',account_no3) ur1='http://10.253.43.83:8399/repayment/order/repaymentTrial'
headers = {'Content-Type':'application/json','Accept': '*/*'}
Value = {
"accountNo": account_no2,
"channelNo": "",
"endPeriod": 1,
"isSettle": "",
"loanCode": loanCode1,
"payCode": user_id2,
"period": 1,
"repayWay": ""
}
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('',repones3)
print('',r.status_code)
print('',r.headers)

执行结果:

D:\Python3\python.exe E:/python/20190221接口/33.py
user_id,account_no: ('4108102770459648', 'ZH9595100061069003') <class 'tuple'>
user_id2: 4108102770459648
account_no2: ZH9595100061069003
1 {
    "msg": "成功",
    "data": {
        "loanCode": "JKSQ20220710049184DK",
        "payTime": "2022-08-11 10:12:50",
        "period": 1,
        "endPeriod": 1,
        "repayWay": "2",
        "settleStatus": "4",
        "payCode": "4108102770459648",
        "accountNo": "ZH9595100061069003",
        "channelNo": "0014",
        "orderId": "101002_2022081110124980996895558",
        "feeList": []
    },
    "code": 20000
}
2 200
3 {'X-Application-Context': 'repayment-asset-order-web:pre:8399', 'X-Request-Id': 'x-defa0473-70c7-4966-a9a5-2f963d88fab4', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 11 Aug 2022 02:12:50 GMT'}

Process finished with exit code 0

三、完整的只传入loan_code即完成还款试算、还款接口的调用

import requests
import json
import pymysql loanCode1="JKSQ20220710049178DK"
'''
# 还款试算接口
'''
#参数化取出user_id,account_no
mydb = pymysql.connect(host="172.31.20.2", port=3306, user="root", passwd="sjroot", db="user", charset='utf8')
mycursor = mydb.cursor()
sql = "select user_id,account_no from repay.t_asset_core where loan_code = '{0}';".format(loanCode1)
# sql = "select user_id,account_no from repay.t_asset_core where loan_code = 'JKSQ20220711049208DK'"
mycursor.execute(sql)
myresult =mycursor.fetchall()
for x in myresult:
print('user_id,account_no:',x,type(x))
user_id2=x[0]
account_no2=x[1]
print('user_id2:',user_id2)
print('account_no2:',account_no2)
# user_id3='"'+user_id2+'"'
# account_no3='"'+account_no2+'"'
# print('user_id3:',user_id3)
# print('account_no3:',account_no3)#加上这部分会出错的 #调用还款试算接口
ur1='http://10.253.43.83:8399/repayment/order/repaymentTrial'
headers = {'Content-Type':'application/json','Accept': '*/*'}
Value = {
"accountNo": account_no2,
"channelNo": "",
"endPeriod": 1,
"isSettle": "",
"loanCode": loanCode1,#参数化
"payCode": user_id2,#参数化
"period": 1,
"repayWay": ""
}
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('',repones3)
print('',r.status_code)
print('',r.headers) repones = r.text
print('',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']#打印字典中的某个值
orderId1=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:',orderId1,'类型为:',type(orderId1)) #判断payMoney的值是否为payBen、payIni、payFee的和
payMoneytotal=payBen+payIni+payFee
print(payMoneytotal)
payMoneytotal2=round(payMoneytotal,2)#取小数点后两位数
print('payMoneytotal2:',payMoneytotal2)
if payMoneytotal2==payMoney:
print('payMoney的值,PASS:','payBen+payIni+payFee=payMoney')
else:
print('呵呵哒...') '''
以下这部分待完善。。。
'''
# 连接数据判断接口返回的值是否和数据表中的一致
mydb = pymysql.connect(host="172.31.20.2", port=3306, user="root", passwd="sjroot", db="user", charset='utf8')
mycursor = mydb.cursor()
sql = "select must_amt from repay.t_external_borrow_repay where loan_code = 'JKSQ20220208048780DK' and period=1"
mycursor.execute(sql)
myresult =mycursor.fetchall()
for x in myresult:
# print(x,type(x))
print(x[0]) sql2 = "select must_amt from repay.t_external_borrow_fee_asset where loan_code = 'JKSQ20220208048780DK' and period=1"
mycursor.execute(sql2)
myresult =mycursor.fetchall()
for x in myresult:
# print(x,type(x))
print(x[0]) '''
还款接口
'''
#调用还款接口
ur12='http://10.253.43.83:8399/repayment/order/repaymentRequest'
headers2 = {'Content-Type':'application/json','Accept': '*/*'}
Value2 = {
"accountNo": account_no2,#参数化
"accountType": "capital",
"channelNo": "",
"endPeriod": 1,
"loanCode": loanCode1,#参数化
"orderId": orderId1,#参数化
"payCode": user_id2,#参数化
"payMoney": payMoneytotal2,#参数化
"period": 1,
"repayWay": "",
"settleStatus": ""
}
r = requests.post(url=ur12,json=Value2,headers=headers2)
repones2 =r.json()
repones3=json.dumps(repones2,indent=4,ensure_ascii=False)#ensure_ascii=False将返回的json汉字化
print('',repones3)
print('',r.status_code)
print('',r.headers) repones = r.text
print('',repones)
print(type(repones))#<class 'str'>

运行后的结果:

D:\Python3\python.exe E:/python/20190221接口/还款试算与还款接口2.py
user_id,account_no: ('4108102770459648', 'ZH9595100061069003') <class 'tuple'>
user_id2: 4108102770459648
account_no2: ZH9595100061069003
1 {
    "msg": "成功",
    "data": {
        "loanCode": "JKSQ20220710049178DK",
        "payBen": 112.3,
        "payIni": 4.67,
        "payFee": 40.0,
        "payMoney": 156.97,
        "payTime": "2022-08-11 10:15:31",
        "period": 1,
        "endPeriod": 1,
        "repayWay": "2",
        "settleStatus": "4",
        "payCode": "4108102770459648",
        "accountNo": "ZH9595100061069003",
        "channelNo": "0014",
        "orderId": "101002_2022081110153112167045558",
        "feeList": [
            {
                "feeName": "靖哲还款时资管费",
                "feeCode": "FC20181102011507002",
                "feeMoney": 40.0
            }
        ]
    },
    "code": 20000
}
2 200
3 {'X-Application-Context': 'repayment-asset-order-web:pre:8399', 'X-Request-Id': 'x-44ddc786-1eaa-423e-ba8f-8b335d497b8c', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 11 Aug 2022 02:15:31 GMT'}
11 {"msg":"成功","data":{"loanCode":"JKSQ20220710049178DK","payBen":112.3,"payIni":4.67,"payFee":40.0,"payMoney":156.97,"payTime":"2022-08-11 10:15:31","period":1,"endPeriod":1,"repayWay":"2","settleStatus":"4","payCode":"4108102770459648","accountNo":"ZH9595100061069003","channelNo":"0014","orderId":"101002_2022081110153112167045558","feeList":[{"feeName":"靖哲还款时资管费","feeCode":"FC20181102011507002","feeMoney":40.0}]},"code":20000}
<class 'str'>
s_dic的类型为: <class 'dict'>
s_dic: {'msg': '成功', 'data': {'loanCode': 'JKSQ20220710049178DK', 'payBen': 112.3, 'payIni': 4.67, 'payFee': 40.0, 'payMoney': 156.97, 'payTime': '2022-08-11 10:15:31', 'period': 1, 'endPeriod': 1, 'repayWay': '2', 'settleStatus': '4', 'payCode': '4108102770459648', 'accountNo': 'ZH9595100061069003', 'channelNo': '0014', 'orderId': '101002_2022081110153112167045558', 'feeList': [{'feeName': '靖哲还款时资管费', 'feeCode': 'FC20181102011507002', 'feeMoney': 40.0}]}, 'code': 20000}
payBen: 112.3 类型为: <class 'float'>
payIni: 4.67 类型为: <class 'float'>
payFee: 40.0 类型为: <class 'float'>
payMoney: 156.97 类型为: <class 'float'>
orderId: 101002_2022081110153112167045558 类型为: <class 'str'>
156.97
payMoneytotal2: 156.97
payMoney的值,PASS: payBen+payIni+payFee=payMoney
1146.34
49.59
245.0300
11 {
    "msg": "成功",
    "data": {
        "msg": "还款申请已提交",
        "code": 20000
    },
    "code": 20000
}
22 200
33 {'X-Application-Context': 'repayment-asset-order-web:pre:8399', 'X-Request-Id': 'x-d1610eb0-041d-45b7-a079-5855baaa5a8b', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 11 Aug 2022 02:15:33 GMT'}
11 {"msg":"成功","data":{"msg":"还款申请已提交","code":20000},"code":20000}
<class 'str'>

Process finished with exit code 0

 

部分还款-还款试算接口与还款接口-python的更多相关文章

  1. 部分还款-还款试算接口-python

    一.swagger-ui中 二.python中调用接口,出现的问题: 解决办法: import requests # 还款试算接口 ur1='http://10.253.43.83:8399/repa ...

  2. [xms]西软xms试算平衡报表-穿透明细报表-增加储值卡卡号列

    只能呵呵哒 [xms]西软xms试算平衡报表-穿透明细报表-增加储值卡卡号列 pospay ' and hotelid='${hotelid}'; hhaccount ' and hotelid='$ ...

  3. Java基础-Collection子接口之Set接口

    Java基础-Collection子接口之Set接口 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 学习Collection接口时,记得Collection中可以存放重复元素,也可 ...

  4. asp 支付宝 企业版 接口 支持网银接口 ,网银直接支付

    asp 支付宝 企业版 接口 支持网银接口 ,网银直接支付 仅仅是多了一个defalutbank的參数. 详细看 open.alipay.com <% ' 类名:AlipaySubmit ' 功 ...

  5. 转】C#接口-显式接口和隐式接口的实现

    [转]C#接口-显式接口和隐式接口的实现 C#中对于接口的实现方式有隐式接口和显式接口两种: 类和接口都能调用到,事实上这就是“隐式接口实现”. 那么“显示接口实现”是神马模样呢? interface ...

  6. JDBC的使用(二):PreparedStatement接口;ResultSet接口(获取结果集);例题:SQL注入

    ResultSet接口:类似于一个临时表,用来暂时存放数据库查询操作所获得的结果集. getInt(), getFloat(), getDate(), getBoolean(), getString( ...

  7. 比较器:Compare接口与Comparator接口区别与理解

    一.实现Compare接口与Comparator接口的类,都是为了对象实例数组排序的方便,因为可以直接调用 java.util.Arrays.sort(对象数组名称),可以自定义排序规则. 不同之处: ...

  8. 集合中Set接口与Collection接口,常用子类TreeSet,HashSet.

    Set接口与List接口的不同之处在于: 不允许有重复的数据. 定义如下: public interface Set<E>extends Collection<E> 主要方法与 ...

  9. Callable接口、Runable接口、Future接口

    1. Callable与Runable区别 Java从发布的第一个版本开始就可以很方便地编写多线程的应用程序,并在设计中引入异步处理.Thread类.Runnable接口和Java内存管理模型使得多线 ...

随机推荐

  1. python多行代码简化

    python中,可以把多行代码简化为一行,把for循环和if条件判断都集中到一行里来写,示例如下: >>> from nltk.corpus import stopwords > ...

  2. KMP 算法详解

    之前模模糊糊的理解了KMP,结果由于并不是完全弄清楚而导致自己在一道题目上疯狂的T,似乎是next函数写的有问题,于是痛心疾首的回来写一篇报告,警示自己 对KMP来说,匹配串的next数组是重中之重, ...

  3. :eq

    匹配一个给定索引值的元素?只要在html页面每个元素都有索引值,相同的元素按html位置顺序从0开始往下排.给定索引值:给定一个html某个区域的元素的索引值,也是从0开始 不给区域就是从html从d ...

  4. Windows小技巧 -- 目录内打开CMD的快捷方式

    工作中常常会有需要在某个文件夹内使用cmd的情况,例如运行某脚本,下面演示几种方法. 以进入以下目录操作为例: 方式一 : 常用的cd命令 cd命令是我们平常使用比较多的方式: 1. Win+R打开c ...

  5. Hbase建表时遇到的问题This could be a sign that the server has too many connections

    Hbase创建表时遇到以下错误: ERROR: org.apache.hadoop.hbase.ZooKeeperConnectionException: HBase is able to conne ...

  6. [No0000CD]shell 中的单行注释和多行注释

    1. 单行注释 众所周知,#  比如想要注释:echo “ni” # echo "ni" 2. 多行注释 法一: : << ! 语句1 语句2 语句3 语句4 ! 例如 ...

  7. 【模板】HDU 1541 树状数组

    http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意:给你一堆点,每个点右一个level,为其右下方所有点的数量之和,求各个level包含的点数. 题解: ...

  8. 关于JAVA项目中的常用的异常处理情况

         Java异常处理的几个原则如下.       1)不要丢弃异常,捕获异常后需要进行相关处理.如果用户觉得不能很好地处理该异常,就让它继续传播,传到别的地方去处理,或者把一个低级的异常转换成应 ...

  9. /etc/apt/sources.list" E212: Can't open file for writing解决方案

    :w !sudo tee % > /dev/null 解决.

  10. iOS程序main函数之前发生了什么

    我是前言 一个iOS app的main()函数位于main.m中,这是我们熟知的程序入口.但对objc了解更多之后发现,程序在进入我们的main函数前已经执行了很多代码,比如熟知的+ load方法等. ...