wechat-mp-controller 0.1.4 → 0.2.1
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 +2 -1
- package/dist/index.js +18 -3
- package/dist/type.d.ts +5 -0
- package/package.json +1 -1
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
|
-
|
|
40
|
+
formData: SubmitAuditFormType;
|
|
40
41
|
uploader: {
|
|
41
42
|
name: string;
|
|
42
43
|
openId: string;
|
package/dist/index.js
CHANGED
|
@@ -114,16 +114,31 @@ 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:
|
|
122
|
-
user_name: encodeURIComponent(
|
|
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
|
-
|
|
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
|
+
}
|
|
127
142
|
await this.page.locator('.btn.btn_primary[data-msgid="提交审核"]').click();
|
|
128
143
|
// 也可以等待 https://mp.weixin.qq.com/wxamp/cgi/route?path=%2Fwxopen%2Fwadevelopcode%3Faction%3Dsubmit_check&token=283379953&lang=zh_CN&random=0.8360122102877674
|
|
129
144
|
await this.page.waitForSelector('div[data-component="sumbitPage"] .main_bd *[data-msgid="已提交审核"]');
|
package/dist/type.d.ts
CHANGED