@youdaa/wechat-open-sdk
v1.3.7
Published
WeChat Auth Hub (WAH) Node.js Client SDK
Readme
@youdaa/wechat-open-sdk
微信开放中台 (WeChat Auth Hub, WAH) 客户端 Node.js SDK。提供自动签名、参数鉴权和接口请求封装,助力子项目极速接入。
安装
npm install @youdaa/wechat-open-sdk或通过 Git 直接安装:
npm install git+https://git.your-server.com/youdian/wechat-open-sdk.git#v1.0.0使用指南
1. 初始化
import { WahClient, WAH_API_BASE, WAH_WEB_BASE } from '@youdaa/wechat-open-sdk';
const wahClient = new WahClient({
clientAppId: '您的 WAH_CLIENT_APPID',
clientAppSecret: '您的 WAH_CLIENT_APPSECRET',
// 平台地址已内置:WAH_API_BASE / WAH_WEB_BASE,无需传入
});2. 常用功能调用
获取商户微信授权扫码预授权 URL
const { wechatAuthUrl } = await wahClient.getPreAuthUrl('merchant_998');获取商户授权绑定状态
const { isBound, nickName, authorizerAppId } = await wahClient.getAuthStatus('merchant_998');生成 iframe 嵌入面板 URL(紧凑模式 + 主题同步)
const { timestamp, nonce, signature } = wahClient.signStatusRequest('merchant_998');
const iframeUrl = wahClient.buildIframePanelUrl({
merchantId: 'merchant_998',
timestamp,
nonce,
signature,
theme: {
uiTheme: 'dark', // light | dark 两套预置
themeColor: 'c9a227', // 可选,覆盖品牌主色
},
});代已绑定的公众号发送模板消息
const res = await wahClient.sendTemplateMessage({
authorizer_appid: '商户绑定的公众号 AppID',
touser: '接收粉丝的 OpenID',
template_id: '模板消息 ID',
url: 'https://m.yourdomain.com/detail',
data: {
first: { value: '您有新的订单通知。', color: '#173177' },
keyword1: { value: '微信中枢 SDK', color: '#173177' }
}
});
console.log('发送成功,微信消息 ID 为:', res.msgid);获取微信网页静默授权 OpenID
const { openid } = await wahClient.getOauthOpenId('temp_code_xxxxx');代公众号计算 JSSDK 签名
const signatureConfig = await wahClient.getJssdkSignature('authorizerAppId', '当前网页完整URL');开发与发布
如果您是维护者,并且需要更新、编译并发布此 SDK,请参考 RELEASE.md 获取详细的发布指南。
