wechat-mp-controller 0.1.4 → 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,4 +1,5 @@
1
1
  import { LaunchOptions } from 'puppeteer-core';
2
+ import { SubmitAuditFormType } from './type';
2
3
  export type WeChatMpControllerOptions = Pick<LaunchOptions, 'headless' | 'userDataDir'>;
3
4
  export declare class WeChatMpController {
4
5
  static create(options?: WeChatMpControllerOptions): Promise<Controller>;
@@ -36,7 +37,7 @@ export declare class Controller {
36
37
  }[];
37
38
  }>;
38
39
  submitAudit(options: {
39
- message: string;
40
+ formData: SubmitAuditFormType;
40
41
  uploader: {
41
42
  name: string;
42
43
  openId: string;
package/dist/index.js CHANGED
@@ -114,16 +114,32 @@ export class Controller {
114
114
  if (!urlToken) {
115
115
  throw new Error('获取token失败');
116
116
  }
117
+ const {
118
+ formData,
119
+ uploader
120
+ } = options;
117
121
  const searchParams = new URLSearchParams({
118
122
  action: 'get_class',
119
123
  token: urlToken,
120
124
  lang: 'zh-CN',
121
- openid: options.uploader.openId,
122
- user_name: encodeURIComponent(options.uploader.name)
125
+ openid: uploader.openId,
126
+ user_name: encodeURIComponent(uploader.name)
123
127
  });
124
128
  await this.page.goto(`https://mp.weixin.qq.com/wxamp/wadevelopcode/get_class?${searchParams.toString()}`);
125
129
  await this.page.waitForSelector('.weui-desktop-form__control-group textarea');
126
- 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
+ }
127
143
  await this.page.locator('.btn.btn_primary[data-msgid="提交审核"]').click();
128
144
  // 也可以等待 https://mp.weixin.qq.com/wxamp/cgi/route?path=%2Fwxopen%2Fwadevelopcode%3Faction%3Dsubmit_check&token=283379953&lang=zh_CN&random=0.8360122102877674
129
145
  await this.page.waitForSelector('div[data-component="sumbitPage"] .main_bd *[data-msgid="已提交审核"]');
package/dist/type.d.ts CHANGED
@@ -59,3 +59,8 @@ export type OriginVersionInfo = {
59
59
  need_finance_audit: number;
60
60
  qr_path: string;
61
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.4",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "license": "MIT",