def getConn(self): """ 获得链接 :return: """ logger.debug("获得链接:" + self.dbPath) return sqlite3.connect(self.dbPath)
def configure(self): """ 登录系统 :return: True/False """ self.alipay.back_to_desktop() self.alipay.open_alipay_app(self.device_id) self.alipay.jump_to_my_page() is_shop = self.alipay.is_shop() account, accountName, taobao_account = self.alipay.get_alipay_account(self.device_id) if not account or not accountName or not taobao_account: return appkey_setting = self.alipay.setting_dao.load(Command.App) if not appkey_setting: return app_secret_setting = self.alipay.setting_dao.load(Command.APP_Secret) if not app_secret_setting: return appkey = appkey_setting["v"] app_secret = app_secret_setting["v"] data = { "account": account, "accountName": accountName, "appkey": appkey, "sign": md5("account=" + account + "&accountName=" + accountName + "&appkey=" + appkey + app_secret) } login_url_setting = self.alipay.setting_dao.load(Command.Login_Url) if not login_url_setting: return if self.debug: beanret = BeanRet() beanret.success = True beanret.data = "login_success" else: beanret = post(login_url_setting['v'], data) if beanret.success: # 设置屏幕分辨率 screen_x_y = self.alipay.screen_resolution() # 设置最大重复数多少时跳出 count_Repeat_setting = self.alipay.setting_dao.load(Command.Count_Repeat) if not count_Repeat_setting: self.alipay.setting_dao.insert(Command.Count_Repeat, 3) token = str(beanret.data) account_load = self.account_dao.load_by_account(account) if account_load: self.account_dao.delete(self.device_id) self.account_dao.insert(account, appkey, token, self.device_id, screen_x_y, is_shop) logger.debug("初始化配置完成") return True, account else: return False, account
def stop(self): ''' stop thread :return: ''' logger.debug("stop thread ! ") self.is_stop = True self.join()
def get(url): # setting_dao = SettingDao() # host_setting = setting_dao.load(Command.Host) # url = host_setting["v"] + url logger.debug("请求url: " + url) response = request.urlopen(url) result = response.read().decode(encoding='utf-8') if result != None: beanret = R() beanret.to_obj(result) return beanret
def query(self, sql): """ 查询集合 :param sql: :return: """ logger.debug(sql) conn = self.getConn() cursor = conn.cursor() results = cursor.execute(sql) return results
def update(self, sql): """ 修改数据 :param sql: :return: """ logger.debug(sql) conn = self.getConn() conn.execute(sql) conn.commit() conn.close()
def insert(self, sql): """ 保存数据 :param sql: :return: """ logger.debug(sql) conn = self.getConn() conn.execute(sql) conn.commit() conn.close()
def load(self, sql): """ 查询指定一条数据 :param sql: :return: """ logger.debug(sql) conn = self.getConn() cursor = conn.cursor() results = cursor.execute(sql) obj = None for result in results: obj = result conn.close() return obj
def list_attr_value(abs_path, attr, value): """ 根据属性和值特性来查询具体的数据 :param abs_path: xml绝对位置 :param attr: 搜索属性 :param value: 属性可能的值,用的是包含查询 :return: list """ logger.debug("解析xml文件: " + abs_path) logger.debug("获取属性: " + attr) logger.debug("获取属性-值匹配: " + value) attr_list = [] root = ET.parse(abs_path).getroot() search_data_from_xml(root, attr_list, attr, value) logger.debug("解析数据: " + str(attr_list)) return attr_list
def run(self): ''' running thread :return: ''' logger.debug("running thread for device [" + self.device_id + "] ") is_connected = False is_login = False # 尝试3次如果没有设备不在线就直接退出自己 count_connected = 0 while True: if self.is_stop: logger.debug("return while") return if count_connected == 3: self.pay_sv.delete_device(self.device_id) self.is_stop = True return try: if not is_connected: is_connected = self.detect_connect() if is_connected: logger.debug("connected to device:" + self.device_id) if not is_login: is_login, alipay_account = self.configure() if is_login: is_notify = self.pay_sv.detect_alipay_notify() if self.debug: is_notify = True if is_notify: self.pay_sv.detect_income(alipay_account) else: count_connected += 1 except: is_connected = False is_login = False logger.debug("lost device: " + self.device_id) time.sleep(self.frequency)
def run(self): ''' running thread :return: ''' logger.debug("running thread for device [" + self.device_id + "] ") try: # ArtOfWar(self.device_id).run_sand() ArtOfWar(self.device_id).run() logger.debug("connected to device:" + self.device_id) except: logger.debug("lost device: " + self.device_id)
def load_detail_xml(abs_path, attr="text", attr2="content-desc"): """ 入口 :param file_name: 文件绝对位置 :return: list """ logger.debug("解析xml文件: " + abs_path) logger.debug("获取属性: " + attr) result_list = [] utf8_parser = ET.XMLParser(encoding='utf-8') root = ET.parse(abs_path, parser=utf8_parser).getroot() get_detail_data(root, result_list, attr, attr2) logger.debug("解析数据:" + str(result_list)) return result_list
def detect_income(self, alipay_account): """ 监听是否有新的支付订单 1.进入账单页面 2.读取订单列表 3.读取订单详情 4.验证订单是否重复 5.提交订单 6.缓存结果 :return: """ # 1.进入账单页面 logger.debug(">> back_to_desktop") self.alipay.back_to_desktop() # 打开支付宝 logger.debug(">> open_alipay_app") self.alipay.open_alipay_app(self.device_id) # 进入账单页面 logger.debug(">> entry_bill_list_page") self.alipay.entry_bill_list_page() # 清理过期的数据 logger.debug(">> delete_bill") self.delete_bill() # 2.读取订单列表 count_repeat = 0 logger.debug(">> 读取订单列表数据") account_load = self.account_dao.load_by_device_id(self.device_id) is_shop = account_load["is_shop"] for page in range(self.page_count): income_list = self.alipay.income_list() if income_list.__len__() <= 0: continue logger.debug(">> 解析订单详情") for income in income_list: if count_repeat == int(self.count_repeat): break # 3.读取订单详情 chick_x_y = income["click_x_y"] data = self.alipay.order_detail(chick_x_y[0], chick_x_y[1], is_shop) self.alipay.back() # 4.验证订单是否重复 order_no = data["orderNo"] bill_record = self.bill_dao.load(order_no) if bill_record: logger.debug("重复单跳过,进行下一个") count_repeat += 1 continue # 5.提交订单 setting_dao = SettingDao() appkey_setting = setting_dao.load(Command.App) if not appkey_setting: break appkey = appkey_setting["v"] account_dao = AccountDao() account_user = account_dao.load_by_account_appkey(alipay_account, appkey) if not account_user: break app_secret_setting = self.alipay.setting_dao.load(Command.APP_Secret) if not app_secret_setting: return app_secret = app_secret_setting["v"] user = data["user"] money = data["money"] state = data["state"] time_str = data["time"] # md5(money=&orderNo=&state=&time=&user= [app_secret]) text = "money=" + str(money) + "&orderNo=" + str(order_no) + "&state=" + str(state) + \ "&time=" + str(time_str) + "&user="******"sign"] = sign header = { 'authorization': account_user["token"] } new_record_Url = self.alipay.setting_dao.load(Command.New_Record_Url) if not new_record_Url: return if self.debug: beanret = BeanRet() beanret.success = True beanret.data = "login_success" else: beanret = post(new_record_Url["v"], data, header) if beanret.success: # 6.缓存结果 bill_obj = self.bill_dao.load(order_no) if not bill_obj: account = self.account_dao.load_by_device_id(self.device_id) if account: self.bill_dao.insert(order_no, user, money, state, sign, time_str, account["account"]) logger.debug("新增一单: " + user) # 翻页计算 if self.page_count - 1 - page > 0: income_0 = income_list[0] income_last = income_list[income_list.__len__() - 1] x1_y1 = income_0["click_x_y"] x2_y2 = income_last["click_x_y"] if x2_y2[1] >= x1_y1[1]: self.alipay.scroll_down(x1_y1[0], 1080, x1_y1[0], 480) else: self.alipay.scroll_down(x1_y1[0], 1080, x1_y1[0], x1_y1[1]) time.sleep(.5) self.alipay.back_to_desktop() time.sleep(.3)
def detect_connect(self): logger.debug("设备链接检测") return self.alipay.detect_connect(self.device_id)