def __device_online(self, ip_list): """ 设备上线告知云端 :param ip_list: 设备ip :return: """ http.post("http://xxx.com/device/online", data={ "ip": ip_list })
def post_wechat_info(self, myself_info, contacts, groups): """ 初始化时向云端发送基础数据 """ data = { "myselfInfo": myself_info, "contact": contacts, "group": groups, "ip": str(self.ip), "serialno": str(self.wechat.serial) } http.post("http://xxxx.com/xxx.shtml", data=data)
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 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)