def do_login_one(): """ 使用账号登录 :param data: :return: """ ip_res = get_zhima_ip() if ip_res.get("status") == 30: return ip_res ip = { "http": ip_res.get("http"), "https": ip_res.get("https"), } res_r = RedisClientClass().s_data_all("TC_account") if len(res_r) == 0: return {"status": 3000, "msg": "无添加账号可以使用"} for data in res_r: print(data) param = {"user": data} try: ret = Login(params=param, ip=ip).do_login_by_one() resp = {"登录账号": data, "返回信息": ret} RedisClientClass().srem_delete("TC_account", data) Journal().save_journal_login(massage=json.dumps(resp)) except (ConnectionError, ConnectTimeout, ReadTimeout, ProxyError, Error, WantReadError, MaxRetryError, NewConnectionError): ret = {'status': 11, 'msg': "请换ip"} return ret except Exception: ret = {'status': 500, 'msg': traceback.format_exc()} resp = {"登录信息": data, "响应数据": ret} Journal().save_journal_login(massage=json.dumps(resp), level="error") return ret
def do_login_log(data): try: ret = Login(params=data).do_login() resp = {"登录信息": data, "返回信息": ret} Journal().save_journal_login(massage=json.dumps(resp)) except Exception: ret = {'status': 500, 'msg': traceback.format_exc()} resp = {"登录信息": data, "响应数据": ret} Journal().save_journal_login(massage=json.dumps(resp), level="error") return json.dumps(ret)
def register_tc(): log = '' params = json.loads(request.get_data(as_text=True)) print(params) try: ret = Order(params=params).do_order_login() resp = {"请求数据": params, "响应数据": ret} Journal().save_journal_order(massage=json.dumps(resp)) except Exception: ret = {'code': 500, 'msg': traceback.format_exc()} resp = {"请求数据": params, "响应数据": ret} Journal().save_journal_order(massage=json.dumps(resp), level="error") log = log + str(ret) + '\n' __write_log__(log, tag="order") return json.dumps(ret)
def get_tc_app_code(self): """ 创建APP授权code任务 :return: """ url = "http://221.229.197.219:8090/api/apiauth" data = { "userid": "3333516394", "platform": "1", "appid": "3908282825", "vxid": "" } headers = {"User-Agent": self.ua} try: res = requests.post(url=url, json=data, headers=headers, timeout=10) res_json = res.json() ret = {"创建app授权任务": res_json} Journal().save_journal_app_empower_taskid(massage=json.dumps(ret)) if res_json.get("err_code") == 1: return res_json.get("taskid") else: return { "status": 3, "msg": "授权任务创建失败!,获取taskid失败", "err_msg": res_json.get("err_msg") } except Exception: return { "status": 3, "msg": "授权任务创建失败!获取taskid失败", }
def register_tc(): log = '' params = json.loads(request.get_data(as_text=True)) print(params) vxid = params.get("vx_token").get("vxid") print("vxid", vxid) phone = params.get("token").get("loginName") try: ret = wechat_code(vxid=vxid, phone=phone) print(ret) resp = {"请求数据": params, "响应数据": ret} Journal().save_journal_wechat_code(massage=json.dumps(resp)) except Exception: ret = {'code': 500, 'msg': traceback.format_exc()} resp = {"请求数据": params, "响应数据": ret} Journal().save_journal_wechat_code(massage=json.dumps(resp), level="error") log = log + str(ret) + '\n' __write_log__(log, tag="wechat_code") return json.dumps(ret)
def do_register_log(): pwd = random_password() phone = GetNumberCodeByBM(aip_token).do_get_phone_number() if isinstance(phone, dict): return phone res_phone = get_get_user_do(phone=phone) if res_phone.get("status") in (0, 2): return { "status": 1, "msg": "该账号已存在账号中心", } data = {"user": phone, "password": pwd} print(data) try: ret = Register(params=data).do_register_two() print(ret) resp = {"注册信息": data, "返回信息": ret} Journal().save_journal_register(massage=json.dumps(resp)) except Exception: ret = {'status': 500, 'msg': traceback.format_exc()} resp = {"注册信息": data, "响应数据": ret} Journal().save_journal_register(massage=json.dumps(resp), level="error") return json.dumps(ret)
def get_result_code(self, task_id): """ 获取授权code :param task_id: :return: 授权任务的id """ url = "http://221.229.197.219:8090/api/apiauthresult" data = {"userid": "3333516394", "taskid": task_id} headers = {"User-Agent": self.ua} res = requests.post(url=url, json=data, headers=headers) res_json = res.json() ret = {"授权结果请求数据": data, "授权结果返回数据": res_json} Journal().save_journal_app_empower_result(massage=json.dumps(ret)) if res_json.get("err_code") == 1: if res_json.get("task_ret") == 1: vxid_1 = res_json.get("vxid") code_str = re.findall(r"code=(.*?)&state=", res_json.get("auth_str"))[0] vxid = base64.b64encode(res_json.get("vxid").encode()).decode() return code_str, vxid, task_id, vxid_1 else: return { "status": 1, "msg": "授权正在进行中,请重新请求", } elif res_json.get("err_code") == 0 and res_json.get("task_ret") == 0: return { "status": 2, "msg": "重新创建授权任务", } else: log_wechat_author(taskid=task_id, app_id="3908282825", success="1", vxid="") return { "status": 3, "msg": "授权任务创建失败!", "err_msg": res_json.get("err_msg") }
def get_wechat_tc_code(self, vxid, phone=""): """ 创建微信小程序授权code任务 :param vxid: 微信id :return: """ url = "http://221.229.197.219:8090/api/apiminiauth" data = { "userid": "3333516394", "appid": "3117146270", "vxid": vxid, } headers = {"User-Agent": self.ua} try: res = requests.post(url=url, json=data, headers=headers, timeout=10) res_json = res.json() ret = {"创建任务请求数据": data, "创建任务返回结果": res_json} Journal().save_journal_wechat_empower_taskid( massage=json.dumps(ret)) print(res_json) if res_json.get("err_code") == 1: return res_json.get("taskid") else: return { "status": 3, "msg": "授权任务创建失败!", "err_msg": res_json.get("err_msg") } except Exception: return { "status": 3, "msg": "授权任务创建失败!", }