wechat-mp-controller 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export type WeChatMpControllerOptions = {
2
- headless?: boolean;
3
- };
1
+ import { LaunchOptions } from 'puppeteer-core';
2
+ import { SubmitAuditFormType } from './type';
3
+ export type WeChatMpControllerOptions = Pick<LaunchOptions, 'headless' | 'userDataDir'>;
4
4
  export declare class WeChatMpController {
5
5
  static create(options?: WeChatMpControllerOptions): Promise<Controller>;
6
6
  }
@@ -37,7 +37,7 @@ export declare class Controller {
37
37
  }[];
38
38
  }>;
39
39
  submitAudit(options: {
40
- message: string;
40
+ formData: SubmitAuditFormType;
41
41
  uploader: {
42
42
  name: string;
43
43
  openId: string;
package/dist/index.js CHANGED
@@ -15,8 +15,7 @@ export class Controller {
15
15
  defaultViewport: null,
16
16
  args: ['--start-maximized'],
17
17
  channel: 'chrome',
18
- headless: options?.headless,
19
- userDataDir: './.wmpc-cache'
18
+ ...options
20
19
  });
21
20
  this.page = await this.browser.newPage();
22
21
  await this.page.goto(`https://mp.weixin.qq.com/`);
@@ -115,16 +114,32 @@ export class Controller {
115
114
  if (!urlToken) {
116
115
  throw new Error('获取token失败');
117
116
  }
117
+ const {
118
+ formData,
119
+ uploader
120
+ } = options;
118
121
  const searchParams = new URLSearchParams({
119
122
  action: 'get_class',
120
123
  token: urlToken,
121
124
  lang: 'zh-CN',
122
- openid: options.uploader.openId,
123
- user_name: encodeURIComponent(options.uploader.name)
125
+ openid: uploader.openId,
126
+ user_name: encodeURIComponent(uploader.name)
124
127
  });
125
128
  await this.page.goto(`https://mp.weixin.qq.com/wxamp/wadevelopcode/get_class?${searchParams.toString()}`);
126
129
  await this.page.waitForSelector('.weui-desktop-form__control-group textarea');
127
- await this.page.locator('.weui-desktop-form__control-group textarea').fill(options.message);
130
+ if (formData.message) {
131
+ await this.page.locator('.weui-desktop-form__control-group textarea').fill(formData.message);
132
+ }
133
+ if (formData.imageUrls?.length || formData.videoUrl) {
134
+ const [imageUploader, videoUploader] = await this.page.$$('.webuploader-container input');
135
+ if (formData.imageUrls?.length) {
136
+ await imageUploader.uploadFile(...formData.imageUrls);
137
+ }
138
+ if (formData.videoUrl) {
139
+ await videoUploader.uploadFile(formData.videoUrl);
140
+ }
141
+ await this.page.waitForNetworkIdle();
142
+ }
128
143
  await this.page.locator('.btn.btn_primary[data-msgid="提交审核"]').click();
129
144
  // 也可以等待 https://mp.weixin.qq.com/wxamp/cgi/route?path=%2Fwxopen%2Fwadevelopcode%3Faction%3Dsubmit_check&token=283379953&lang=zh_CN&random=0.8360122102877674
130
145
  await this.page.waitForSelector('div[data-component="sumbitPage"] .main_bd *[data-msgid="已提交审核"]');
package/dist/type.d.ts CHANGED
@@ -21,6 +21,23 @@ export type OriginVersionInfo = {
21
21
  inner_version: number;
22
22
  };
23
23
  };
24
+ experience_info: {
25
+ basic_info: {
26
+ open_id: string;
27
+ version: string;
28
+ nick_name: string;
29
+ time: number;
30
+ describe: string;
31
+ status: number;
32
+ warning_api_list: string[];
33
+ avatar: string;
34
+ fail_reason: string;
35
+ is_speedup: number;
36
+ audit_status: number;
37
+ audit_id: number;
38
+ };
39
+ qr_path: string;
40
+ };
24
41
  develop_info: {
25
42
  info_list: Array<{
26
43
  basic_info: {
@@ -42,3 +59,8 @@ export type OriginVersionInfo = {
42
59
  need_finance_audit: number;
43
60
  qr_path: string;
44
61
  };
62
+ export type SubmitAuditFormType = {
63
+ message?: string;
64
+ imageUrls?: string[];
65
+ videoUrl?: string;
66
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechat-mp-controller",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "license": "MIT",