1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- # -*- coding: utf-8 -*-
- """
- Created on 2024-03-01
- ---------
- @summary: 中国船舶采购管理电子商务平台 - 账号登录
- ---------
- @author: lzz
- """
- from hashlib import md5
- import requests
- from untils.cookie_pool import LoginCookiePool
- from untils.get_imgcode import jy_ocr
- class ZgcbwzPool(LoginCookiePool):
- def create_cookie(self, username, password):
- session = requests.Session()
- headers = {
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
- "Accept-Language": "zh-CN,zh;q=0.9",
- "Cache-Control": "no-cache",
- "Content-Type": "application/x-www-form-urlencoded",
- "Origin": "http://bs.ebuy.csemc.com",
- "Pragma": "no-cache",
- "Proxy-Connection": "keep-alive",
- "Referer": "http://bs.ebuy.csemc.com/login/doTdLogin.do",
- "Upgrade-Insecure-Requests": "1",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
- }
- image_text = ''
- url = 'http://bs.ebuy.csemc.com/authimg.img'
- for i in range(5):
- response = session.get(url)
- image_text = jy_ocr(
- response.content,
- "zhipu",
- '这是一张100以内数学计算图片验证码,中间被包裹字符是"?",图片算术内容是什么?你只需要返回图片算术内容即可,不要解释,不要返回任何其它内容'
- )
- if image_text and "=" in image_text:
- break
- def _extract(captcha, symbol):
- end = captcha.index(symbol)
- n1 = str(captcha[:end]).strip() # 被乘数/加数
- start = captcha.index("=")
- n2 = str(captcha[start + 1:]).strip() # 积/和
- return n1, n2
- def input_num(code):
- if "x" in code:
- multiplicand, product = _extract(code, "x")
- return round(int(product) / int(multiplicand))
- elif "+" in code:
- addend, sum_ = _extract(code, "+")
- return round(int(sum_) - int(addend))
- else:
- return "解析失败!"
- url = 'http://bs.ebuy.csemc.com/market/syscode/publicfun/getPwdRandom.do'
- random_res = session.post(url)
- random = random_res.content.decode()
- gg = md5(password.encode()).hexdigest().upper()
- pwd = md5((gg + random).encode()).hexdigest().upper()
- url = "http://bs.ebuy.csemc.com/login/doTdLogin.do"
- data = {
- "type": "1",
- "logsid": "M00004",
- "rememberflag": "0",
- "pwd": f"{pwd}",
- "url": "",
- "uid": f"{username}",
- "kl": "",
- "randCode": f"{input_num(image_text)}"
- }
- _ = session.post(url, headers=headers, data=data, timeout=20, verify=False)
- return requests.utils.dict_from_cookiejar(session.cookies)
|