181 lines
7.3 KiB
Python
181 lines
7.3 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
import time
|
|
import requests
|
|
import json
|
|
import xlrd
|
|
from tqdm import tqdm
|
|
|
|
|
|
# 生成 token,参数不需要修改
|
|
def generateToken() -> str:
|
|
""" 生成 token """
|
|
token_api = 'https://api.dingtalk.com/v1.0/oauth2/accessToken'
|
|
# 该信息在钉钉开放应用中
|
|
data = {
|
|
"appKey": "ding5kqocon5s9oph5uq",
|
|
"appSecret": 'HL1jgsIIfLAC0eTH0A1m4mwxUDqbgsiPeCCGGE3ocM6qJBTIW7Ivt9drxF_Z4Kb_'
|
|
}
|
|
|
|
res = requests.post(token_api, json=data)
|
|
token = res.json()['accessToken']
|
|
|
|
return token
|
|
|
|
|
|
class NpEncoder(json.JSONEncoder):
|
|
def default(self, obj):
|
|
if isinstance(obj, np.integer):
|
|
return int(obj)
|
|
elif isinstance(obj, np.floating):
|
|
return float(obj)
|
|
elif isinstance(obj, np.ndarray):
|
|
return obj.tolist()
|
|
else:
|
|
return super(NpEncoder, self).default(obj)
|
|
|
|
|
|
def ceshi(formData) -> str:
|
|
""" 处理流程开始 """
|
|
TOKEN = generateToken()
|
|
|
|
""" 通过实例id 获取表单内容 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/processes/instances/start'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
payload = {
|
|
"appType": "APP_TNVBVZ3K8G56HG03Z45Q",
|
|
"systemToken": "CH7669818R0WN18TYTYJ42PE6GY22WZN0BYWKD1",
|
|
"userId": "2268275546837446",
|
|
"language": "zh_CN",
|
|
"formUuid": "FORM-UP96637151Q3XIFU9NNW9BKFUVHU2XWN0EF9L84",
|
|
"formDataJson": json.dumps(formData, cls=NpEncoder),
|
|
"processCode": "TPROC--UP96637151Q3XIFU9NNW9BKFUVHU2YWN0EF9L94",
|
|
"departmentId": "574140511" # 560526483 2706271
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=payload)
|
|
res_new = res.json()
|
|
print("生成失败预警!")
|
|
|
|
|
|
cookies_str ="marketingSESSIONID=1458e261-f7a5-44ab-813e-5112e3b54222; sajssdk_2015_cross_new_user=1; erpLanguage=zh-CN; prodOrg=11240984669918390035; unp=15956902486724325447; un=15956902486724325447; _up=-NillNN-qyBEJ--t3vnSknvoOF52yPeEsM8B2304WONeVPTFo57QjaZJ9Q3d-WrAAGgt60MgQHajHWBHMKKxj0CuWypi1JgKCFP1EPEk-HbqEvEVrIIg0AAJ9_NRv-ZNHu3M-GTc1523HHeqquVTjukek1TGOhdorEj9kxq49c3TRxc.; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2215956902486724325447%22%2C%22first_id%22%3A%2219a48e066e68e2-067b1e693596828-4c657b58-2073600-19a48e066e71500%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%2219a48e066e68e2-067b1e693596828-4c657b58-2073600-19a48e066e71500%22%7D; tmall=false; Hm_lvt_25f5e7a3a5dbb293d7dd35d5f1be8d0a=1762159273; HMACCOUNT=55F2182717FD6AE6; Hm_lpvt_25f5e7a3a5dbb293d7dd35d5f1be8d0a=1762159385"
|
|
cookies_str = cookies_str.encode('utf-8').decode('latin-1')
|
|
|
|
cookie_dict = {item.split('=')[0]: item.split('=')[1]
|
|
for item in cookies_str.split('; ')}
|
|
|
|
headers = {
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.40',
|
|
"Content-Type": "application/json",
|
|
'origin': 'https://yunxiu.f6car.cn'
|
|
}
|
|
# 读取excel文件
|
|
data = xlrd.open_workbook(r"D:\Idea Project\F6+宜搭+其它(1)\张阳脚本\模板\套餐卡退卡.xls")
|
|
|
|
table = data.sheet_by_index(0) # 通过索引顺序获取
|
|
|
|
h = table.nrows
|
|
|
|
l = table.ncols
|
|
|
|
print(u"表数据的行数为%s,列数为%s" % (h, l))
|
|
|
|
for i in tqdm(range(1, h)):
|
|
try:
|
|
idMember = table.cell(i, 0).value # 卡id
|
|
idMember1 = table.cell(i, 1).value # 退款金额
|
|
idMember2 = table.cell(i, 2).value # 退款金额
|
|
idOwnOrg = table.cell(i, 3).value # 门店ID
|
|
employeeId = table.cell(i, 4).value # 退卡服务顾问ID
|
|
# 读取cardVersion信息并配置退卡data
|
|
url = 'https://yunxiu.f6car.cn/marketing/tkdBill/baseInfo?pkId={}'.format(idMember)
|
|
resget = requests.get(url, cookies=cookie_dict)
|
|
resget = json.loads(resget.text)
|
|
cardVersion = resget['data']['cardVersion']
|
|
data = {
|
|
"cardId": idMember, # 退卡实体id
|
|
"cardVersion": cardVersion,
|
|
"employeeId": employeeId, # 退卡服务顾问ID 手动更新
|
|
"idOwnOrg": idOwnOrg, # 门店ID 手动更新
|
|
"refundAmount": idMember1, # 退卡金额
|
|
"remark": "" # 备注
|
|
}
|
|
# 生成退卡单
|
|
res = requests.post(f'https://yunxiu.f6car.cn/marketing/tkdBill/add',
|
|
headers=headers, cookies=cookie_dict, json=data)
|
|
resdata = res.json().get('data')
|
|
print(res.json())
|
|
|
|
# 读取Version信息并配置退卡data
|
|
url1 = 'https://yunxiu.f6car.cn/marketing/tkdBill/detail/{}'.format(resdata)
|
|
resget1 = requests.get(url1, cookies=cookie_dict)
|
|
resget1 = json.loads(resget1.text)
|
|
cardVersion1 = resget1['data']['version']
|
|
# 完成收款
|
|
if idMember1 != "0":
|
|
data = {
|
|
"idOwnOrg": idOwnOrg, # 门店ID 手动更新
|
|
"idOperationOrg": idOwnOrg, # 退卡门店ID 手动更新
|
|
"idSourceBill": resdata, # 退卡单ID
|
|
"sourceBillType": "TKD", # 类型
|
|
"receiptMemo": "", # 备注
|
|
"version": cardVersion1,
|
|
"favourableList": [],
|
|
"gatheringFavourable": 0,
|
|
"paymentTypeGroupId": "",
|
|
"czkList": [],
|
|
"paymentList": [
|
|
{
|
|
"paymentTypeId": "18525862", # 各门店不同 手动更新
|
|
"paymentType": "现金",
|
|
"paymentAmount": idMember2,
|
|
"gatheringType": 0,
|
|
"kind": "normal"
|
|
}
|
|
],
|
|
"pkId": 0,
|
|
"billType": "YSF",
|
|
"domainCode": "SAAS"
|
|
}
|
|
else:
|
|
data = {
|
|
"idOwnOrg": idOwnOrg, # 门店ID 手动更新
|
|
"idOperationOrg": idOwnOrg, # 退卡门店ID 手动更新
|
|
"idSourceBill": resdata, # 退卡单ID
|
|
"sourceBillType": "TKD", # 类型
|
|
"receiptMemo": "", # 备注
|
|
"version": cardVersion1,
|
|
"favourableList": [],
|
|
"gatheringFavourable": 0,
|
|
"paymentTypeGroupId": "",
|
|
"czkList": [],
|
|
"paymentList": [
|
|
{
|
|
"status": 0,
|
|
"paymentAmount": 0
|
|
}
|
|
],
|
|
"pkId": 0,
|
|
"billType": "YSF",
|
|
"domainCode": "SAAS"
|
|
}
|
|
# print(data)
|
|
res = requests.post(f'https://yunxiu.f6car.cn/financial/advance/payment/singleGathering',
|
|
headers=headers, cookies=cookie_dict, json=data)
|
|
print("打印出响应信息:", i, cardVersion, cardVersion1, resdata, idMember, res.text)
|
|
time.sleep(4)
|
|
# break # 测试
|
|
except:
|
|
formData = {
|
|
"textField_l9fe0uiw": idMember,
|
|
"textField_l9fe0uiv": '退卡异常!!'
|
|
}
|
|
# ceshi(formData)
|
|
print("异常", i)
|
|
continue
|