npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-wx-third

v1.1.8

Published

微信第三方平台对接,实现小程序批量发布/一键发布

Readme

node-wx-third

微信第三方平台 Node 封装,可用于代商家小程序授权、代码上传、审核发布等。

微信文档:第三方平台

安装

npm install node-wx-third

统一返回格式

所有接口都返回 Promise,微信业务错误不会走 catch,而是 resolve 下面两种结构:

成功:

{ code: 200, result: { /* 微信返回的数据 */ } }

失败(参数校验失败、网络错误、微信 errcode 非 0):

{ code: 409, message: '错误说明', errcode: 40001 } // errcode 仅微信接口失败时存在

建议这样取结果:

const body = await wxThirdClient.getAccountBasicInfo(authorizer_access_token)
if (body.code !== 200) {
    // body.message
    return
}
const info = body.result

初始化

const wxThirdClient = require('node-wx-third').initClient({
    appId: '第三方平台 appid',
    appsecret: '第三方平台 appsecret',
    encodingAESKey: '消息加解密 Key',
    token: '消息校验 Token'
})

消息加解密

checkMsg(encrypt, timestamp, nonce, msg_signature)

校验微信推送消息是否合法。

| 参数 | 说明 | | --- | --- | | encrypt | 报文主体 Encrypt | | timestamp | URL 上的 timestamp | | nonce | URL 上的 nonce | | msg_signature | URL 上的 msg_signature |

返回:

{ isValid: true, msg: '消息有效' }
// 或
{ isValid: false, msg: '消息无效' }

encryption(obj)

把 JSON 转成 XML 后加密。

返回:{ result: '加密后的字符串' }

decrypt(encrypt)

解密微信推送的 Encrypt 字段,并转成 JSON。

返回示例:

{
    result: {
        AppId: 'wx550ed3a0385d4d59',
        CreateTime: '1627622264',
        InfoType: 'component_verify_ticket',
        ComponentVerifyTicket: 'ticket@@@xxxx'
    }
}

授权与令牌

getComponentAccessToken(component_verify_ticket)

用微信推送的 ticket 换第三方平台令牌。

返回 result

| 字段 | 说明 | | --- | --- | | component_access_token | 第三方平台令牌 | | expires_in | 有效期(秒),一般 7200 |

getPreAuthCode(component_access_token)

获取预授权码。

返回 result

| 字段 | 说明 | | --- | --- | | pre_auth_code | 预授权码 | | expires_in | 有效期(秒),一般 600 |

getAuthUrl(pre_auth_code, redirect_uri, auth_type, biz_appid)

拼授权链接,不请求微信。

| 参数 | 说明 | | --- | --- | | pre_auth_code | 预授权码 | | redirect_uri | 授权完成回调地址 | | auth_type | 1 仅公众号,2 仅小程序,3 都展示 | | biz_appid | 指定授权的小程序/公众号 appid |

返回 result

| 字段 | 说明 | | --- | --- | | pcUrl | PC 端授权页 | | mobileUrl | 移动端授权页 |

getAuthorizerAccessToken(component_access_token, authorization_code)

授权码换授权信息。

返回 result.authorization_info

| 字段 | 说明 | | --- | --- | | authorizer_appid | 授权方 appid | | authorizer_access_token | 接口调用令牌 | | expires_in | 有效期(秒) | | authorizer_refresh_token | 刷新令牌,需长期保存 | | func_info | 授权的权限集列表 |

refreshAuthorizerAccessToken(component_access_token, authorizer_appid, authorizer_refresh_token)

刷新商家接口调用令牌。

返回 result

| 字段 | 说明 | | --- | --- | | authorizer_access_token | 新的调用令牌 | | expires_in | 有效期(秒) | | authorizer_refresh_token | 新的刷新令牌(请覆盖保存) |

fastRegisterWeApp(component_access_token, params)

快速注册企业小程序。paramsnamecodecode_typelegal_persona_wechatlegal_persona_name,可选 component_phone

返回 result:微信原始响应,成功时通常只有 errcode / errmsg


