import json import requests from flask import request, Blueprint API_INFO = Blueprint("API_INFO", __name__) @API_INFO.route('/apis/info/qq', methods=["POST"]) def api_info_fromQQToAll(): data = request.get_data().decode("utf-8") if data=="": data= request.values.to_dict() print(type(data), data) else: data = json.loads(data) try: qq = data["qq"] print("test:",qq) except: return {"code": -1, "message": "请输入正确的QQ账号", "data": {}} if "/" in qq: result_all = [] # 批量获取 qqlist = qq.split("/") for i in qqlist: print("===========") print("==查询QQ号==", i) result = API_FromQQtoALl(i) print("==查询结果==:", result) if result["code"] != 1: qqlist.append(i) # 失败了,就把这个QQ号添加进去,到时候重新执行一次 但是这样容易出现一直请求失败然后导致死循环问题 else: result_all.append(result["data"]) return {"code": 1, "message": "sucess", "data": result_all} return API_FromQQtoALl(qq) # 功能方法 - 取中间文本 def getCenterContent(s, l, r): text = s start_text = l end_text = r start_index = text.find(start_text) end_index = text.find(end_text) if start_index >= 0 and end_index >= 0: middle_text = text[start_index + len(start_text):end_index] return middle_text else: return "" # 未完成的接口 因为这个API获取到的QQ名称是乱码 def API_FromQQToQQName(QQNumber): print(QQNumber) response = requests.request("POST", "https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg", data={"uins": QQNumber}, headers={ # "Accept-Encoding":"", "Content-Type": 'application/json; charset=UTF-8' }) print(response.headers["Content-Type"]) # print(response.content.decode("utf-8").encode('raw_unicode_escape')) # print(response.content) response = response.text print(response) # encoding = chardet.detect(response)["encoding"] # print(encoding) # response = response.decode(encoding) try: response = getCenterContent(response, "portraitCallBack(", ")") if response == "": return "" response = json.loads(json.loads(json.dumps(response))) info = response[str(QQNumber)] name = info[6] name = name.encode("utf-8").decode("utf-8") print(name) return info[0], name except Exception as e: print(e) return {"code": -1, "message": "服务器异常,请重试", "data": {}} # 通过QQ获取电话 def API_FromQqToTel(QQNumber): # 获取手机号 response = requests.request("POST", "https://zy.xywlapi.cc/qqapi", data={"qq": QQNumber}).content.decode("utf-8") try: # print(response) response = json.loads(json.loads(json.dumps(response))) print(response) # print(response) if response["status"] == 200: return {"code": 1, "message": response["message"], "data": { "qq": QQNumber, "tel": response["phone"], "address": response["phonediqu"] }} elif response["status"] == 500: return {"code": 0, "message": response["message"], "data": {}} else: return {"code": -1, "message": response["message"], "data": {}} except Exception as e: print('==============Err Info Start==================') print(e,'\n',str(e)) print(response) print('==============Err Info End==================') return {"code": -1, "message": "服务器异常,请重试", "data": {}} # 通过电话获取QQ def API_FromTelToQQ(TelNumber): response = requests.request("POST", "https://zy.xywlapi.cc/qqphone", data={"phone": TelNumber}).content.decode( "utf-8") try: # print(response) response = json.loads(json.loads(json.dumps(response))) # print(response) if response["status"] == 200: return {"code": 1, "message": response["message"], "data": { "qq": response["qq"], "tel": TelNumber, "address": response["phonediqu"] }} elif response["status"] == 500: return {"code": 0, "message": response["message"], "data": {}} else: return {"code": -1, "message": response["message"], "data": {}} except: return {"code": -1, "message": "服务器异常,请重试", "data": {}} def API_FromTelToWeiBo(TelNumber): response = requests.request("POST", "https://zy.xywlapi.cc/wbphone", data={"phone": TelNumber}).content.decode( "utf-8") try: # print(response) response = json.loads(json.loads(json.dumps(response))) # print(response) if response["status"] == 200: return {"code": 1, "message": response["message"], "data": { "id": response["id"], "tel": TelNumber, "address": response["phonediqu"] }} elif response["status"] == 500: return {"code": 0, "message": response["message"], "data": {}} else: return {"code": -1, "message": response["message"], "data": {}} except: return {"code": -1, "message": "服务器异常,请重试", "data": {}} # 功能聚合接口,整合上面的接口,实现通过QQ号获取到全部信息 def API_FromQQtoALl(QQNumber): res = API_FromQqToTel(QQNumber) qq = QQNumber if res["code"] == 1: tel = res["data"]["tel"] address = res["data"]["address"] res2 = API_FromTelToWeiBo(tel) if res2["code"] == 1: id = res2["data"]["id"] else: id = "无" return {"code": 1, "message": "success", "data": { "qq": qq, "tel": tel, "id": id, "address": address }} elif res["code"] == 0: return {"code": 1, "message": "success", "data": { "qq": qq, "tel": '无', "id": '无', "address": '无' }} else: return {"code": -1, "message": "服务器异常,请重试。一直失败请联系萌狼蓝天维护(哔哩哔哩/CSDN 私信 萌狼蓝天)", "data": {}}