68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""实测美团定位 SDK 的 network 通道, 看能否按 IP 返回位置。
|
|
|
|
来源: h5.waimai.meituan.com 首页包 index.0f6b961e.js 里的定位 SDK
|
|
接口 : POST {mars.meituan.com}/locate/v3/sdk/loc
|
|
body : 不带 location 字段 -> 服务端按请求来源 IP 定位
|
|
"""
|
|
import json
|
|
import sys
|
|
import time
|
|
import warnings
|
|
|
|
import requests
|
|
|
|
warnings.filterwarnings("ignore")
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8") # 终端默认 GBK, 不改打印中文乱码
|
|
|
|
# 首页定位 SDK 的配置 (index 包内 G 对象)
|
|
LOC_KEY = "48779dc57b66313d303b72616ada6c19" # X-Request-Source
|
|
LOC_PROJECT = "wm_open_h5" # X-Request-Agent 里的 project
|
|
LOC_VERSION = "0.8.15" # Location-SDK 版本
|
|
LOC_PREJECT_VERSION = "2.0" # X-Request-Agent 里的 project 版本
|
|
LOC_URL = "https://mars.meituan.com/locate/v3/sdk/loc" # prod 域名
|
|
UUID = "2096194299624722486" # 从抓包 cookie 里取的 _lxsdk, 可换
|
|
|
|
headers = {
|
|
"X-Request-Source": LOC_KEY,
|
|
"X-Request-Medium": "uuid:" + UUID,
|
|
"X-Request-Pivot": "meituan:",
|
|
"X-Request-ID": str(int(time.time() * 1000)),
|
|
"X-Request-Agent": "Location-SDK/%s %s/%s" % (LOC_VERSION, LOC_PROJECT, LOC_PREJECT_VERSION),
|
|
"X-Request-Platform": "6",
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
# 不带 location 就是纯 IP 定位; need_address=1 让服务端返回城市/地址
|
|
body = {
|
|
"need_openCity": 1, # 1=meituan 2=dianping 3=all
|
|
"need_address": True,
|
|
"coord_type": "GCJ02",
|
|
}
|
|
|
|
# 带坐标时的形态 (对照用): 有 location 就是"按坐标逆地理", 不是 IP 定位
|
|
# body_with_geo = {
|
|
# "need_openCity": 1,
|
|
# "need_address": True,
|
|
# "coord_type": "GCJ02",
|
|
# "location": {"id": 1, "longitude": 113.299172, "latitude": 23.129393, "accuracy": -1, "type": "GCJ02", "source": "network"},
|
|
# }
|
|
|
|
|
|
def run_ip_locate(prox):
|
|
req = requests.post(LOC_URL, headers=headers, data=json.dumps(body), verify=False, timeout=20, proxies=prox)
|
|
resp_data = req.json()
|
|
location = resp_data["data"]["location"]
|
|
address = resp_data["data"]["address"]
|
|
print("IP :", prox,'\t','位置 :', location['latitude'], location['longitude'], address["city"], address["district"], address["township"], address["detail"])
|
|
return req
|
|
|
|
|
|
if __name__ == '__main__':
|
|
ip_list = [
|
|
{"http": "http://uuvg:uuvgt@2p3c.smart.51tcp.net:21209", "https": "http://uuvg:uuvgt@2p3c.smart.51tcp.net:21209"},
|
|
]
|
|
for ip in ip_list:
|
|
run_ip_locate(ip)
|