代码模板

以下接口的 token 用 component_access_token

getTemplateDraftList(component_access_token)

返回 result.draft_list:草稿数组。

| 字段 | 说明 | | --- | --- | | draft_id | 草稿 id | | user_version | 版本号 | | user_desc | 描述 | | create_time | 创建时间 | | source_miniprogram / source_miniprogram_appid | 来源小程序 | | developer | 开发者 |

addToTemplate(component_access_token, { draft_id, template_type })

template_type0 普通模板,1 标准模板。

返回 result:成功时通常只有 errcode / errmsg

getTemplateList(component_access_token)

返回 result.template_list:模板数组,字段与草稿类似,多 template_idtemplate_type

deleteTemplate(component_access_token, { template_id })

返回 result:成功时通常只有 errcode / errmsg


代码、审核、发布

以下接口的 token 用 authorizer_access_token

commit(access_token, params)

上传代码。paramstemplate_idext_jsonuser_versionuser_desc

返回 result:成功时通常只有 errcode / errmsg

getPage(access_token)

返回 result.page_list:已上传代码的页面路径数组,如 ['pages/index/index']

getQrcode(access_token, path, filePath)

拉取体验版二维码并写到本地。path 可选,filePath 为保存路径。

返回 result:保存后的文件路径字符串。

submitAudit(access_token, params)

提交审核。params 均可选:item_listpreview_infoversion_descfeedback_infofeedback_stuffugc_declareorder_path

返回 result

| 字段 | 说明 | | --- | --- | | auditid | 审核单 id,后续查状态、加急都用它 |

getAuditStatus(access_token, { auditid })

返回 result

| 字段 | 说明 | | --- | --- | | status | 0 成功,1 被拒,2 审核中,3 已撤回,4 延后 | | reason | 拒绝或延后原因 | | screenshot | 截图 media_id,多个用 | 分隔 |

getLatestAuditStatus(access_token)

返回 result

| 字段 | 说明 | | --- | --- | | auditid | 最新审核单 id | | status | 同上 | | reason | 拒绝原因 | | screen_shot | 截图 | | user_version / user_desc | 提交时的版本号、描述 | | submit_audit_time | 提交时间 |

undoCodeAudit(access_token)

撤回审核。成功时 result 通常只有 errcode / errmsg

release(access_token)

发布已通过审核的版本。成功时 result 通常只有 errcode / errmsg

getHistoryVersion(access_token)

返回 result.version_list

| 字段 | 说明 | | --- | --- | | app_version | 小程序版本 | | user_version | 自定义版本号 | | user_desc | 描述 | | commit_time | 提交时间 |

appVersion(access_token, params)

版本回退。不传 app_version 则回退到上一版本。

成功时 result 通常只有 errcode / errmsg

getWeAppSupportVersion(access_token)

返回 result

| 字段 | 说明 | | --- | --- | | now_version | 当前最低基础库版本 | | uv_info.items | { version, percentage } 各版本用户占比 |

setWeAppSupportVersion(access_token, { version })

设置最低基础库版本。成功时 result 通常只有 errcode / errmsg

speedUpAudit(access_token, { auditid })

加急审核。成功时 result 通常只有 errcode / errmsg


体验者

token 用 authorizer_access_token

memberAuth(access_token)

返回 result.members[{ userstr }]

bindTester(access_token, { wechatid })

返回 result.userstr:对应的用户串。

unbindTester(access_token, { wechatid })

成功时 result 通常只有 errcode / errmsg


域名与隐私

token 用 authorizer_access_token

getEffectiveServerDomain(access_token, params)

返回 result:当前生效的 request / socket / upload / download 域名配置。

modifyDomain(access_token, params)

actiongetsetset 时需传 requestdomainwsrequestdomainuploaddomaindownloaddomain

返回 result:设置后的域名列表。

getEffectiveJumpDomain(access_token, params)

返回 result:当前生效的业务域名。

setWebViewDomain(access_token, params)

