← 返回 Skills 市场
huazhuhelper
作者
wangjinliang1991
· GitHub ↗
· v1.0.3
· MIT-0
84
总下载
0
收藏
0
当前安装
4
版本数
在 OpenClaw 中安装
/install huazhuhelper
功能描述
查询华住酒店列表。通过华住OpenAPI获取酒店数据,需要用户提供clientId和clientSecret进行OAuth2认证。当用户提到华住酒店、酒店列表、华住API、查酒店时使用。
使用说明 (SKILL.md)
华住酒店列表查询
查询华住OpenAPI的酒店列表,自动处理OAuth2认证和Token管理。
前置条件
向用户询问以下信息(必需):
- clientId: 华住分配的客户端ID
- clientSecret: 华住分配的客户端密钥
- distributorId: 渠道Code(默认 MEITUAN,可选)
工作流程
Step 1: 安装依赖
pip install requests
Step 2: 确认环境
- 测试环境(默认):
https://test-oauth2-api.huazhu.com - 生产环境:
https://openapi.huazhu.com
Step 3: 运行查询脚本
在用户项目根目录执行以下 Python 代码(将凭证替换为用户提供的真实值):
import base64, time, uuid, requests
# === 用户凭证 ===
CLIENT_ID = "用户提供的clientId"
CLIENT_SECRET = "用户提供的clientSecret"
DISTRIBUTOR_ID = "MEITUAN"
IS_TEST = True
# === Step 1: 获取 Token ===
auth_domain = "https://test-oauth2-api.huazhu.com" if IS_TEST else "https://openapi.huazhu.com"
biz_domain = "http://test-crs-distributor.huazhu.com" if IS_TEST else "https://openapi.huazhu.com"
raw_cred = f"{CLIENT_ID}:{CLIENT_SECRET}"
basic_auth = f"Basic {base64.b64encode(raw_cred.encode()).decode()}"
headers = {
"Authorization": basic_auth,
"Content-Type": "application/x-www-form-urlencoded",
}
if IS_TEST:
headers["X-Lane-Tag"] = "preview"
resp = requests.post(
f"{auth_domain}/oauth/token",
data={"scope": "ALL", "grant_type": "client_credentials"},
headers=headers,
timeout=10,
)
resp.raise_for_status()
token = resp.json()["access_token"]
print(f"Token: {token[:20]}...")
# === Step 2: 查询酒店列表 ===
hotel_headers = {
"Authorization": f"Bearer {token}",
"distributorId": DISTRIBUTOR_ID,
"timestamp": str(int(time.time() * 1000)),
"traceId": str(uuid.uuid4()),
}
resp = requests.get(f"{biz_domain}/hotels", headers=hotel_headers, timeout=10)
resp.raise_for_status()
data = resp.json()
hotels = data if isinstance(data, list) else data.get("content", data.get("data", []))
print(f"共 {len(hotels)} 个酒店:")
for i, h in enumerate(hotels[:20], 1):
print(f" {i}. {h.get('hotelName','')} (ID: {h.get('hotelId','')})")
if len(hotels) > 20:
print(f" ... 还有 {len(hotels)-20} 个")
使用本项目模块
本 Skill 安装后,脚本位于 {baseDir}/scripts/ 目录下。
方式一:直接使用模块(推荐)
import sys
sys.path.insert(0, "{baseDir}/scripts")
from huazhuhelper_auth import HuazhuhelperAuth
from huazhuhelper_hotel import HuazhuhelperHotel
# distributor_id 默认为 MEITUAN,可省略
auth = HuazhuhelperAuth(
client_id="用户的clientId",
client_secret="用户的clientSecret",
is_test=True,
)
hotel = HuazhuhelperHotel(auth)
hotels = hotel.get_hotel_list()
for h in hotels:
print(h.get("hotelName"), h.get("hotelId"))
其中 {baseDir} 是 Skill 安装后的根目录,通常为 ~/.openclaw/skills/huazhuhelper。
方式二:直接复制脚本代码
如果不想安装 Skill,可以直接复制以下两个脚本文件的内容到您的项目中:
脚本1: huazhuhelper_auth.py(认证模块)
"""华住OpenAPI认证模块 - 获取access_token"""
import base64
import time
import requests
class HuazhuhelperAuth:
"""华住认证客户端"""
def __init__(self, client_id: str, client_secret: str,
distributor_id: str = "MEITUAN", is_test: bool = True):
"""
Args:
client_id: 客户端ID(从华住申请)
client_secret: 客户端密钥(从华住申请)
distributor_id: 渠道Code(默认 MEITUAN)
is_test: 是否测试环境
"""
self.client_id = client_id
self.client_secret = client_secret
self.distributor_id = distributor_id
self.is_test = is_test
self.auth_domain = "https://test-oauth2-api.huazhu.com" if is_test else "https://openapi.huazhu.com"
self._token = None
self._expires_at = 0
def _basic_auth(self) -> str:
"""将 clientId:clientSecret 进行Base64编码"""
raw = f"{self.client_id}:{self.client_secret}"
encoded = base64.b64encode(raw.encode()).decode()
return f"Basic {encoded}"
def get_token(self) -> str:
"""获取access_token(自动缓存,到期前120秒刷新)"""
if self._token and time.time() \x3C self._expires_at - 120:
return self._token
headers = {
"Authorization": self._basic_auth(),
"Content-Type": "application/x-www-form-urlencoded",
}
if self.is_test:
headers["X-Lane-Tag"] = "preview"
resp = requests.post(
f"{self.auth_domain}/oauth/token",
data={"scope": "ALL", "grant_type": "client_credentials"},
headers=headers,
timeout=10,
)
resp.raise_for_status()
data = resp.json()
if "access_token" not in data:
raise Exception(f"获取token失败: {data}")
self._token = data["access_token"]
self._expires_at = time.time() + data.get("expires_in", 3600)
return self._token
脚本2: huazhuhelper_hotel.py(酒店查询模块)
"""华住OpenAPI酒店查询模块"""
import time
import uuid
import requests
from huazhuhelper_auth import HuazhuhelperAuth
class HuazhuhelperHotel:
"""华住酒店查询客户端"""
def __init__(self, auth: HuazhuhelperAuth,
biz_domain: str = "http://test-crs-distributor.huazhu.com"):
self.auth = auth
self.biz_domain = biz_domain
def get_hotel_list(self) -> list:
"""
获取酒店列表
Returns:
list[dict],每个元素包含 hotelId、hotelName 等字段
"""
token = self.auth.get_token()
headers = {
"Authorization": f"Bearer {token}",
"distributorId": self.auth.distributor_id,
"timestamp": str(int(time.time() * 1000)),
"traceId": str(uuid.uuid4()),
}
resp = requests.get(f"{self.biz_domain}/hotels", headers=headers, timeout=10)
if not resp.ok:
raise Exception(
f"酒店列表请求失败 [HTTP {resp.status_code}]: {resp.text}"
)
data = resp.json()
if isinstance(data, list):
return data
code = data.get("code")
if code and code != 1000:
raise Exception(f"API错误 [code={code}]: {data.get('message', '未知错误')}")
return data.get("content", data.get("data", []))
使用示例
将以上两个脚本保存为 huazhuhelper_auth.py 和 huazhuhelper_hotel.py,然后:
from huazhuhelper_auth import HuazhuhelperAuth
from huazhuhelper_hotel import HuazhuhelperHotel
# 创建认证实例(distributor_id 默认为 MEITUAN)
auth = HuazhuhelperAuth(
client_id="573d8245-5ec0-4172-92aa-5e1a8de1e507",
client_secret="您的clientSecret",
is_test=True # 测试环境设为True,生产环境设为False
)
# 查询酒店列表
hotel_client = HuazhuhelperHotel(auth)
hotels = hotel_client.get_hotel_list()
print(f"共查询到 {len(hotels)} 个酒店")
for h in hotels[:10]: # 显示前10个
print(f" - {h.get('hotelName')} (ID: {h.get('hotelId')})")
API 请求头说明
获取 Token
| 头 | 值 | 说明 |
|---|---|---|
| Authorization | Basic {base64(clientId:secret)} |
clientId:secret 的 Base64 编码 |
| Content-Type | application/x-www-form-urlencoded |
- |
| X-Lane-Tag | preview |
仅测试环境需要 |
查询酒店
| 头 | 值 | 说明 |
|---|---|---|
| Authorization | Bearer {token} |
上一步获取的token |
| distributorId | 渠道Code | 如 MEITUAN |
| timestamp | 毫秒时间戳 | 自动生成 |
| traceId | UUID | 自动生成 |
错误处理
- 401: clientId 或 clientSecret 错误
- 403: IP 不在白名单,需联系华住添加
- Token过期: 重新执行 Step 1 获取新 token
安全使用建议
Review before installing. Use only test credentials with the default test configuration, avoid sending production tokens to the default HTTP business endpoint, do not paste long-lived secrets into chat or source files, and remove token printing before running this in shared terminals, CI, or production.
能力标签
能力评估
Purpose & Capability
The stated purpose, querying Huazhu hotel lists through Huazhu OpenAPI with OAuth2 client credentials, matches the code and instructions.
Instruction Scope
The skill asks for clientId and clientSecret and shows credential-based code, but does not give clear handling guidance for secrets and includes an example that prints the first part of an access token.
Install Mechanism
The package contains only SKILL.md and instructs users to install the common Python requests dependency; no hidden install scripts or bundled executable files were present.
Credentials
The test business endpoint is plain HTTP by default while the code sends a Bearer token to it, which is not proportionate for OAuth-protected API traffic and is not clearly warned about.
Persistence & Privilege
The example module caches the OAuth token only in memory until expiry; no file persistence, background workers, privilege escalation, or destructive actions were found.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install huazhuhelper - 安装完成后,直接呼叫该 Skill 的名称或使用
/huazhuhelper触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.3
- Removed README.md file from the project.
- No other functional or documentation changes.
- Internal cleanup; usage and API remain unchanged.
v1.0.2
- Initial public release with core features.
- Added OAuth2 authentication and automated token management for Huazhu OpenAPI.
- Provided sample scripts and ready-to-use Python modules (`huazhuhelper_auth.py`, `huazhuhelper_hotel.py`) for hotel list queries.
- Included detailed usage instructions for both module import and direct script use.
- Described headers, error handling, and environment switching (test/production).
v1.0.1
- 增加了 .gitignore 和项目配置文件 (.idea 相关),便于开发环境管理
- 移除了 skill-card.md 文件
- distributorId 参数现在为可选项,默认值为 MEITUAN,简化模块使用方式
- 更新文档,明确 distributorId 可省略,优化使用示例说明
v1.0.0
Initial release of huazhuhelper.
- Provides hotel list query via Huazhu OpenAPI.
- Handles OAuth2 authentication and token management automatically.
- Prompts user for clientId, clientSecret, and distributorId (defaults to MEITUAN).
- Includes detailed usage steps, example scripts, and error handling guidance.
- Supports both test and production environments.
元数据
常见问题
huazhuhelper 是什么?
查询华住酒店列表。通过华住OpenAPI获取酒店数据,需要用户提供clientId和clientSecret进行OAuth2认证。当用户提到华住酒店、酒店列表、华住API、查酒店时使用。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 84 次。
如何安装 huazhuhelper?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install huazhuhelper」即可一键安装,无需额外配置。
huazhuhelper 是免费的吗?
是的,huazhuhelper 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
huazhuhelper 支持哪些平台?
huazhuhelper 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 huazhuhelper?
由 wangjinliang1991(@wangjinliang1991)开发并维护,当前版本 v1.0.3。
推荐 Skills