1286 lines
50 KiB
Python
1286 lines
50 KiB
Python
from datetime import datetime, timedelta
|
||
from Crypto.PublicKey import RSA
|
||
import base64, re
|
||
from Crypto.Cipher import PKCS1_v1_5
|
||
import requests, time, json, uuid, datetime
|
||
from config import *
|
||
from dateutil.relativedelta import relativedelta
|
||
import threading
|
||
import urllib3
|
||
from Crypto.Cipher import AES
|
||
from base64 import b64encode, b64decode
|
||
import logging
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||
|
||
lock = threading.Lock()
|
||
|
||
def format_uct(origin_date_str):
|
||
origin_date_str = origin_date_str.split('.')[0]
|
||
utc_date = datetime.datetime.strptime(origin_date_str, "%Y-%m-%dT%H:%M:%S")
|
||
local_date = utc_date + datetime.timedelta(hours=8)
|
||
local_date_str = datetime.datetime.strftime(local_date, '%Y-%m-%d %H:%M:%S')
|
||
return local_date_str
|
||
|
||
|
||
def filter_jdy_ht(id):
|
||
"""筛选简道云合同表单中驾驶员对应信息"""
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data = {
|
||
"app_id": fu_app,
|
||
"entry_id": ht_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "shfzhh",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
logger.info(f"开始查询合同信息{filter_data}")
|
||
ht_detail = turn_page(url, filter_data)
|
||
if not ht_detail:
|
||
return []
|
||
ht_detail = ht_detail[0]
|
||
# 机构
|
||
jg = ht_detail['ssbm']
|
||
# 分司
|
||
fs = ht_detail['fs']
|
||
# 商户号
|
||
if jg == '金建':
|
||
sh = '0001000F7152040'
|
||
elif jg == '银建':
|
||
sh = '0001000F7152279'
|
||
elif jg == '金银建':
|
||
sh = '0001000F7152152'
|
||
elif jg == '华建':
|
||
sh = '0001000F7151798'
|
||
elif jg == '银建新能源':
|
||
sh = '0001000F7173132'
|
||
# 商户号证书
|
||
shzs = ht_detail['shxl']
|
||
# 姓名
|
||
name = ht_detail['xm']
|
||
# 车牌号
|
||
hphm = ht_detail['hphm']
|
||
# 分司负责人
|
||
fsfz = ht_detail['fsfz']['dept_no'] if ht_detail['fsfz'] else ""
|
||
# 身份ID
|
||
shfid = ht_detail['shfid']
|
||
return [jg, fs, sh, shzs, name, hphm, fsfz,shfid]
|
||
|
||
def get_sort():
|
||
"""筛选简道云合同表单中驾驶员对应信息"""
|
||
res = query_reasons_for_payment()
|
||
# 初始化两个空字典来存储结果
|
||
reason_to_sort = {}
|
||
|
||
# 遍历data列表
|
||
for item in res:
|
||
reason = item['reason']
|
||
sort = item['sort']
|
||
|
||
# 更新reason_to_sort字典
|
||
if reason not in reason_to_sort:
|
||
reason_to_sort[reason] = sort
|
||
# 注意:这里我们没有处理相同reason但不同sort的情况,因为只保留了第一个sort值
|
||
|
||
# 打印结果以验证
|
||
return reason_to_sort
|
||
|
||
def queryUser(id):
|
||
# 查询充值明细
|
||
# user = get_user_info(id)
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": pay_details_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "pay_type",
|
||
"method": "in",
|
||
"value": ["微信支付","支付宝支付","云闪付支付"]
|
||
},
|
||
{
|
||
"field": "mode_type",
|
||
"method": "eq",
|
||
"value": ["自营"]
|
||
},
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
logger.info(f"queryUser开始查询充值明细{filter_data}")
|
||
pay_detail = turn_page(url, filter_data)
|
||
pay_detail.reverse()
|
||
for i in pay_detail:
|
||
i['charge_time'] = format_uct(i['charge_time'])
|
||
# 查询个人余额
|
||
info = {
|
||
"app_id": cw_app,
|
||
"entry_id": accout_id,
|
||
"filter": {"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "date",
|
||
"method": "empty",
|
||
|
||
}
|
||
]}
|
||
}
|
||
# 查询个人余额账户表 没有新增,有更新
|
||
logger.info(f"queryUser开始查询个人余额{info}")
|
||
res = req_tool_jdy(url, info)
|
||
logger.info(f"res====={res}")
|
||
balance = 0
|
||
if res['data']:
|
||
balance = res['data'][0]['balance']
|
||
balance = float("%.2f" % balance)
|
||
return {"balance": balance, "pay_detail": pay_detail}
|
||
|
||
|
||
def get_last_8_hour():
|
||
_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() - 8 * 60 * 60))
|
||
return _time
|
||
|
||
|
||
def turn_page(url, data):
|
||
"""翻页查询"""
|
||
info = []
|
||
while 1:
|
||
try:
|
||
logger.info(f"开始翻页查询{url},{data}")
|
||
res = req_tool_jdy(url, data)
|
||
info += res['data']
|
||
if len(res['data']) < 100:
|
||
return info
|
||
data["data_id"] = res["data"][-1]["_id"]
|
||
except Exception as e:
|
||
logger.error(f"turn_page,e{e}, res{res}")
|
||
|
||
|
||
def get_user_info(id, type=None):
|
||
"""获取用户信息"""
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
if type:
|
||
filter_data = {
|
||
"app_id": fu_app,
|
||
"entry_id": fu_id,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
else:
|
||
filter_data = {
|
||
"app_id": fu_app,
|
||
"entry_id": fu_id,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "user",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
logger.info(f"开始查询用户信息{filter_data}")
|
||
res = req_tool_jdy(url, filter_data)
|
||
if res['data']:
|
||
return res['data'][0]
|
||
return ''
|
||
|
||
# def query_reasons_type
|
||
|
||
def query_reasons_for_payment():
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": reasons_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "business",
|
||
"method": "eq",
|
||
"value": ["自营"]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
reasons_data = turn_page(url, filter_data)
|
||
return reasons_data
|
||
|
||
def get_reasons():
|
||
"""筛选简道云合同表单中驾驶员对应信息"""
|
||
reasons_data = query_reasons_for_payment()
|
||
reasons_data = sorted(reasons_data, key=lambda x: x['sort'])
|
||
# 使用字典推导式创建reason为键,dktype为值的字典
|
||
# 初始化字典,包含两个空列表作为值
|
||
dktype_to_reasons_dict = {
|
||
'非专项扣除': [],
|
||
'专项扣除': []
|
||
}
|
||
# 遍历数据,根据dktype的值将reason添加到对应的列表中
|
||
for item in reasons_data:
|
||
dktype = item['dktype']
|
||
reason = item['reason']
|
||
if dktype in dktype_to_reasons_dict:
|
||
dktype_to_reasons_dict[dktype].append(reason)
|
||
|
||
return dktype_to_reasons_dict
|
||
|
||
def query_zxpay_details(id):
|
||
# 查询某人未收付明细
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": uncollected_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "mode_type",
|
||
"method": "eq",
|
||
"value": ["自营"]
|
||
},
|
||
{
|
||
"field": "no_money",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
|
||
logger.info(f"开始查询专项未收付{filter_data}")
|
||
uncollected_data = turn_page(url, filter_data)
|
||
_data = []
|
||
reasons = get_reasons()
|
||
for i in uncollected_data:
|
||
flag = False
|
||
for j in reasons['专项扣除']:
|
||
if j == i['fukuanshiyou'] and (i['shgid'] == '' or i['fukuanshiyou'] in ["赔偿金", "预收赔偿金"]):
|
||
flag = True
|
||
break
|
||
if not flag:
|
||
continue
|
||
i['money'] = float("%.2f" % i['money']) if i['money'] else 0
|
||
i['pay'] = float("%.2f" % i['pay']) if i['pay'] != None and i['pay'] != '' else 0
|
||
i['no_money'] = float("%.2f" % i['no_money']) if i['no_money'] != None and i['no_money'] != '' else 0
|
||
i['sort'] = 9999
|
||
rule_sort = get_sort()
|
||
for j in rule_sort:
|
||
if j in i['fukuanshiyou']:
|
||
i['sort'] = rule_sort[j]
|
||
_data.append(i)
|
||
uncollected_data = _data
|
||
uncollected_data = sorted(uncollected_data, key=lambda x: x['createTime'], reverse=True)
|
||
# 过滤已结清数据
|
||
uncollected_data = [i for i in uncollected_data if i['money'] != i['pay']]
|
||
undata = {}
|
||
# # 按月份归类 uncollected_data
|
||
# for un in uncollected_data:
|
||
# if un['month1'] in undata.keys():
|
||
# undata[un['month1']]['data'].append(un)
|
||
# else:
|
||
# undata[un['month1']] = {"data": []}
|
||
# undata[un['month1']]['data'] = [un]
|
||
# 按收付款事由归类
|
||
for un in uncollected_data:
|
||
fukuanshiyou = un['fukuanshiyou']
|
||
if fukuanshiyou in undata.keys():
|
||
undata[fukuanshiyou]['data'].append(un)
|
||
else:
|
||
undata[fukuanshiyou] = {"data": []}
|
||
undata[fukuanshiyou]['data'] = [un]
|
||
# 按月查询增减项 flowState结束
|
||
amount = 0
|
||
for un in undata:
|
||
for entry in undata[un]['data']:
|
||
_th_amount = 0
|
||
del_list = []
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": hz_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "month",
|
||
"method": "eq",
|
||
"value": [entry['month1']]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
# logger.info(f"开始查询核增核减", filter_data)
|
||
hz_data_list = turn_page(url, filter_data)
|
||
# 应付总额 承包金定额=应收承包金-增减项
|
||
zj_sum = sum(item['jine'] for item in hz_data_list)
|
||
for index, j in enumerate(undata[un]['data']):
|
||
j['no_money'] = j['no_money'] if j['no_money'] else j['money']
|
||
|
||
if '承包金' in j['fukuanshiyou'] and j['yewubiaodanmingcheng'] == '费税计划':
|
||
if j['pay'] - zj_sum == j['money']:
|
||
del_list.append(index)
|
||
continue
|
||
# 定额 de = 表单中的金额-增减
|
||
# 应付金额 money = 表单中的金额
|
||
# 未付金额 unpay = 应付金额-增减-已付金额
|
||
j['pay'] = j['pay'] if j['pay'] else 0
|
||
|
||
undata[un]['de'] = j['money'] - zj_sum
|
||
# j['money'] = undata[un]['de'] + zj_sum
|
||
j['no_money'] = j['money'] - j['pay']
|
||
# amount += j['unpay'] if j['unpay'] else j['money']
|
||
_th_amount += j['no_money'] if j['no_money'] else j['money']
|
||
undata[un]['_th_amount'] = float("%.2f" % _th_amount)
|
||
undata[un]['hz'] = hz_data_list
|
||
for d in del_list:
|
||
undata[un]['data'].pop(d)
|
||
# 遍历字典中的每个项目(除了 'amount')
|
||
for key, value in undata.items():
|
||
if key not in ('amount','安全统筹') and '_th_amount' in value: # 确保当前项有 '_th_amount'
|
||
amount += value['_th_amount'] # 累加 _th_amount
|
||
|
||
# 更新 'amount' 键的值为总和
|
||
undata['amount'] = float("%.2f" % amount)
|
||
for i in list(undata.keys()):
|
||
if i != 'amount' and not undata[i]['data']:
|
||
del undata[i]
|
||
return undata
|
||
|
||
def query_fzxpay_details(id):
|
||
# 查询某人未收付明细
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": uncollected_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "mode_type",
|
||
"method": "eq",
|
||
"value": ["自营"]
|
||
},
|
||
{
|
||
"field": "no_money",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
|
||
logger.info(f"开始查询非专项未收付{filter_data}")
|
||
uncollected_data = turn_page(url, filter_data)
|
||
_data = []
|
||
reasons = get_reasons()
|
||
for i in uncollected_data:
|
||
flag = False
|
||
for j in reasons['非专项扣除']:
|
||
if j == i['fukuanshiyou'] and i['lydunjiao'] not in ['趸交','租车牌'] and (i['shgid'] == '' or i['fukuanshiyou'] in ["赔偿金", "预收赔偿金"]):
|
||
flag = True
|
||
break
|
||
if not flag:
|
||
continue
|
||
i['money'] = float("%.2f" % i['money']) if i['money'] else 0
|
||
i['pay'] = float("%.2f" % i['pay']) if i['pay'] != None and i['pay'] != '' else 0
|
||
i['no_money'] = float("%.2f" % i['no_money']) if i['no_money'] != None and i['no_money'] != '' else 0
|
||
i['sort'] = 9999
|
||
rule_sort = get_sort()
|
||
for j in rule_sort:
|
||
if j == i['fukuanshiyou']:
|
||
i['sort'] = rule_sort[j]
|
||
_data.append(i)
|
||
uncollected_data = _data
|
||
uncollected_data = sorted(uncollected_data, key=lambda x: x['createTime'], reverse=True)
|
||
# 过滤已结清数据
|
||
uncollected_data = [i for i in uncollected_data if i['money'] != i['pay']]
|
||
undata = {}
|
||
# 按月份归类 uncollected_data
|
||
for un in uncollected_data:
|
||
if un['month1'] in undata.keys():
|
||
undata[un['month1']]['data'].append(un)
|
||
else:
|
||
undata[un['month1']] = {"data": []}
|
||
undata[un['month1']]['data'] = [un]
|
||
# 按月查询增减项 flowState结束
|
||
amount = 0
|
||
logger.info(f"开始查询核增核减{filter_data}")
|
||
for un in undata:
|
||
_th_amount = 0
|
||
del_list = []
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": hz_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "month",
|
||
"method": "eq",
|
||
"value": [un]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
hz_data_list = turn_page(url, filter_data)
|
||
# 应付总额 承包金定额=应收承包金-增减项
|
||
zj_sum = sum(item['jine'] for item in hz_data_list)
|
||
for index, j in enumerate(undata[un]['data']):
|
||
j['no_money'] = j['no_money'] if j['no_money'] else j['money']
|
||
|
||
if '承包金' in j['fukuanshiyou'] and j['yewubiaodanmingcheng'] == '费税计划':
|
||
if j['pay'] - zj_sum == j['money']:
|
||
del_list.append(index)
|
||
continue
|
||
# 定额 de = 表单中的金额-增减
|
||
# 应付金额 money = 表单中的金额
|
||
# 未付金额 unpay = 应付金额-增减-已付金额
|
||
j['pay'] = j['pay'] if j['pay'] else 0
|
||
|
||
undata[un]['de'] = j['money'] - zj_sum
|
||
# j['money'] = undata[un]['de'] + zj_sum
|
||
j['no_money'] = j['money'] - j['pay']
|
||
# amount += j['unpay'] if j['unpay'] else j['money']
|
||
_th_amount += j['no_money'] if j['no_money'] else j['money']
|
||
undata[un]['_th_amount'] = float("%.2f" % _th_amount)
|
||
undata[un]['hz'] = hz_data_list
|
||
for d in del_list:
|
||
undata[un]['data'].pop(d)
|
||
# 遍历字典中的月份(除了 'amount')
|
||
for month, value in undata.items():
|
||
if month != 'amount' and '_th_amount' in value: # 确保当前项有 '_th_amount'
|
||
amount += value['_th_amount'] # 累加 _th_amount
|
||
# 更新 'amount' 键的值为总和
|
||
undata['amount'] = float("%.2f" % amount)
|
||
for i in list(undata.keys()):
|
||
if i != 'amount' and not undata[i]['data']:
|
||
del undata[i]
|
||
return undata
|
||
|
||
def query_pay_details(id):
|
||
# 查询某人未收付明细
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": uncollected_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "mode_type",
|
||
"method": "eq",
|
||
"value": ["自营"]
|
||
},
|
||
{
|
||
"field": "type",
|
||
"method": "eq",
|
||
"value": ["收款"]
|
||
},
|
||
{
|
||
"field": "no_money",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
|
||
logger.info(f"开始查询未收付{filter_data}")
|
||
uncollected_data = turn_page(url, filter_data)
|
||
_data = []
|
||
reasons = get_reasons()
|
||
for i in uncollected_data:
|
||
flag = False
|
||
for keys in reasons.keys():
|
||
for j in reasons[keys]:
|
||
if j == i['fukuanshiyou'] and (i['shgid'] == '' or i['fukuanshiyou'] in ["赔偿金", "预收赔偿金"]):
|
||
flag = True
|
||
break
|
||
if not flag:
|
||
continue
|
||
i['money'] = float("%.2f" % i['money']) if i['money'] else 0
|
||
i['pay'] = float("%.2f" % i['pay']) if i['pay'] != None and i['pay'] != '' else 0
|
||
i['no_money'] = float("%.2f" % i['no_money']) if i['no_money'] != None and i['no_money'] != '' else 0
|
||
i['sort'] = 9999
|
||
rule_sort = get_sort()
|
||
for j in rule_sort:
|
||
if j == i['fukuanshiyou']:
|
||
i['sort'] = rule_sort[j]
|
||
_data.append(i)
|
||
uncollected_data = _data
|
||
uncollected_data = sorted(uncollected_data, key=lambda x: x['createTime'], reverse=True)
|
||
# 过滤已结清数据
|
||
uncollected_data = [i for i in uncollected_data if i['money'] != i['pay']]
|
||
undata = {}
|
||
# 按月份归类 uncollected_data
|
||
for un in uncollected_data:
|
||
if un['month1'] in undata.keys():
|
||
undata[un['month1']]['data'].append(un)
|
||
else:
|
||
undata[un['month1']] = {"data": []}
|
||
undata[un['month1']]['data'] = [un]
|
||
# 按月查询增减项 flowState结束
|
||
amount = 0
|
||
logger.info(f"开始查询核增核减{filter_data}")
|
||
for un in undata:
|
||
_th_amount = 0
|
||
del_list = []
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": hz_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "month",
|
||
"method": "eq",
|
||
"value": [un]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
hz_data_list = turn_page(url, filter_data)
|
||
# 应付总额 承包金定额=应收承包金-增减项
|
||
zj_sum = sum(item['jine'] for item in hz_data_list)
|
||
for index, j in enumerate(undata[un]['data']):
|
||
j['no_money'] = j['no_money'] if j['no_money'] else j['money']
|
||
|
||
if '承包金' in j['fukuanshiyou'] and j['yewubiaodanmingcheng'] == '费税计划':
|
||
# if j['pay'] - zj_sum == j['money']:
|
||
# del_list.append(index)
|
||
# continue
|
||
# 定额 de = 表单中的金额-增减
|
||
# 应付金额 money = 表单中的金额
|
||
# 未付金额 unpay = 应付金额-增减-已付金额
|
||
j['pay'] = j['pay'] if j['pay'] else 0
|
||
|
||
undata[un]['de'] = j['money'] - zj_sum
|
||
# j['money'] = undata[un]['de'] + zj_sum
|
||
j['no_money'] = j['money'] - j['pay']
|
||
amount += j['no_money'] if j['no_money'] else j['money']
|
||
_th_amount += j['no_money'] if j['no_money'] else j['money']
|
||
undata[un]['_th_amount'] = _th_amount
|
||
undata[un]['hz'] = hz_data_list
|
||
for d in del_list:
|
||
undata[un]['data'].pop(d)
|
||
undata['amount'] = float("%.2f" % amount)
|
||
for i in list(undata.keys()):
|
||
if i != 'amount' and not undata[i]['data']:
|
||
del undata[i]
|
||
return undata
|
||
|
||
# def req_tool_jdy(url, data):
|
||
# headers = {"Authorization": f"Bearer {apikey}"}
|
||
# while 1:
|
||
# try:
|
||
# res = requests.post(url, headers=headers, json=data, timeout=10, verify=False).json()
|
||
# if "code" in res.keys():
|
||
# logger.info(f"req_tool_jdy", res)
|
||
# logger.info(f"url", url)
|
||
# logger.info(f"data", data)
|
||
# time.sleep(2)
|
||
# continue
|
||
# return res
|
||
# except Exception as e:
|
||
# print(e)
|
||
|
||
def req_tool_jdy(url, data):
|
||
headers = {"Authorization": f"Bearer {apikey}"}
|
||
max_retries = 5 # 最大重试次数
|
||
retries = 0
|
||
|
||
while retries < max_retries:
|
||
try:
|
||
res = requests.post(url, headers=headers, json=data, timeout=10, verify=False).json()
|
||
if "code" in res.keys():
|
||
logger.error("req_tool_jdy response indicates an error:", res, url, data)
|
||
retries += 1
|
||
time.sleep(2) # 等待时间,避免迅速重试
|
||
continue
|
||
else:
|
||
return res
|
||
except Exception as e:
|
||
logger.error(f"Request error:url{url},data{data}, e{e}")
|
||
retries += 1
|
||
time.sleep(2)
|
||
logger.error(f"Max retries reached for url: {url} with data: {data}")
|
||
return None # 在多次尝试后返回 None
|
||
|
||
def req_tool_vx(url, data=None, flag=None):
|
||
while 1:
|
||
try:
|
||
if not flag:
|
||
res = requests.post(url, json=data, timeout=10, verify=False).json()
|
||
else:
|
||
res = requests.get(url, timeout=10, verify=False).json()
|
||
return res
|
||
except Exception as e:
|
||
logger.error(e)
|
||
|
||
|
||
def update_unpay(data,is_specialized):
|
||
"""更新未收付,添加已收付明细"""
|
||
url = f'{base_path}/api/v5/app/entry/data/update'
|
||
add_url = f'{base_path}/api/v5/app/entry/data/create'
|
||
del_url = f'{base_path}/api/v1/app/{cw_app}/entry/{uncollected_id}/data_delete'
|
||
for i in data:
|
||
if 'amount' == i:
|
||
continue
|
||
for j in data[i]['data']:
|
||
info = {
|
||
"app_id": cw_app,
|
||
"entry_id": uncollected_id,
|
||
"data_id": j['_id'],
|
||
"is_start_trigger": True,
|
||
"is_start_workflow": True,
|
||
"data": {
|
||
"pay": {"value": j['pay']},
|
||
"no_money": {"value": j['no_money']},
|
||
}
|
||
}
|
||
logger.info(f"开始更新未收付{info}")
|
||
now_time = get_last_8_hour()
|
||
req_tool_jdy(url, info)
|
||
# 新增已收付明细
|
||
if 'flag' in j.keys() and float(j['flag_m']):
|
||
if not j['flag_m'] or not float(j['flag_m']):
|
||
continue
|
||
fs_p = j['fs_p']['dept_no'] if j['fs_p'] else ""
|
||
if is_specialized == 1:
|
||
add_info = {
|
||
"app_id": cw_app,
|
||
"entry_id": received_id,
|
||
"is_start_trigger": True,
|
||
"is_start_workflow": True,
|
||
"data": {
|
||
"code": {"value": j['code']}, "type": {"value": "收款"},
|
||
"fukuanshiyou": {"value": j['fukuanshiyou']}, "month1": {"value": j['month1']},
|
||
"month": {"value": j['month']},"yewubiaodanmingcheng": {"value": j['yewubiaodanmingcheng']},
|
||
"yewubiaodanbianma": {"value": j['yewubiaodanbianma']},
|
||
"sijixingming": {"value": j['sijixingming']}, "shfid": {"value": j['shfid']},
|
||
"id_card": {"value": j['id_card']},
|
||
"company_jc": {"value": j['company_jc']}, "xd": {"value": j['xd']},
|
||
"sijisuozaigongsi": {"value": j['sijisuozaigongsi']}, "fs": {"value": j['fs']},
|
||
"license_plate": {"value": j['license_plate']}, "money": {"value": j['money']},
|
||
"pay": {"value": j['flag_m']}, "hz_month": {"value": j['hz_month']},"pay_time": {"value": now_time},
|
||
"fs_p": {"value": fs_p}, "shgid": {"value": j['shgid']}, "mode_type": {"value": j['mode_type']},
|
||
"sy": {"value": "个人账户抵扣-专项"},"ys": {"value": j['ys']},"lydunjiao": {"value": j['lydunjiao']},"bill_type": {"value": j['bill_type']},
|
||
"car_dept": {"value": j['car_dept']},"contract_num": {"value": j['contract_num']}
|
||
}
|
||
}
|
||
else:
|
||
add_info = {
|
||
"app_id": cw_app,
|
||
"entry_id": received_id,
|
||
"is_start_trigger": True,
|
||
"is_start_workflow": True,
|
||
"data": {
|
||
"code": {"value": j['code']}, "type": {"value": "收款"},
|
||
"fukuanshiyou": {"value": j['fukuanshiyou']}, "month": {"value": j['month']},
|
||
"month1": {"value": j['month1']},"yewubiaodanmingcheng": {"value": j['yewubiaodanmingcheng']},
|
||
"yewubiaodanbianma": {"value": j['yewubiaodanbianma']},
|
||
"sijixingming": {"value": j['sijixingming']},"shfid": {"value": j['shfid']},
|
||
"id_card": {"value": j['id_card']},
|
||
"company_jc": {"value": j['company_jc']}, "xd": {"value": j['xd']},
|
||
"sijisuozaigongsi": {"value": j['sijisuozaigongsi']}, "fs": {"value": j['fs']},
|
||
"license_plate": {"value": j['license_plate']}, "money": {"value": j['money']},
|
||
"pay": {"value": j['flag_m']}, "hz_month": {"value": j['hz_month']},"pay_time": {"value": now_time},
|
||
"fs_p": {"value": fs_p}, "shgid": {"value": j['shgid']}, "mode_type": {"value": j['mode_type']},
|
||
"sy": {"value": "个人账户抵扣-非专项"},"ys": {"value": j['ys']},"lydunjiao": {"value": j['lydunjiao']},"bill_type": {"value": j['bill_type']},
|
||
"car_dept": {"value": j['car_dept']},"contract_num": {"value": j['contract_num']}
|
||
}
|
||
}
|
||
logger.info(f"开始新增已收付{add_info}")
|
||
print(f"开始新增已收付{add_info}")
|
||
req_tool_jdy(add_url, add_info)
|
||
logger.info(f"删除========={j['pay']},{j['money']}")
|
||
if j['sijixingming'] == '姓名':
|
||
logger.info(f"j:{j}")
|
||
if j['pay'] == j['money']:
|
||
# 未收付已清缴,删除未收付明细
|
||
del_info = {
|
||
"data_id": j["_id"],
|
||
"is_start_trigger": True
|
||
}
|
||
logger.info(f"开始删除未收付{del_info}")
|
||
req_tool_jdy(del_url, del_info)
|
||
|
||
|
||
def update_info(cz, _balcace, balance, user_info):
|
||
# 余额 = 累计充值金额-累计抵扣金额
|
||
# 本次抵扣=本次充值+本次余额-剩余金额
|
||
di = cz + balance - _balcace
|
||
"""更新个人账户余额"""
|
||
# if pay_amount:
|
||
# # 支付完有剩余余额可直接更新
|
||
# amount = pay_amount
|
||
# else:
|
||
# # 查询未收付历史数据
|
||
# details = query_pay_details(user_info['user']['username'])
|
||
# amount = details['amount']
|
||
# amount *= -1
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
info = {
|
||
"app_id": cw_app,
|
||
"entry_id": accout_id,
|
||
"filter": {"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [user_info['id']]
|
||
},
|
||
{
|
||
"field": "mode_type",
|
||
"method": "eq",
|
||
"value": ['自营']
|
||
},
|
||
{
|
||
"field": "date",
|
||
"method": "empty"
|
||
},
|
||
]}
|
||
}
|
||
# 查询个人余额账户表 没有新增,有更新
|
||
logger.info(f"开始查询个人余额,没有新增,有更新{info}")
|
||
res = req_tool_jdy(url, info)
|
||
if res['data']:
|
||
# 更新
|
||
url = f'{base_path}/api/v5/app/entry/data/update'
|
||
pay = res['data'][-1]['pay'] + cz
|
||
di = di + (res['data'][-1]['deduction'] if res['data'][-1]['deduction'] else 0)
|
||
amount = pay - di # 累计充值-累计抵扣
|
||
info = {
|
||
"app_id": cw_app,
|
||
"entry_id": accout_id,
|
||
"data_id": res['data'][-1]["_id"],
|
||
"is_start_workflow": True,
|
||
"is_start_trigger": True,
|
||
"data": {
|
||
"pay": {"value": pay}, "balance": {"value": amount},
|
||
"deduction": {"value": di}
|
||
}
|
||
}
|
||
else:
|
||
# 新增
|
||
amount = cz - di # 本次充值-本次抵扣
|
||
if 'name' in user_info.keys():
|
||
name = user_info['name']
|
||
else:
|
||
name = ""
|
||
url = f'{base_path}/api/v5/app/entry/data/create'
|
||
info = {
|
||
"app_id": cw_app,
|
||
"entry_id": accout_id,
|
||
"is_start_workflow": True,
|
||
"is_start_trigger": True,
|
||
"data": {
|
||
"id_card": {"value": user_info['id']},
|
||
"account_type": {"value": "预收款"},
|
||
"mode_type": {"value": "自营"},
|
||
"name": {"value": name},
|
||
"pay": {"value": cz},
|
||
"deduction": {"value": di},
|
||
"balance": {"value": amount},
|
||
"jg": {"value": user_info['jg']},
|
||
"fs": {"value": user_info['fs']},
|
||
"fsfz": {"value": user_info['fsfz']},
|
||
"hphm": {"value": user_info['hphm']},
|
||
"shfid": {"value": user_info['shfid']},
|
||
}
|
||
}
|
||
logger.info(f"开始回写个人账户,没有新增,有更新{info}")
|
||
req_tool_jdy(url, info)
|
||
|
||
|
||
def add_payment(data, type=None):
|
||
lock.acquire()
|
||
logger.info(f"开始========add_payment,data是{data}")
|
||
logger.info(f"data{data}, type{type}")
|
||
# user = get_user_info(data['id'])
|
||
# 充值成功后 回写充值明细
|
||
now_month = datetime.datetime.now().strftime("%Y-%m")
|
||
now_time = get_last_8_hour()
|
||
url = f'{base_path}/api/v5/app/entry/data/create'
|
||
if not type:
|
||
# 查询是否已存在
|
||
query_url = f'{base_path}/api/v5/app/entry/data/list'
|
||
_query_tmp = {
|
||
"app_id": cw_app,
|
||
"entry_id": pay_details_id,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "transactionid",
|
||
"method": "eq",
|
||
"value": [data['transaction_id']]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
logger.info(f"add_payment开始查询充值明细{_query_tmp}")
|
||
res = req_tool_jdy(query_url, _query_tmp)
|
||
if res['data']:
|
||
logger.info(f"充值明细已存在========{data['transaction_id']}")
|
||
lock.release()
|
||
return
|
||
if any("安全统筹" in detail for detail in data['paymentdetails']):
|
||
info = {
|
||
"app_id": cw_app,
|
||
"entry_id": pay_details_id,
|
||
"is_start_workflow": True,
|
||
"is_start_trigger": True,
|
||
"data": {
|
||
"id_card": {"value": data['id']}, "name": {"value": data['name']},
|
||
"charge_amount": {"value": data['pay_amount']}, "pay_type": {"value": data['pay_type']},
|
||
"coll_type": {"value": "网银"}, "month": {"value": now_month},"fsfz": {"value": data['fsfz']},
|
||
"jg": {"value": data['jg']}, "fs": {"value": data['fs']},"mode_type": {"value": "自营"},
|
||
"hphm": {"value": data['hphm']},"shfid":{"value": data['shfid']},"zhtype": {"value": "预收款"},"type": {"value": "转入"},
|
||
"charge_time": {"value": now_time}, "transactionid": {"value": data['transaction_id']},"collect_pos":{"value": "安全统筹"}
|
||
}
|
||
}
|
||
else:
|
||
info = {
|
||
"app_id": cw_app,
|
||
"entry_id": pay_details_id,
|
||
"is_start_workflow": True,
|
||
"is_start_trigger": True,
|
||
"data": {
|
||
"id_card": {"value": data['id']}, "name": {"value": data['name']},
|
||
"charge_amount": {"value": data['pay_amount']}, "pay_type": {"value": data['pay_type']},
|
||
"coll_type": {"value": "网银"}, "month": {"value": now_month},"fsfz": {"value": data['fsfz']},
|
||
"jg": {"value": data['jg']}, "fs": {"value": data['fs']},"mode_type": {"value": "自营"},"collect_pos": {"value": data['jg']},
|
||
"hphm": {"value": data['hphm']}, "shfid": {"value": data['shfid']},"zhtype": {"value": "预收款"},"type": {"value": "转入"},
|
||
"charge_time": {"value": now_time}, "transactionid": {"value": data['transaction_id']}
|
||
}
|
||
}
|
||
if data['fsfz']:
|
||
info['data']["fsfz"] = {"value": data['fsfz']}
|
||
logger.info(f"add_payment开始新增充值明细{info}")
|
||
req_tool_jdy(url, info)
|
||
|
||
details = query_pay_details(data['id'])
|
||
dates = list(details.keys())
|
||
dates.sort()
|
||
dates.remove('amount')
|
||
|
||
pay_amount = data['pay_amount']
|
||
# 查询余额
|
||
balance = queryUser(data['id'])
|
||
pay_amount += balance['balance']
|
||
if pay_amount <= 0:
|
||
logger.info(f"余额为0结束========{data}")
|
||
lock.release()
|
||
return
|
||
logger.info(f"执行add_payment{data}")
|
||
is_specialized = 0
|
||
next_month = (datetime.datetime.now().date() - relativedelta(months=-1)).strftime("%Y-%m")
|
||
if not data['paymentdetails']:
|
||
if next_month in dates:
|
||
_tmp = details[next_month]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if '补收预收承包金' in i['fukuanshiyou'] or '安全统筹' in i['fukuanshiyou'] or i['lydunjiao'] == "趸交":
|
||
i['flag_m'] = 0
|
||
continue
|
||
if '承包金' in i['fukuanshiyou']:
|
||
# 承包金实际需要缴纳的
|
||
if pay_amount < i['money'] - i['pay']:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= (i['money'] - i['pay'])
|
||
i['flag_m'] = (i['money'] - i['pay'])
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
|
||
else:
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
if now_month in dates:
|
||
_tmp = details[now_month]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if '补收预收承包金' in i['fukuanshiyou'] or '安全统筹' in i['fukuanshiyou'] or i['lydunjiao'] == "趸交":
|
||
i['flag_m'] = 0
|
||
continue
|
||
if '承包金' in i['fukuanshiyou']:
|
||
# 承包金实际需要缴纳的
|
||
if pay_amount < i['money'] - i['pay']:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= (i['money'] - i['pay'])
|
||
i['flag_m'] = (i['money'] - i['pay'])
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
|
||
else:
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
for i in dates:
|
||
if i == next_month or i == now_month:
|
||
continue
|
||
# 将字符串日期转换为datetime对象
|
||
# 注意:由于我们的日期只有年和月,我们假设日是1(即每个月的第一天)
|
||
now_month_date = datetime.datetime.strptime(now_month + "-01", "%Y-%m-%d")
|
||
next_month_start = datetime.datetime.strptime(next_month + "-01", "%Y-%m-%d")
|
||
date_i_str = (i + "-01")
|
||
date_i = datetime.datetime.strptime(date_i_str, "%Y-%m-%d") # 注意这里我们使用了具体的日
|
||
|
||
_tmp = details[i]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
# 如果大于次月
|
||
if date_i > next_month_start and '补收预收承包金' in i['fukuanshiyou']:
|
||
i['flag_m'] = 0
|
||
continue
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if '补收预收承包金' in i['fukuanshiyou'] or i['lydunjiao'] == "趸交":
|
||
i['flag_m'] = 0
|
||
continue
|
||
if '承包金' in i['fukuanshiyou']:
|
||
# 承包金实际需要缴纳的
|
||
if pay_amount < i['money'] - i['pay']:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
|
||
else:
|
||
pay_amount -= (i['money'] - i['pay'])
|
||
i['flag_m'] = (i['money'] - i['pay'])
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
|
||
else:
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
# 根据抵扣规则,更新未支付的数据,将清缴数据新增至已收付明细
|
||
else:
|
||
is_specialized = 1
|
||
# 初始化结果字典
|
||
result = {}
|
||
# 处理每个项目
|
||
for item in data['paymentdetails']:
|
||
# 分割类型和日期
|
||
expense_type = item[:-7]
|
||
date = item[-7:]
|
||
|
||
# 更新专项收取字典
|
||
if date not in result:
|
||
result[date] = []
|
||
result[date].append(expense_type)
|
||
# 创建一个新的字典来存储过滤后的专项收取数据
|
||
filtered_details = {}
|
||
# 遍历未收付数据
|
||
for month, value in details.items():
|
||
# 跳过非月份的键(如'amount')
|
||
if month not in result:
|
||
continue
|
||
|
||
# 初始化一个列表来存储满足条件的data项
|
||
filtered_data = [item for item in value['data'] if item['fukuanshiyou'] in result[month]]
|
||
|
||
# 如果filtered_data非空,则添加到filtered_details中,并可以选择性地包含其他字段
|
||
if filtered_data:
|
||
# 注意:这里我们保留了'data'和其他可能需要的字段(如'de', '_th_amount', 'hz')
|
||
filtered_details[month] = {k: v for k, v in value.items() if k in ['data', 'de', '_th_amount', 'hz']}
|
||
# 但是,'data'字段已经被更新为filtered_data
|
||
filtered_details[month]['data'] = filtered_data
|
||
dates = [month for month in dates if month in result]
|
||
if next_month in dates:
|
||
# _tmp = filtered_details[next_month]['data']
|
||
_tmp = filtered_details.get(next_month, {}).get('data', [])
|
||
if _tmp:
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
if now_month in dates:
|
||
_tmp = filtered_details[now_month]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
for i in dates:
|
||
if i == next_month or i == now_month:
|
||
continue
|
||
_tmp = filtered_details[i]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
# 根据抵扣规则,更新未支付的数据,将清缴数据新增至已收付明细
|
||
logger.info(f"更新未收付{details,is_specialized}")
|
||
update_unpay(details,is_specialized)
|
||
# 未收付更新完后,更新个人账户余额update_info
|
||
logger.info(f"更新个人账户余额update_info")
|
||
update_info(data['pay_amount'], pay_amount, balance['balance'], data)
|
||
lock.release()
|
||
logger.info(f"结束========")
|
||
|
||
def rsa_long_decrypt(priv_key, msg, length=256):
|
||
"""
|
||
1024bit的证书用128,2048bit证书用256位
|
||
"""
|
||
try:
|
||
privobj = PKCS1_v1_5.new(priv_key)
|
||
res = []
|
||
b64_msg = base64.b64decode(msg)
|
||
for i in range(0, len(b64_msg), length):
|
||
chunk = b64_msg[i:i + length]
|
||
decrypted_chunk = privobj.decrypt(chunk, 'xyz').decode('GBK')
|
||
res.append(decrypted_chunk)
|
||
except Exception as e:
|
||
logger.error(f"解密回调失败:{e}")
|
||
return None
|
||
return "".join(res)
|
||
|
||
def decode_notify_data(res_json):
|
||
try:
|
||
ciphertext = res_json['resource']['ciphertext']
|
||
nonce = res_json['resource']['nonce']
|
||
associated_data = res_json['resource']['associated_data']
|
||
cipher = AES.new(v3_SECRET.encode(), AES.MODE_GCM, nonce=nonce.encode())
|
||
cipher.update(associated_data.encode())
|
||
en_data = b64decode(ciphertext.encode('utf-8'))
|
||
auth_tag = en_data[-16:]
|
||
_en_data = en_data[:-16]
|
||
plaintext = cipher.decrypt_and_verify(_en_data, auth_tag)
|
||
decodejson = json.loads(plaintext.decode())
|
||
except Exception as e:
|
||
logger.error(f"解密回调失败:{e}")
|
||
return None
|
||
return decodejson
|
||
|
||
def get_wx_token():
|
||
url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={SECRET}'
|
||
res = req_tool_vx(url, flag=1)
|
||
# print("==========================获取企微TOKEN============================",res)
|
||
return res['access_token']
|
||
|
||
|
||
def query_wx_fj_info(id):
|
||
"""查询企微中的附加信息"""
|
||
token = get_wx_token()
|
||
url = f'https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={token}&userid={id}'
|
||
res = req_tool_vx(url, flag=1)
|
||
# print("==========================获取企微附加信息============================", res)
|
||
val = ""
|
||
logger.info(f"query_wx_fj_info{res},{id}")
|
||
for i in res['extattr']['attrs']:
|
||
if i['name'] == '附加信息':
|
||
val = i['value']
|
||
return val
|
||
|
||
|
||
def query_wx_userid(code):
|
||
"""查询企微中的userid"""
|
||
token = get_wx_token()
|
||
url = f'https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token={token}&code={code}'
|
||
res = req_tool_vx(url, flag=1)
|
||
# print("==========================获取企微userid============================", res)
|
||
return res['userid']
|
||
|
||
def find_pay_details(id, paymentdetails):
|
||
# 查询某人未收付明细
|
||
can_submit = 0
|
||
for item in paymentdetails:
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
month = item[-7:]
|
||
logger.info(f"month{month}")
|
||
filter_data = {
|
||
"app_id": cw_app,
|
||
"entry_id": uncollected_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "month1",
|
||
"method": "eq",
|
||
"value": [month]
|
||
},
|
||
{
|
||
"field": "fukuanshiyou",
|
||
"method": "eq",
|
||
"value": ["安全统筹"]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
|
||
logger.info(f"发起安全统筹支付前开始查询未收付{filter_data}")
|
||
uncollected_data = turn_page(url, filter_data)
|
||
if uncollected_data == []:
|
||
logger.info(f"未查询到安全统筹未收付{uncollected_data}")
|
||
return 0
|
||
else:
|
||
logger.info(f"查询到安全统筹未收付{uncollected_data}")
|
||
return 1 |