def login(session): """ 登录 获取cookie 和 必要的member_id :return: {"member_lv_id":"1","experience":null,"order_num":1,"member_id":"6527184"}} """ loginUrls = urls.get("login") data = { "uname": session.userInfo.get("user", ""), "password": session.userInfo.get("pwd", ""), "forward": "", } session.httpClint.send(urls.get("passportLogin")) while True: loginRsp = session.httpClint.send(loginUrls, data) if loginRsp and loginRsp.get("success", "") == "登录成功": U.Logging.info("账号: {}已登录".format(session.userInfo.get("user", ""))) session.loginData = loginRsp.get("data", "") if session.FastType is 0: # 下单 goodsDetail(session) break elif session.FastType is 1: # 查单 searchOrderInfo(session) break else: U.Logging.error("账号: {} 错误信息: {}".format( session.userInfo.get("user", ""), loginRsp.get("error", "")))
def speed(self): print("cdn测试开始") self.httpClint.send(urls.get("m", "")) for c in cdn: self.httpClint._cdn = [c] startTime = datetime.datetime.now() result = self.httpClint.send(urls.get("m", "")) if result.find("斐讯商城") != -1: print("测试cdn: {},速度为: {}ms".format( c, (datetime.datetime.now() - startTime).microseconds / 1000)) else: print("测试cdn: {} 有问题".format(c))
def searchOrderInfo(session): """ 查询账号订单状态, 查询间隔十秒 :param session: :return: """ U.Logging.info("账号:{} 查询线程开始启动...".format(session.userInfo.get("user", ""))) while not session.orderDone: searchOrderInfoRsp = session.httpClint.send(urls.get("myOrder", "")) if searchOrderInfoRsp: if searchOrderInfoRsp.find("您还没有相关订单哦") != -1: if session.FastType is 1: # 如果是查订单的话,就只查一次 U.Logging.info("账号:{} 无待付款订单".format( session.userInfo.get("user", ""))) break else: time.sleep(5) elif searchOrderInfoRsp.find("订单号:") != -1: orderRe = re.compile(r'order:\[{"order_id":"(\S+)","uid":') orderId = re.search(orderRe, searchOrderInfoRsp).group(1) orderDetail( session, orderId, ) else: U.Logging.error("账号:{}订单查询失败".format( session.userInfo.get("user", "")))
def createOrderThread(data, session): """ 提交订单线程 :param data: :param session: :return: """ U.Logging.info("订单线程{}启动..".format(session.userInfo.get("user", ""))) orderCreateUrls = urls.get("orderCreate", "") if session.orderType is 0 else urls.get( "orderCreate2", "") # 如果是下单接口2,就要用对应2的下单接口 createOrderRsp = session.httpClint.send(orderCreateUrls, data) if createOrderRsp and createOrderRsp.get("success", "") == "订单提交成功": U.Logging.info("账号: {} {}".format(session.userInfo.get("user", ""), createOrderRsp.get("success", ""))) sendEmail("(接口返回成功,无订单号)", session.userInfo.get("user", ""), session.email) session.orderDone = True else: U.Logging.info("账号: {} {}".format(session.userInfo.get("user", ""), createOrderRsp))
def cartRemove(session, goods_id): """ 删除购物车中所有商品 :param session: :return: """ data = {"ident[]": goods_id} cartRemoveRps = session.httpClint.send(urls.get("cartRemove" ""), data) if cartRemoveRps.get("result", "") == "success": goods_id = cartRemoveRps["data"]["objects"]["goods"][0]["obj_ident"] U.Logging.info("当前删除购物车商品id为: {}".format(goods_id)) cartRemove(session, goods_id) elif cartRemoveRps.get("error", "") == "购物车为空": U.Logging.error("购物车信息返回: {}".format(cartRemoveRps))
def receiver(session): """ 获取收货地址 :param session: :return: """ U.Logging.info("账号:{} 查询线程开始启动...".format(session.userInfo.get("user", ""))) receiverRsp = session.httpClint.send(urls.get("receiver", "")) if receiverRsp: receiverRe = re.compile(r'lists:\[{"addr_id":"(\S+)","uid":') session.addrId = re.search(receiverRe, receiverRsp).group(1) else: U.Logging.info("查询收货地址失败")
def joinCreateOrder(session): """ 进入下单页 :return: """ U.Logging.info("账号: {} cookie 已种植,正在下单".format( session.userInfo.get("user", ""))) while not session.orderDone: joinCreateOrderUrls = urls.get("checkOrderFast", "") joinCreateOrderRsp = session.httpClint.send(joinCreateOrderUrls) cartMd5Re = re.compile(r'cart_md5:"(\S+)"') tokenRe = re.compile(r"'token':'(\S+)'") try: cartMd5 = re.search(cartMd5Re, joinCreateOrderRsp).group(1) token = re.search(tokenRe, joinCreateOrderRsp).group(1) session.httpClint.get_cookies() createOrder(session, cartMd5, token) except (TypeError, AttributeError): try: jsonJoinCreateOrderRsp = json.loads(joinCreateOrderRsp) U.Logging.info(jsonJoinCreateOrderRsp.get("error")) except (JSONDecodeError, TypeError): U.Logging.info(joinCreateOrderRsp)
def getVcode(session): """ 获取验证码 :return: """ U.Logging.info("识别验证码线程启动...") # if session.isFastSnap: # while time.strftime('%H:%M:%S', time.localtime(time.time())) < session.checkVCodeTime: # time.sleep(0.05) # U.Logging.info("抢购时间点,开始自动打码") vcodeUrls = copy.copy(urls.get("vcode", "")) vcodeUrls["req_url"] = vcodeUrls["req_url"].format( session.loginData.get("member_id")) while True: if session.orderDone: break U.Logging.info("用户{}: 正在缓存验证码".format(session.userInfo.get("user", ""))) VcodeRsp = session.httpClint.send(vcodeUrls) U.Logging.info("用户{}: 缓存验证码成功".format(session.userInfo.get("user", ""))) for _ in range(4000): # if session.VCode == "": # 如果检测到验证码识别失败了,立即重新识别验证码 # break if session.VCode == "": if session.isFastSnap is 1 and session.isStock: checkVCode(session, VcodeRsp) elif session.isFastSnap is 0: checkVCode(session, VcodeRsp) else: time.sleep(0.01) else: time.sleep(0.01) session.VCode = "" # 设置验证码 U.Logging.warn("用户{}: 验证码识别有效期超过45秒,正在重新识别".format( session.userInfo.get("user", "")))