mina-admin
微信小程序公众平台后台功能非官方 SDK
帮助构建小程序自动化系统,小程序管理后台
已支持功能
- 小程序后台登录
- 小程序体验成员管理(查询,添加,删除)
- 小程序版本管理(获取所有版本列表,版本设为体验版,版本提审,撤回提审,版本发布)
- 生成任意小程序的小程序码
- 客户端开启复制小程序路径
- 小程序获取公众号文章渠道来源数据
安装
$ npm install --save mina-admin
使用
const Admin = ; const admin = account: "" password: ""; await admin;await admin;const users = await admin type: "list";
环境变量
STORAGE_FILE
: 定义运行过程中用户数据(cookie...)存储的路径, 默认为 lib/.storage
CRYPTO_KEY
: 用户数据加密秘钥
Admin Api
获取 Admin 对象
const admin = account: "" // 微信小程序后台登录账号 password: "" // 微信小程序后台登录密码
初始化 init()
使用前必须先调用初始化方法
admin
登录 login()
调用后台功能前必须先登录,第一次登录或者登录会话过期,会在控制台中打印二维码,需要管理员通过微信进行扫码登录。
通过监听 qrcode
事件,在回调中获取二维码,开发者可以通过自定义方式发送二维码给管理员。
通过监听 login-expired
事件,处理登录过期,并添加重新登录逻辑。
adminawait admin;
admin
注册扩展指令 registerCommand()
除了使用默认小程序后台指令外,开发者还可以编写自定义指令并注册
admin
执行功能指令 exec(), command()
执行指令有两种不同的方式
adminadminargs
获取用户信息 getUser()
admin
内置指令
MinaCodeCommand
提供小程序版本管理功能(获取所有版本列表,版本设为体验版,版本提审,撤回提审,版本发布)
// 获取当前的小程序版本(线上版本,审核版本,开发版本)const codes = await admin; console // 开发版本 [Code, Code]console // 体验版本 Codeconsole // 线上版本 Code
// 版本设为体验版const codes = await admin;
// 版本提审const codes = await admin;
// 撤回提审const codes = await admin;
// 版本发布到线上const codes = await admin;
MinaExprUsersCommand
提供小程序体验成员管理(查询,添加,删除)
// 获取所有有体验版权限的成员const users = await admin; console // [User, User]
// 添加指定用户为体验版成员const users = await admin;
// 删除指定体验版成员const users = await admin;
MinaQrcodeCommand
生成任意小程序的小程序码
// 生成小程序码const base64ImageStr = await admin; console // Base64 encode image string
// 获取 appIdconst appId = await admin;
MinaToolsCommand
小程序工具指令,支持复制小程序路径
// 开启客户端复制小程序路径功能// 该微信用户可打开小程序右上角菜单,点击“复制页面路径”并粘贴至左侧“小程序页面路径”中const isSuccess = await admin;
// 获取 appIdconst appId = await admin;
MinaQrcodeCommand
生成任意小程序的小程序码
// 生成小程序码const base64ImageStr = await admin; console // Base64 encode image string
// 获取 appIdconst appId = await admin;
MinaVisitOfficialSourceCommand
小程序获取公众号文章渠道来源数据
const resp = await admin;
Command Api
开发者通过继承 Command 来编写自定义指令, 具体例子可以查看 lib/commands
目录中的内置指令
内置指令类名和所在文件名必须符合 AxxBxxCommand
的格式, 指令名解析为 axx_bxx
const Command = ; async { // 指令功能入口 } { // 指令执行完成的清理函数 }
command.fetch()
封装了 node-fetch
, 会设置额外的 url 参数和 cookie 绕过微信接口身份认证
let resp = await command;
command.dom()
封装了 jsdom
, 简化处理 html
const dom = command;const document = domwindowdocument;document
常量
MINA_CODE_IN_DEV
: 开发版本
MINA_CODE_IN_REVIEW
: 审核中
MINA_CODE_REVIEW_PASS
: 已过审待发布
License
BSD-3-Clause © alexayan