← Back to Skills Marketplace
wangjinliang1991

huazhuhelper

by wangjinliang1991 · GitHub ↗ · v1.0.3 · MIT-0
cross-platform ⚠ suspicious
84
Downloads
0
Stars
0
Active Installs
4
Versions
Install in OpenClaw
/install huazhuhelper
Description
查询华住酒店列表。通过华住OpenAPI获取酒店数据,需要用户提供clientId和clientSecret进行OAuth2认证。当用户提到华住酒店、酒店列表、华住API、查酒店时使用。
README (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.pyhuazhuhelper_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
Usage Guidance
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.
Capability Tags
requires-oauth-tokenrequires-sensitive-credentials
Capability Assessment
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.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install huazhuhelper
  3. After installation, invoke the skill by name or use /huazhuhelper
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
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.
Metadata
Slug huazhuhelper
Version 1.0.3
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 4
Frequently Asked Questions

What is huazhuhelper?

查询华住酒店列表。通过华住OpenAPI获取酒店数据,需要用户提供clientId和clientSecret进行OAuth2认证。当用户提到华住酒店、酒店列表、华住API、查酒店时使用。 It is an AI Agent Skill for Claude Code / OpenClaw, with 84 downloads so far.

How do I install huazhuhelper?

Run "/install huazhuhelper" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is huazhuhelper free?

Yes, huazhuhelper is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does huazhuhelper support?

huazhuhelper is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created huazhuhelper?

It is built and maintained by wangjinliang1991 (@wangjinliang1991); the current version is v1.0.3.

💬 Comments