actiongetsetset 时需传 webviewdomain

返回 result:业务域名列表。

getPrivacySetting(access_token, { privacy_ver })

privacy_ver1 现网版,2 开发版。

返回 result:隐私协议配置,含 owner_settingsetting_list 等。

setPrivacySetting(access_token, params)

params.owner_settingparams.setting_list 必填。成功时 result 通常只有 errcode / errmsg


获取基本信息

getAccountBasicInfo(access_token)

获取已授权小程序或公众号的基本信息。

  • token 用 authorizer_access_token
  • 权限集:小程序 30,公众号 3
  • 无请求体
const body = await wxThirdClient.getAccountBasicInfo(authorizer_access_token)
if (body.code === 200) {
    console.log(body.result.nickname, body.result.principal_name)
}

成功时 result

| 字段 | 类型 | 说明 | | --- | --- | --- | | appid | string | 账号 appid | | account_type | number | 1 订阅号,2 服务号,3 小程序 | | principal_type | number | 主体类型,见下方枚举 | | principal_name | string | 主体名称 | | realname_status | number | 实名状态,见下方枚举 | | nickname | string | 账号名称 | | registered_country | number | 注册国家,1017 为中国 | | credential | string | 非个人主体的企业/组织代码 | | customer_type | number | 认证类型,未认证为 0 | | wx_verify_info | object | 微信认证信息 | | signature_info | object | 功能介绍及本月修改额度 | | head_image_info | object | 头像及本年修改额度 | | nickname_info | object | 名称及本年修改额度 |

wx_verify_info

| 字段 | 说明 | | --- | --- | | qualification_verify | 是否资质认证 | | naming_verify | 是否名称认证 | | annual_review | 是否需要年审(已资质认证才有) | | annual_review_begin_time / annual_review_end_time | 年审时间戳 |

signature_info / head_image_info / nickname_info

| 字段 | 说明 | | --- | --- | | signature / head_image_url / nickname | 当前功能介绍、头像、名称 | | modify_used_count | 已使用修改次数 | | modify_quota | 总额度 |

返回示例:

{
    code: 200,
    result: {
        errcode: 0,
        errmsg: 'ok',
        appid: 'wx355c737061e52e03',
        account_type: 3,
        principal_type: 1,
        principal_name: '深圳市xx计算机系统有限公司',
        realname_status: 1,
        wx_verify_info: {
            qualification_verify: false,
            naming_verify: false
        },
        signature_info: {
            signature: '美味助手',
            modify_used_count: 0,
            modify_quota: 5
        },
        head_image_info: {
            head_image_url: 'http://wx.qlogo.cn/mmhead/xxxx/0',
            modify_used_count: 0,
            modify_quota: 5
        },
        nickname: '美味助手',
        registered_country: 1017,
        nickname_info: {
            nickname: '美味助手',
            modify_used_count: 2,
            modify_quota: 2
        },
        credential: '91440xxxx08461136T',
        customer_type: 0
    }
}

常用枚举:

principal_type 主体类型

| 值 | 说明 | | --- | --- | | 0 | 个人 | | 1 | 企业 | | 2 | 媒体 | | 3 | 政府 | | 4 | 其他组织 |

realname_status 实名验证

| 值 | 说明 | | --- | --- | | 1 | 成功 | | 2 | 验证中 | | 3 | 失败 |

创建账号时会初始化为 2realname_status !== 1 时,账号只能调认证和账号设置相关接口。

customer_type 认证类型(未完成微信认证为 0

| 值 | 说明 | | --- | --- | | 1 | 企业 | | 2 | 企业媒体 | | 3 | 政府 | | 4 | 非盈利组织 | | 5 | 民营非企业 | | 6 | 盈利组织 | | 8 | 社会团体 | | 9 | 事业媒体 | | 11 | 事业单位 | | 12 | 个体工商户 | | 14 | 海外企业 | | 15 | 个人 |

注意:组织类型小程序发布代码后不可直接改名,需走认证;发布后 nickname_info.modify_used_count 可能为 2