miniprogram-mp-ci is an npm package designed to streamline the member management process for Mini Programs. It allows developers to execute bulk management tasks directly via code, rather than manually through the WeChat Official Accounts Platform. This toolkit provides a range of automation features, making the management of Mini Program members quick and efficient.
Key and IP Whitelist Configuration
Before using miniprogram-mp-ci, you must visit "WeChat Official Platform (https://mp.weixin.qq.com) - Management - Development Management - Development Settings - Mini Program Code Upload" to generate a "Code Upload Key" and configure the IP whitelist.
Developers can choose to enable the IP whitelist. Once enabled, only IPs in the whitelist can call the related APIs. We recommend that all developers enable this option by default to reduce risks.
The Code Upload Key has the permissions to preview and upload code. The key is not stored in plaintext on the WeChat Official Platform. If lost, it must be reset. Please ensure developers keep the key secure.
Features
miniprogram-mp-ci currently provides the following capabilities:
- Batch member management
Script Invocation
npm install miniprogram-mp-ci --save
Project Object
The Project object is the primary input parameter for this module. You can implement it according to the definition below.
Definition of the Project Object:
interface IProject {
appid: string
type: string
projectPath: string
privateKey: string
attr(): Promise<IProjectAttr>
stat(prefix: string, filePath: string): IStat | undefined
getFile(prefix: string, filePath: string): Promise<Buffer>
getFileList(prefix: string, extName: string): string[]
updateFiles: () => void
}
| Key | Type | Description |
|---|---|---|
| appid | Property | The appid of Mini Program /Mini Program |
| type | Property | The type of the project. Valid values are miniProgram/miniProgramPlugin/miniGame/miniGamePlugin |
| projectPath | Property | The path of the project, i.e., the directory containing project.config.json |
| privateKey | Property | The private key, used for authentication when retrieving project attributes and uploading. Download it after logging in to WeChat Official Platform |
| attr | Async method | The attributes of the project. If privateKey is specified, the actual project attributes will be used |
| stat | Sync method | The stat of the file path (filePath) under the specific prefix (prefix) in a directory. Returns undefined if it does not exist |
| getFile | Async method | The Buffer of the file path (filePath) under the specific prefix (prefix) in a directory |
| getFileList | Sync method | The file list under the specific prefix (prefix) in a directory |
| updateFile | Sync method | Updates the project files |
You can also create this object by specifying the project path.
const ci = require('miniprogram-mp-ci')
// Note: When calling new ci.Project, ensure the project code is complete to avoid file-not-found errors during compilation.
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/privatekey/path',
ignores: ['node_modules/**/*'],
})
| Key | Type | Required | Description |
|---|---|---|---|
| appid | string | Yes | The valid Mini Program /Mini Game appid |
| projectPath | string | Yes | The project path |
| privateKeyPath | string | Yes | The path to the private key |
| type | string | No | Explicitly specifies the current project type. Defaults to miniProgram. Valid values: miniProgram/miniProgramPlugin/miniGame/miniGamePlugin |
| ignores | string[] | No | Specifies rules to be excluded |
Batch Member Management
const ci = require('miniprogram-mp-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
const result = await ci.manageProjectMember({
project,
action: "add_project_member_data",
robot: 1,
member_list: [
{
wechatid: "wechatid1",
remark: "remark1"
}
{
wechatid: "wechatid2",
remark: "remark2"
}
]
})
console.log(result)
})()
Parameters
| Key | Type | Required | Description |
|---|---|---|---|
| project | IProject | Yes | #Project object |
| action | string | Yes | #Member management action |
| robot | number | Yes | Specifies which CI robot to use, acceptable values: 1 ~ 30 |
| member_list | array | Yes | #Member object array |
Member Management Action
| Optional Value | Description |
|---|---|
| add_experiencer | Batch add experiencers with permission to view experience rights |
| delete_experiencer | Batch delete experiencers with permission to view experience rights |
| add_experiencer_dev | Batch add experiencers with permission to view development rights |
| delete_experiencer_dev | Batch delete experiencers with permission to view development rights |
| add_project_member_operator | Batch add project members with operator permissions |
| delete_project_member_operator | Batch delete project members with operator permissions |
| add_project_member_developer | Batch add project members with developer permissions |
| delete_project_member_developer | Batch delete project members with developer permissions |
| add_project_member_data | Batch add project members with data analyst permissions |
| delete_project_member_data | Batch delete project members with data analyst permissions |
Member Object
| Key | Type | Required | Description |
|---|---|---|---|
| wechatid | string | Yes | The WeChat ID of the target user |
| remark | string | No | Remark |
Returns
| Key | Type | Required | Description |
|---|---|---|---|
| errCode | number | No | #errCode explanation |
| errMsg | string | No | Text description of the operation failure |
errCode Explanation
| Value | Description |
|---|---|
| 0 | Operation successful |
| -1 | Request failed |
| 80601 | The new member already exists |
| 80602 | The member to be deleted does not exist |
| 80603 | The list of WeChat IDs operated on exceeds the limit |
| 80604 | One or more WeChat IDs in the operation list do not exist |
| 80605 | Cannot operate on the administrator |
Frequently Asked Questions
Q1. What is the effective method? A1: Ensure the information is accurate. After a successful call, the administrator's WeChat will receive a message notification from the "Official Account Security Assistant". It takes effect immediately upon administrator confirmation.