説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Verify3001.py 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. from selenium import webdriver
  2. from selenium.webdriver.support.ui import WebDriverWait
  3. from sqlalchemy import Column,String,create_engine
  4. from sqlalchemy.orm import sessionmaker
  5. from sqlalchemy.ext.declarative import declarative_base
  6. import pyodbc
  7. import pandas as pd
  8. import traceback
  9. import csv
  10. import rsa
  11. import requests
  12. import binascii
  13. import json
  14. Base = declarative_base()
  15. class User(Base):
  16. __tablename__ = '客戶資料表'
  17. 客戶 = Column(String(20), primary_key=True)
  18. 資料庫 = Column(String(20))
  19. IP位置 = Column(String(20))
  20. 帳號 = Column(String(20))
  21. 密碼 = Column(String(20))
  22. class Someoneupdate(Base):
  23. __tablename__ = '自動導入判斷'
  24. 正在自動導入中= Column(String(20), primary_key=True)
  25. class CustomerDataVerify(Base):
  26. __tablename__ = '商客基本資料表'
  27. 網址= Column(String(20), primary_key=True)
  28. 帳號= Column(String(20), primary_key=True)
  29. 密碼= Column(String(20), primary_key=True)
  30. 驗證= Column(String(20))
  31. def LongFirstLogin(urlkey,adminkey,passkey):
  32. try:
  33. print(urlkey)
  34. pubkey="B0C1D0E12B47DA93A24C7422D433170A4D5B126A27CED6F3087652723562889803E2280041F02E6B24A251C928EBE5BA12501D466D63A43AD5D88A5809A09271F14FD220C0DAE272CAAF9F1CF09DAF52005272529071723C0CB87B5A6392860CA2E72B23A4652910DB87BAC31D89E4DD23B3C56AAE685D9A14C4CC89862AAA27"
  35. rsaPublickey = int(pubkey,16)
  36. key = rsa.PublicKey(rsaPublickey,65537)
  37. message='{\"Account\":\"'+adminkey+'\",\"Password\":\"'+passkey+'\"}'
  38. message=message.encode('utf8')
  39. #passwd = rsa.encrypt(message,key)
  40. passwd = binascii.b2a_hex(rsa.encrypt(message,key)).decode()
  41. Loginurl="http://"+urlkey+"/api/shared/login"
  42. headers1 = {
  43. 'Content-Length': '256',
  44. 'Content-Type': 'application/x-www-form-urlencoded'
  45. }
  46. response = requests.request("POST", Loginurl, headers=headers1, data=passwd)
  47. return response
  48. except:
  49. response="無法取得資料"
  50. print(response)
  51. return response
  52. def LongSecondLogin(LFLresponse):
  53. try:
  54. LFLresponseJson=json.loads(LFLresponse.text)
  55. print(LFLresponseJson)
  56. SecondLoginUrl=LFLresponseJson['Redirect']
  57. SecondLoginData=LFLresponseJson['Data']
  58. headers2 = {
  59. 'Content-Length': '514',
  60. 'Content-Type': 'application/x-www-form-urlencoded'
  61. }
  62. print(SecondLoginUrl)#debug
  63. GatewayUrl="http:"+SecondLoginUrl
  64. print(GatewayUrl)
  65. LoginGatewayPostData="+="+SecondLoginData
  66. response2 = requests.request("POST", GatewayUrl, headers=headers2, data=LoginGatewayPostData)
  67. return SecondLoginUrl,SecondLoginData,response2
  68. except:
  69. SecondLoginUrl=""
  70. SecondLoginData=""
  71. response2=""
  72. return SecondLoginUrl,SecondLoginData,response2
  73. def LongGetData(urlkey, adminkey, passkey):
  74. LFLresponse=LongFirstLogin(urlkey,adminkey,passkey)
  75. if LFLresponse=="無法取得資料":
  76. fordebugger="websiteerror"
  77. return fordebugger
  78. if LFLresponse.status_code==200:
  79. SecondLoginUrl,SecondLoginData,LSLresponse=LongSecondLogin(LFLresponse)
  80. if LSLresponse=="":
  81. fordebugger="ADPSERROR"
  82. return fordebugger
  83. else:
  84. fordebugger="OK"
  85. return fordebugger
  86. if LFLresponse.status_code!=200:
  87. fordebugger=ShortGetData(urlkey, adminkey, passkey)
  88. return fordebugger
  89. def ShortGetData(urlkey, adminkey, passkey):
  90. sloginUrl = "https://"+urlkey+"/pub/SuperGateway.php?c=900%2C"+adminkey+"%2C"+passkey
  91. response = requests.request("POST", sloginUrl)
  92. print(response.text)
  93. if response.status_code==200:
  94. if len(response.text)>3:
  95. SIDKey=response.text.split(',')[2]
  96. if len(SIDKey)<5:
  97. SIDKey=response.text.split(',')[3]
  98. print(SIDKey)
  99. AMKey=SIDKey.split('_')[0]
  100. print(AMKey)
  101. fordebugger="OK"
  102. return fordebugger
  103. else:
  104. fordebugger="ADPSERROR"
  105. return fordebugger
  106. if response.status_code!=200:
  107. fordebugger="ADPSERROR"
  108. return fordebugger
  109. def loadCSV():
  110. try:
  111. with open('000.csv', newline='') as csvfile:
  112. rows = csv.reader(csvfile)
  113. csvvrow=[]
  114. for row in rows:
  115. csvvrow.append(row)
  116. coustomtxt=(csvvrow[1][0])
  117. bdtxtcrypto=(csvvrow[2][0])
  118. #====================================解密==========================
  119. PRIVATTTTT=693199020841184529005187339596013597950466957598599888793608033530271219415853952414609432155441426597962873618644988823224505129033188472492232565627111731743840442387622658441932249274048207290194890312931801018119336565101207159089093817844379836520246765598761731093447853178093855957965143730121353938159096214435813116478583463281838568325696377260624492699103838269489173425735163766515881745838239102851526971498900537039965925229366981233886305256752613857576375123305107336285923247046744901857058559811348110224118414002814652550587381981742663420856507553321403129123387307759852585845583253705194423896104474967966535066409675943348475929657759428664521337873475544406762447015072876289975051669953965932555224693025757002523361150649200905802416556626834350633483715061798581642291839762255979334372982156774414505811030453728205541010293992016524698689810201483053731487961892768615175941360043106707261541518852778287823654935902238415934276399863697899069150965902889645358960710613979521286008786269668237598187906056491031301559442316212834296436205439154886053776090316790598915161638161668892006476380622662058436463540372859165165728327478177043147902958378365406901451035507793539047616182219516942468776336379
  120. #PrivateKey
  121. A1=435136098972877768874748645248339158125703956065257805897130489515873898645785064137580564100320503666838498219287367368030775233887671705599248600291953393231454780648861079171195672717473628632853618453449217420455794237632155291175461656351373149436294485404694429947256530385791280349340495413483412113186857182441596591220416636342090069157129915377951859333634936029548424638926391232291634636038258059603109206715187896810765799441703590963590776385210580000409455669280693512175818186066741512695081131148497030784289903926969375944559780083722346620544362180693184053719440253987062360057770451705216722616373945761278697477867656454308042535057052004210508850990364826097246310462235289453838547367442863138161099765610183693493835956264409463595891562624222255540841617618186384919177648960630843478742501992844305124096538648231123014949030890404247398161443680124720970242595119682693770042136274011065565273819531541118246115073819134261046370918950429149073365625538812772489582690787721407799409054150416184648077711942774002489730938839028835996373562349388498470086161265863994312489374464512279091382150353090705188164569282723516063722137626802108564462453248942121100848000690940344201632450119420978307322308945
  122. A2=9627714051932950193134188501742994592784042206914443459734438308841410040354738469881718445461422881776007294906803790685427277699734850787185938262102876531473114260174800542552232307443022494368143100728406826855674366796656059054215802558213346170105688323652674928367680251460924362233864869984871966783909100785712414620921144535418728448391075664442600744983428543175164409720230286595771434578391588137898216407341812591598354427012529961000712417819821596260309468611766323842906019082923549785615976305556417630687246871293866806059225782724368215141401076633953519395967986211659258251543120569378038365122086876706827618666557619122782700896147
  123. A3=72000374865933143340744306653169834428832683081115110740204100237805467875781399111076588189449270231784547205065314993551385284482420372845976820023615822918370850049018336485262561074750111640775157594829249815372287322731748252778906894672575675394415480712584447066603079224388770970172603768779881242086210954654794512868330782099170594476257989194451530266257956383540560124814995186866139904562390161487741092810396910518052928540664299189962055810713116703112503213279177866017925218355080344908808970420740591501342146164000394175136511345019472809580649061686926648057
  124. bdtxtcrypto=bdtxtcrypto.encode('utf8')
  125. print(bdtxtcrypto)
  126. print(type(bdtxtcrypto))
  127. bdtxtcrypto=binascii.a2b_hex(bdtxtcrypto)
  128. mmmmm=rsa.decrypt(bdtxtcrypto,rsa.PrivateKey(PRIVATTTTT,65537,A1,A2,A3))
  129. bdtxt=(mmmmm.decode('utf8'))
  130. #====================================解密==========================
  131. return coustomtxt,bdtxt
  132. except:
  133. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  134. traceback.print_exc(file=open('log.txt', 'a'))
  135. def connectEngine(coustomtxt):
  136. try:
  137. DB_session = sessionmaker(engine)
  138. db_session = DB_session()
  139. comDbUserData=db_session.query(User).filter(User.客戶.like(coustomtxt)).all()
  140. UserDbName=comDbUserData[0].資料庫
  141. UserIPName=comDbUserData[0].IP位置
  142. UserAdName=comDbUserData[0].帳號
  143. UserPdName=comDbUserData[0].密碼
  144. engine3 = create_engine('mssql+pyodbc://'+UserAdName+':'+UserPdName+'@'+UserIPName+'/'+UserDbName+'?driver=SQL+Server+Native+Client+11.0')
  145. return engine3
  146. except:
  147. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  148. traceback.print_exc(file=open('log.txt', 'a'))
  149. def LoadCustomData(engine3):
  150. try:
  151. text3="SELECT TOP(1000) 網址, 帳號, 密碼 FROM 商客基本資料表"
  152. loopper2=pd.read_sql(text3,engine3)
  153. contforloop=len(loopper2)
  154. loopper2=loopper2.values
  155. print(loopper2)
  156. return contforloop,loopper2
  157. except:
  158. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  159. traceback.print_exc(file=open('log.txt', 'a'))
  160. def UpdateVerify():
  161. Verifying=db_session2.query(CustomerDataVerify).filter_by(網址=urlkey,帳號=adminkey,密碼=passkey).first()
  162. Verifyingc=db_session2.query(CustomerDataVerify).filter_by(網址=urlkey,帳號=adminkey,密碼=passkey).count()
  163. print(Verifying)
  164. print("Have SQLData :"+str(Verifyingc))
  165. if (Verifyingc==1):
  166. Verifying.驗證=VerifyStr
  167. db_session2.commit()
  168. try:
  169. coustomtxt,bdtxt=loadCSV()
  170. engine = create_engine('mssql+pyodbc://'+bdtxt+'?driver=SQL+Server+Native+Client+11.0')
  171. engine3=connectEngine(coustomtxt)
  172. DB_session2 = sessionmaker(engine3)
  173. db_session2= DB_session2()
  174. def LoadingYesorNo():
  175. SUPDA=db_session2.query(Someoneupdate).filter_by(正在自動導入中='YES').first()
  176. SUPDAc=db_session2.query(Someoneupdate).filter_by(正在自動導入中='YES').count()
  177. print(SUPDAc)
  178. if (SUPDAc==1):
  179. SUPDA.正在自動導入中='NO'
  180. db_session2.commit()
  181. contforloop,loopper2=LoadCustomData(engine3)
  182. for z in range (contforloop):
  183. urlkey=loopper2[z][0]
  184. print(urlkey)
  185. adminkey=loopper2[z][1]
  186. passkey=loopper2[z][2]
  187. tttt2=LongGetData(urlkey, adminkey, passkey)
  188. if tttt2=="OK":
  189. VerifyStr="已驗證"
  190. UpdateVerify()
  191. elif tttt2=="websiteerror":
  192. VerifyStr="網址錯誤"
  193. UpdateVerify()
  194. elif tttt2=="ADPSERROR":
  195. VerifyStr="帳號密碼錯誤"
  196. UpdateVerify()
  197. LoadingYesorNo()
  198. except:
  199. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  200. traceback.print_exc(file=open('lorverrorlog.txt', 'a'))
  201. print("NNNNNNNNN2N")
  202. finally:
  203. LoadingYesorNo()