def addRole(head, env, userNum, roleType): #添加角色 out(f'正在为 {userNum} 添加角色……\t\t\t\t\t\t') roleCodeDic = { 'fundManager': 'R001', 'fundLiable': 'R002', 'coreManager': 'R003', 'coreLiable': 'R004', 'custManager': 'R005', 'custLiable': 'R006' } key = {'userNum': userNum, 'roleNum': roleCodeDic[roleType]} for i in range(5): r = requests.post(f'{MMdomainDic[env]}/eSealUserRole/insert', headers=head, data=key, verify=False) try: result = r.json() except json.decoder.JSONDecodeError: time.sleep(1) continue if result['success']: out(f'为 {userNum} 添加角色成功!\t\t\t\t\t') return result else: time.sleep(1) print(f'为 {userNum} 添加角色失败!\t\t\t\t\t') goonORquit()
def ICGR(processInstanceId,head,domain):#第五步录入授信结果 out('正在录入授信结果……\t\t\t\t\t\t') key={ 'processInstanceId':processInstanceId, 'grantingType':'LG_APPLICATION',#LG_APPLICATION大保理进件 LG_LIFTING大保理提额 'grantingPlatformCode':str(uuid1()).replace('-',''), 'grantingAmount':randint(5,9)*10**6, 'grantingWithdrawalsAmount':randint(1,4)*10**6, 'circulation':'Y',#Y可循环 N不可循环 'guaranteeType':'SELF_SUPPORTING',#SELF_SUPPORTING自担 OUTSIDE_CREDIT_ENHANCEMENT外部增信 'effectiveDate':time.strftime('%Y-%m-%d',time.localtime()), 'expirationDate':f"{time.localtime().tm_year+1}-{time.strftime('%m-%d',time.localtime())}", 'rightRecourse':'N',#Y有追索权 N无追索权 'factoringType':'MING_INSURANCE',#MING_INSURANCE明保 SILENT_CONFIRMATION暗保 'externalEnhcType':'RE_FACTORING',#SURETY_BOND保证担保 BUY_BACK回购 RE_FACTORING再保理 MORTGAGE抵押 'remark':'自动化测试数据', } for i in range(5): r=requests.post(f'{domain}/actCreditGranting/saveInputCreditGrantingResult',headers=head,data=key,verify=False) try: result=r.json() state=result['state'] if state==1:return True except json.decoder.JSONDecodeError: saveLog('录入授信请求失败!',r.text) time.sleep(1);continue except KeyError: saveLog('录入授信失败!',str(result)) time.sleep(1);continue goonORquit() return True
def uploadCustomerPic(processInstanceId,head,domain):#第三步上传图片 out('正在上传图片……\t\t\t\t\t\t') key={ 'processInstanceId':processInstanceId, 'customerFilesReqDTOList[0].fileName':'法人*屏蔽的关键字*背面', 'customerFilesReqDTOList[0].fileCode':'INF201901221125019791032', 'customerFilesReqDTOList[0].filePath':'group2/M00/B6/3A/rBGkFlyKFq-EHG9CAAAAABjiGCM515.png', 'customerFilesReqDTOList[1].fileName':'开户许可证', 'customerFilesReqDTOList[1].fileCode':'INF201901221125018623138', 'customerFilesReqDTOList[1].filePath':'group2/M00/B6/3A/rBGkFlyKFrOEbIFeAAAAALolShc807.png', 'customerFilesReqDTOList[2].fileName':'统一社会信用代码', 'customerFilesReqDTOList[2].fileCode':'INF201901221125018058703', 'customerFilesReqDTOList[2].filePath':'group2/M00/B6/3A/rBGkFlyKFriET-lSAAAAAC7Lx4U342.png', 'customerFilesReqDTOList[3].fileName':'法人*屏蔽的关键字*背面', 'customerFilesReqDTOList[3].fileCode':'INF201901221110014955628', 'customerFilesReqDTOList[3].filePath':'group2/M00/B6/3A/rBGkFlyKFryEMeLNAAAAAOdAfM4298.png', 'customerFilesReqDTOList[4].fileName':'法人*屏蔽的关键字*', 'customerFilesReqDTOList[4].fileCode':'INF201901221110014533804', 'customerFilesReqDTOList[4].filePath':'group2/M00/B6/3A/rBGkFlyKFr-EBEalAAAAAH1fsFg293.png', } for i in range(5): r=requests.post(f'{domain}/actCreditGranting/saveUploadCustomerDatum',headers=head,data=key,verify=False) try: result=r.json() state=result['state'] if state==1:return True except json.decoder.JSONDecodeError: saveLog('上传图片请求失败!',r.text) time.sleep(1);continue except KeyError: saveLog('上传图片失败!',str(result)) time.sleep(1);continue goonORquit() return True
def signProduct(domain, head, processInstanceId, agreTempCode=''): #第一步签约产品协议 out('正在签约产品……\t\t\t\t\t\t') key = { 'processInstanceId': processInstanceId, 'agreementTempleteCode': agreTempCode, 'busiManager': '', } for i in range(5): r = requests.post(f'{domain}/actCreditGranting/saveSignProduct', headers=head, data=key, verify=False) try: result = r.json() state = result['state'] if state == 1: return True except json.decoder.JSONDecodeError: saveLog('签约产品请求失败!', r.text) time.sleep(1) continue except KeyError: saveLog('签约产品失败!', str(result)) time.sleep(1) continue goonORquit() return True
def creditGrant(loginID, env): #第六步审核授信申请 out('正在审核授信申请……\t\t\t\t\t\t') domain, head, processInstanceId = getProcessInstanceId(loginID=loginID, env=env, MMusername='', MMpassword='') key = { 'result': 'Y', 'processInstanceId': processInstanceId, } for i in range(5): r = requests.post( f'{domain}/actCreditGranting/saveAuditingCreditGrantingResult', headers=head, data=key, verify=False) try: result = r.json() state = result['state'] if state == 1: return True, head except json.decoder.JSONDecodeError: saveLog('审核授信申请请求失败!', r.text) time.sleep(1) continue except KeyError: saveLog('审核授信申请失败!', str(result)) time.sleep(1) continue goonORquit() return True
def getProcessInstanceId(loginID, env='c', MMusername='', MMpassword=''): out(f'{MMusername} 正在获取 {loginID} 对应流程实例Id……\t\t\t\t\t\t') head = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36', 'Cookie': loginMMReq(env=env, username=MMusername, password=MMpassword)['Cookie'], 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Connection': 'close', } for i in range(5): r = requests.get(f'{MMdomainDic[env]}/myTask/list?page=1&limit=10', headers=head, verify=False) try: result = r.json() except json.decoder.JSONDecodeError: saveLog('查询流程实例Id失败!', r.text) time.sleep(1) continue for data in result['data']: if data['loginCode'] == loginID: return MMdomainDic[env], head, data['processInstanceId'] time.sleep(1) print('未查询到', loginID, '对应的 processInstanceId')
def savePic(code, imgdata, fpath=r'E:\Users\ZP\Desktop\5-2\py\RecognizeCode\codes\codes_H5', n=0): if not os.path.exists(fpath): os.mkdir(fpath) picName = f'{code}_{uuid.uuid1().hex[:8]}.png' picPath = os.path.join(fpath, picName) with open(picPath, 'wb') as f: f.write(base64.b64decode(imgdata)) out(f"{n} {picName}")
def addUser(company, head=''): #新增用户、角色 if not head: head = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36', 'Cookie': loginMMReq(env=company.env, username='', password='')['Cookie'], 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Connection': 'close', } key = { 'userNum': '', 'loginName': company.loginID, 'realName': company.legalName, 'password': '', 'email': company.email, 'statusCd': 'Y', 'sexCd': '1', 'city': company.city, 'mobile': company.legalTel, 'entCreditCode': company.BLRN, } # userNumDic={} if company.cusType == 'CORE': roleNameDic = {'manager': 'coreManager', 'liable': 'coreLiable'} elif company.cusType == 'CUSTOMER': roleNameDic = {'manager': 'custManager', 'liable': 'custLiable'} for loginID in [company.loginID, company.opLoginID]: key['loginName'] = loginID out(f'正在为 {loginID} 新增资金管理后台用户……\t\t\t\t\t\t') for i in range(5): r = requests.post( f'{MMdomainDic[company.env]}/electronicSealUser/insert', headers=head, data=key, verify=False) try: result = r.json() except json.decoder.JSONDecodeError: time.sleep(1) continue if result['success']: out(f'为 {loginID} 新增资金管理后台用户成功!\t\t\t\t\t\t\t') # userNumDic[loginID]=result['result']['userNum'] roleType = roleNameDic['liable'] if loginID.endswith( 'b') else roleNameDic['manager'] addRole(head, company.env, result['result']['userNum'], roleType) break else: time.sleep(1) return head
def getProcessInstanceId(loginID,env='c',MMusername='******',MMpassword='******',head=False): out(f'{MMusername} 正在获取 {loginID} 对应流程实例Id……\t\t\t\t\t\t') if not head:head=loginMMReq(env=env,username=MMusername,password=MMpassword) for i in range(5): r=requests.get(f'{MMdomainDic[env]}/myTask/list?page=1&limit=10',headers=head,verify=False) try: result=r.json() except json.decoder.JSONDecodeError: saveLog('查询流程实例Id失败!',r.text) time.sleep(1);continue for data in result['data']: if data['loginCode']==loginID:return MMdomainDic[env],head,data['processInstanceId'] time.sleep(1) print('未查询到',loginID,'对应的 processInstanceId')
def factorApply(head):#发起保理申请 out('正在发起保理申请……\t\t\t\t\t\t') if not head:head=loginMMReq(env=args.env,username='',password='') key={ 'loginCode':args.loginID, 'partnerCode':'BESTPAY', 'productCode':productCodeDic[_productCodeDic[args.productCode]], 'forecastReceAmount':args.FRA, 'applyAmount':args.applyAmount, 'expectTransferAmount':args.ETA, 'expectLoanDay':args.expectLoanDay, 'loanUsage':args.loanUsage, 'factoringExpires':args.factorExp, 'fundingCode':args.daddy, 'creditAgencyCode':args.CAC, 'factoringRate':args.factorRate, 'totalPeriod':args.totalPeriod, 'discountRate':args.discountRate, 'coreEnterpriseCode':args.CEC, 'repaymentType':args.repaymentType, 'repayType':args.repayType, 'guaranteeType':args.guarante, 'loanType':args.loanType, 'isRightRecourse':args.recourse, 'factoringType':'', 'informationSources':'', 'contractSignWay':'', 'repaySource':'', 'externalEnhcType':'', 'agent':'', 'agentContact':'13207165870', 'applyTime':f'{time.strftime("%Y%m%d",time.localtime())}000000', } for i in range(5): r=requests.post(f'{MMdomainDic[args.env]}/actFactoringApply/applyLargeFactoring',headers=head,data=key,verify=False) try: result=r.json() if result['success']: print("发起保理申请成功: ",result) return True else: print("发起保理申请失败: ",result) except json.decoder.JSONDecodeError: saveLog('发起保理申请请求失败!',r.text) time.sleep(1);continue except KeyError: saveLog('发起保理申请失败,返回数据异常!',r.text) time.sleep(1);continue
def bindBankCard(loginID,companyName,processInstanceId,domain,head):#第四步绑定银行卡 out('正在绑定银行卡……\t\t\t\t\t\t') soup=0 for i in range(5): r=requests.get(f'{domain}/actCreditGranting/bindingBankCard?processInstanceId={processInstanceId}&roleName=admin',headers=head) if '绑定账户' in r.text: soup=BeautifulSoup(r.text,'lxml') break else: saveLog('获取绑定账户页面失败!',r.text) time.sleep(1) if not soup:myexit() key={ 'processInstanceId':processInstanceId, 'index':soup.select_one("[name='index']")['value'], 'customerAccountReqDTOList[0].code':soup.select_one('[class="tbfongtweight"]').contents[4]['value'], 'customerAccountReqDTOList[0].accountCode':soup.select_one('[class="tbfongtweight"]').contents[7]['value'], 'customerAccountReqDTOList[0].accountType':'1',#0对私 1对公 2第三方 'customerAccountReqDTOList[0].accountUsage':'ENTRY_EXIT',#ENTRY_EXIT出入帐 ENTRY入账 EXIT出帐 'customerAccountReqDTOList[0].accountCategery':'1',#1银行账户 2第三方账户 'customerAccountReqDTOList[0].accountNumber':loginID, 'customerAccountReqDTOList[0].accountUserName':companyName, 'customerAccountReqDTOList[0].accountBank':'', 'customerAccountReqDTOList[0].bankBranch':'', 'customerAccountReqDTOList[0].paymentAgreementCode':'', 'customerAccountReqDTOList[0].remark':'', } for i in range(5): r=requests.post(f'{domain}/actCreditGranting/saveBindingBankCard',headers=head,data=key,verify=False) try: result=r.json() state=result['state'] if state==1:return True except json.decoder.JSONDecodeError: saveLog('绑定银行卡请求失败!',r.text) time.sleep(1);continue except KeyError: saveLog('绑定银行卡失败!',str(result)) time.sleep(1);continue goonORquit() return True
def actCreditGranting(MMusername='',MMpassword=''):#授信申请发起 out(f'发起授信申请:{args.loginID}\t\t\t\t\t\t') head=loginMMReq(env=args.env,username=MMusername,password=MMpassword) key={ 'loginCode':args.loginID, 'customerType':args.cusType, 'productCode':productCodeDic[_productCodeDic[args.productCode]], } for i in range(5): r=requests.post(f'{domain}/actCreditGranting/start',headers=head,data=key,verify=False) try: result=r.json() state=result['state'] if state==1:return head except json.decoder.JSONDecodeError: saveLog(f'{args.loginID} 发起授信申请请求失败!',r.text) time.sleep(1);continue except KeyError: saveLog(f'{args.loginID} 发起授信申请失败!',str(result)) time.sleep(1);continue goonORquit() return False
def addUser(company,head=''):#新增用户、角色 if not head:head=loginMMReq(env=company.env,username='******',password='******') key={ 'userNum':'', 'loginName':company.loginID, 'realName':company.legalName, 'password':'******', 'email':company.email, 'statusCd':'Y', 'sexCd':'1', 'city':company.city, 'mobile':company.legalTel, 'entCreditCode':company.BLRN, } # userNumDic={} if company.cusType=='CORE': roleNameDic={'manager':'coreManager','liable':'coreLiable'} elif company.cusType=='CUSTOMER': roleNameDic={'manager':'custManager','liable':'custLiable'} for loginID in [company.loginID,company.opLoginID]: key['loginName']=loginID out(f'正在为 {loginID} 新增资金管理后台用户……\t\t\t\t\t\t') for i in range(5): r=requests.post(f'{MMdomainDic[company.env]}/electronicSealUser/insert',headers=head,data=key,verify=False) try: result=r.json() except json.decoder.JSONDecodeError: time.sleep(1);continue if result['success']: out(f'为 {loginID} 新增资金管理后台用户成功!\t\t\t\t\t\t\t') # userNumDic[loginID]=result['result']['userNum'] roleType=roleNameDic['liable'] if loginID.endswith('b') else roleNameDic['manager'] addRole(head,company.env,result['result']['userNum'],roleType) break else: time.sleep(1) return head
def entryCoreCompany(company,head=''):#录入核心企业 if not head:head=loginMMReq(env=company.env,username='******',password='******') a,b=str(time.time()).split('.') key={ 'customerType':'1', 'coreEnterpriseCode':f"ENT{time.strftime('%Y%m%d%H%M%S',time.localtime(int(a)))}{b}", 'coreEnterpriseName':company.companyName, 'loginCode':company.loginID, 'partnerCode':company.bankCode, 'certType':'01', 'certCode':company.legalID, 'isRealnameAuth':'1', 'coreEnterpriseType':'CTCC', 'province':'000000', 'busiManager':'*', 'remark':'', 'customerName':company.companyName, 'busiLicenseNumber':company.BLRN, 'legalPerson':company.legalName, 'legalPersonCertNo':company.legalID, 'legalPersonMobile':company.legalTel, 'registrationDate':f"{company.regTime.replace('-','')}000000", 'registeredCapital':company.regCapital, 'registeredAddr':company.officeAddr, 'enterpriseType':'国企', 'enterpriseNature':'国企', 'enterpriseScale':'国企', 'registrationAuthority':'国企', 'officeAddr':company.officeAddr, 'businessOpeningDate':f"{company.regTime.replace('-','')}000000", 'businessClosingDate':f"{company.endTime.replace('-','')}000000", 'businessScope':company.scope, 'nationalTaxNo':company.taxRegCode, 'localTaxNo':company.taxRegCode, 'organizationalCode':company.orgCode, 'organizationalValidity':f"{company.endTime.replace('-','')}000000", 'unifiedSocialCode':company.BLRN, 'importExportCert':company.permitNum, 'annualInspectionDate':f"{company.endTime.replace('-','')}000000", 'employeeNum':company.regCapital, 'shareholdersNum':company.district, 'tel':company.legalTel, 'fax':'020689745', 'email':company.email, 'establishmentBackground':'测试成立背景', 'developingProcess':'测试发展过程', 'managementStructure':'测试管理结构', 'mainProducts':'测试主要产品', 'industryPolicy':'测试行业政策', 'marketCompetition':'测试市场竞争状况', 'futureDevelopmentPlan':'测试未来发展计划', 'busiPlacesNature':'临街店面', 'busiPlacesArea':'100.00', 'busiPlacesEvaluation':'1000000.00', 'actualController':company.legalName, 'actualControllerCertNo':company.legalID, 'actualControllerMobile':company.legalTel, 'contacts':company.legalName, 'contactsMobile':company.legalTel, } for i in range(5): r=requests.post(f'{MMdomainDic[company.env]}/coreEnterprise/save',headers=head,data=key,verify=False) try: result=r.json() except json.decoder.JSONDecodeError: print('添加核心企业返回数据错误',r.text) time.sleep(1);continue if result['success']: out(f'资金后台添加 {company.loginID} 核心企业成功!\t\t\t\t\t') return result else: time.sleep(1) print(f'资金后台添加 {company.loginID} 核心企业失败!{result}') goonORquit()
def getSMScode(tel, waiteSec=1, timeout=120, robot=0, menhuPath='', env='c', status='SUCCESS'): cookie = open(os.path.join(menhuPath, f'cookie\\MC_{env}'), 'r', encoding='UTF-8').read() date = time.strftime('%Y-%m-%d', time.localtime()) keys = { 'currentPage': '-1', 'pageSize': '10', 'requestStart': f'{date} 00:00:00', 'requestEnd': f'{date} 23:59:59', 'receiveNumber': tel, 'status': status } head = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Cookie': cookie, 'Connection': 'close' } for i in range(10): time.sleep(waiteSec) try: response = requests.post( f'{MCdomainDic[env]}/push/record/qureyPushList', headers=head, data=keys) except Exception as err: if i == 9: return err else: continue try: repJson = response.json() except jsonError: #返回的不是json数据,可能需要重新登陆 if '登录' in response.text: # print('cookieMC失效,重新登录……') browser, cookieLogined = loginMC(env=env) head['Cookie'] = cookieLogined browser.quit() else: print(response.text) continue if robot: try: if not repJson['items']: return 0 except KeyError: return repJson n = 0 result = '' for item in repJson['items']: n += 1 submitDate = time.strftime( '%Y-%m-%d %X', time.localtime(item['submitDate'] / 1000)) if tel: result = f"{result}{n}、发送时间:{submitDate}\n 短信内容:{item['content']}\n" else: result = f"{result}{n}、接收号码:{item['receiveNumber']}\t发送时间:{submitDate}\n 短信内容:{item['content']}\n" if n >= 5: break return result.strip() else: for item in repJson['items']: if time.time() - int(str(item['submitDate']) [:10]) <= timeout: #当前时间减去提交时间,小于120秒 if '验证码' in item['content']: SMScode = re.findall(r'\d+', item['content'])[0] return SMScode out(f'未找到{tel}的验证码,1秒后再查询') time.sleep(1)