def getobtainVerificationCode(licenseno, sessionid, frameNo): try: #请求车管所验证码并且打码 ####################################### log.info( u"请求车管所验证码=====http://www.epicc.com.cn/wap/carProposal/JSArea/obtainVerificationCode============================开始" ) headers[ 'Referer'] = 'http://www.epicc.com.cn/wap/carProposal/car/carInput2' #obtainVerificationCodebody='licenseNo=%E8%http://www.epicc.com.cn8B%8FA44444&frameNo=LVZA43F93EC554224&channelNo=2&sessionId='+sessionid obtainVerificationCodebody = { "licenseNo": licenseno, "sessionId": sessionid, "frameNo": frameNo, "channelNo": "2" } obtainVerificationCodebody = urllib.urlencode( obtainVerificationCodebody) obtainVerificationCode_response = requests.post( url= 'http://www.epicc.com.cn/wap/carProposal/JSArea/obtainVerificationCode', headers=headers, data=obtainVerificationCodebody) obtainVerificationCode_body = obtainVerificationCode_response.json() code_msg = obtainVerificationCode_body['message'] code_msg = eval(code_msg) check_code = jsonpath.jsonpath(code_msg, '$.check_code')[0] #log.info("check_code=%s" % check_code) #fname=se.imagePath+utils.getTimstamp()+'.jpg' #log.info('code =%s'% check_code) #log.info('picnam =%s'% fname) #imagebse64.base642img(check_code,fname) codestr = utils.pic2Str(base64.b64decode(check_code)) log.info(u"验证码为=%s" % (codestr)) log.info( u"请求车管所验证码=====http://www.epicc.com.cn/wap/carProposal/JSArea/obtainVerificationCode============================结束" ) return codestr except Exception, e: log.error(e) log.error(traceback.format_exc()) log.error(u"验证码流程异常") #getobtainVerificationCode('苏A44444','4a9491a5-0460-459d-9d6b-e3c79634ee3a','LVZA43F93EC554224')
def _Get_RandomNum(session_req): log = Logger() try: millis = int(round(time.time() * 1000)) url = "http://32.0.192.232:88/sinoiais/pages/login/RandomNumUtil.jsp?d={0}".format( str(millis)) code_resp = session_req.get(url=url, headers=headers) # 验证码 codestr = None if code_resp: code_base64 = base64.b64encode(code_resp.content) codestr = pic2Str(base64.b64decode(code_base64)) if not codestr: log.info("获取验证码异常") log.info("codestr=%s" % codestr) return codestr except Exception as e: log.error(e) log.error(traceback.format_exc()) return None
def get_yzm(TWFID): millis = int(round(time.time() * 1000)) headers_3 = { 'Accept': 'image/png, image/svg+xml, image/jxr, image/*;q=0.8, */*;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN', 'Referer': 'https://vpn.cjbx.com.cn/web/1/http/0/88.32.0.232:88/sinoiais/', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Cookie': 'collection=%7Bauto_login_count%3A0%2Cpage_state%3A%27started%27%2Cneed_ist_cscm%3A%27-1%27%2CscacheUseable%3A0%2CAppCount%3A0%7D; g_LoginPage=login_psw; VisitTimes=0; haveLogin=1; ENABLE_RANDCODE=0; LoginMode=2; websvr_cookie={0}; TWFID={1}; webonly=1; allowlogin=1' .format(millis * 1000, TWFID), 'Host': 'vpn.cjbx.com.cn', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36', } url3 = "https://vpn.cjbx.com.cn/web/0/http/1/88.32.0.232:88/sinoiais/pages/login/RandomNumUtil.jsp?d={0}".format( str(millis)) print url3 # 验证码 r = requests.get(url3, headers=headers_3, verify=False) with open('3.png', 'wb') as output: output.write(r.content) code_base64 = base64.b64encode(r.content) codestr = pic2Str(base64.b64decode(code_base64)) print codestr return codestr
def login_ssl(): try: millis = int(round(time.time() * 1000)) headers = se.headers with open('cookie.txt') as f: TWFID = f.readline() print TWFID headers["Cookie"] = "TWFID={0}".format(TWFID) url_yzm = "https://vpn.cjbx.com.cn/web/0/http/1/88.32.0.232:88/sinoiais/pages/login/RandomNumUtil.jsp?d={0}".format( str(millis)) code_resp = get_request(url=url_yzm, headers=headers) # 验证码 codestr = None if code_resp: code_base64 = base64.b64encode(code_resp.content) codestr = pic2Str(base64.b64decode(code_base64)) if not codestr: print u"获取验证码异常" print codestr url_login1 = "https://vpn.cjbx.com.cn/web/0/http/1/88.32.0.232:88/sinoiais/checklogin/checkLoginInfo.do" data_1 = { "sysUserCode": "CJCXwm01", "sysPassWord": "******", "random": codestr } headers["Content-Type"] = "application/x-www-form-urlencoded" login_1_resp = post_request(url=url_login1, data=data_1, headers=headers) if not login_1_resp: return print login_1_resp.text response_body = login_1_resp.content.decode() response_body = json.loads(response_body) print response_body print type(response_body) msg = response_body.get('msg') count =0 if msg != 'success' and count <5: print u'验证码错误' count=count+1 return login_ssl() # 如果验证码返回错误不执行第二步 url_login2 = "https://vpn.cjbx.com.cn/web/1/http/1/88.32.0.232:88/sinoiais/login.html" data_2 = { "sysUser.userCode": "CJCXwm01", } login_2_resp = post_request(url=url_login2, data=data_2, headers=headers) # print login_2_resp.text # req_session.adapters.pop('https://') # log1_session = codecs.encode(pickle.dumps(req_session), "base64").decode() # update_new_session("11", {"11": log1_session}) except Exception as e: print e
licenseNo) + '&frameNo=' + rackNo + '&channelNo=2&sessionId=' + sessionid re2 = s.post( url='http://www.epicc.com.cn/wap/carProposal/JSArea/obtainVerificationCode', data=data2) body2 = re2.json() code_msg = body2['message'] code_msg = eval(code_msg) #log.info("code_msg=%s" % code_msg) check_code = jsonpath.jsonpath(code_msg, '$.check_code')[0] log.info("check_code=%s" % check_code) fname = '../image/' + utils.getTimstamp() + '.jpg' #log.info('code =%s'% check_code) log.info('picnam =%s' % fname) imagebse64.base642img(check_code, fname) codestr = utils.pic2Str(fname) log.info(u"验证码为=%s,文件名为=%s" % (codestr, fname)) #发送验证码 data3 = 'icationCode=' + codestr + '&channelNo=2&sessionId=' + sessionid re3 = s.post( url='http://www.epicc.com.cn/wap/carProposal/JSArea/obtainVerifQueryCar', data=data3) body3 = re3.json() body3 = ast.literal_eval(body3['message']) code = body3['head']['errorCode'] while code == '93037': #####获取车管所验证码 headers[ 'Referer'] = 'http://www.epicc.com.cn/wap/carProposal/car/carInput2' data2 = 'licenseNo=' + urllib.quote(