@iflyrpa/actions 1.2.5 → 1.2.6-beta.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.mjs CHANGED
@@ -198,6 +198,24 @@ async function copyHtmlToClipboard(page, html, options = {
198
198
  }, html);
199
199
  }
200
200
  }
201
+ function PopupListener(page, popupSelector, popKey, buttonSelector, options = {}) {
202
+ const { checkInterval = 1000, stopAfterClick = false } = options;
203
+ const popup = page.locator(popupSelector);
204
+ const button = page.locator(buttonSelector);
205
+ const intervalId = setInterval(async ()=>{
206
+ try {
207
+ if (await popup.count() > 0 && await popup.isVisible() && (await popup.textContent() || "").includes(popKey)) {
208
+ await button.click({
209
+ force: true
210
+ });
211
+ if (stopAfterClick) clearInterval(intervalId);
212
+ }
213
+ } catch (err) {}
214
+ }, checkInterval);
215
+ return ()=>{
216
+ clearInterval(intervalId);
217
+ };
218
+ }
201
219
  const parseUrlQueryString = (url)=>{
202
220
  const queryStringObject = {};
203
221
  if (!url || !url.includes("?")) return queryStringObject;
@@ -1101,13 +1119,28 @@ const QuotaType = {
1101
1119
  Normal: "kQuotaTypeMassSendNormal",
1102
1120
  ProductActivity: "kQuotaTypeMassSendProductActivity"
1103
1121
  };
1104
- const GET_QRCODE_DEFAULT_ERROR = "二维码获取异常,请稍后重试发布。";
1122
+ const GET_QRCODE_DEFAULT_ERROR = "二维码获取异常,请稍后重试。";
1105
1123
  const weixinPublish_mock_errnoMap = {
1106
- 200003: "微信公众号号登录状态失效,请重新绑定账号后重试。"
1124
+ 200003: "微信公众号号登录状态失效,请重新绑定账号后重试。",
1125
+ 420001: "封面图不支持GIF,请更换后重试。",
1126
+ 200002: "上传图片参数错误,请检查后重试。",
1127
+ 200039: "上传图片高度(像素)与宽度(像素)的乘积不能超过600万,请更换后重试。",
1128
+ 153201: "不支持发布审核中或转码中的视频",
1129
+ 200007: "登陆失败,请重新登陆账户后重试。",
1130
+ 64703: "摘要超出120字长度限制,请修改摘要后重试。",
1131
+ "-4": "不支持发布审核中或转码中的视频",
1132
+ "-2": "不支持发布审核中或转码中的视频",
1133
+ 770001: "不支持发布审核中或转码中的视频",
1134
+ 200074: "系统繁忙,请稍后重试!"
1107
1135
  };
1108
1136
  const ignoreErrno = [
1109
1137
  154019
1110
1138
  ];
1139
+ const userTypeMap = {
1140
+ 所有用户: 1,
1141
+ 已关注的用户: 2,
1142
+ 已关注7天及以上的用户: 3
1143
+ };
1111
1144
  const generatorFormData = (data)=>{
1112
1145
  const formData = new URLSearchParams();
1113
1146
  for (const [key, value] of Object.entries(data))formData.append(key, String(value));
@@ -1215,6 +1248,223 @@ const weixinPublish_mock_mockAction = async (task, params)=>{
1215
1248
  const coverRes = await uploadImages([
1216
1249
  params.settingInfo.wxCover
1217
1250
  ]);
1251
+ let oriWhitelist = null;
1252
+ if (params.settingInfo?.wxCopyright && params.settingInfo?.wxWhitelist) {
1253
+ const _oriWhitelist = params.settingInfo.wxWhitelist;
1254
+ if (_oriWhitelist && _oriWhitelist.length > 0) {
1255
+ const white_list = [];
1256
+ const white_list_user = {
1257
+ nickname: "",
1258
+ title: "可修改文章",
1259
+ openid: "",
1260
+ wx_name: "",
1261
+ username: "",
1262
+ avatar: "",
1263
+ can_modify: "1",
1264
+ can_hide_source: "0",
1265
+ can_reward: "0"
1266
+ };
1267
+ for (const _user of _oriWhitelist){
1268
+ const userInfo_res = await http.api({
1269
+ method: "post",
1270
+ url: "https://mp.weixin.qq.com/cgi-bin/appmsgcopyright?action=searchacct",
1271
+ params: {
1272
+ action: "searchacct"
1273
+ },
1274
+ data: generatorFormData({
1275
+ lang: "zh_CN",
1276
+ f: "json",
1277
+ ajax: 1,
1278
+ token: params.token,
1279
+ random: Math.random().toString(),
1280
+ username: _user
1281
+ }),
1282
+ defaultErrorMsg: "搜索用户信息失败"
1283
+ });
1284
+ if (!(userInfo_res.search_list.length > 0)) return {
1285
+ code: 200,
1286
+ message: `白名单用户:${_user} 未搜索到,请确定输入是否正确!`,
1287
+ data: ''
1288
+ };
1289
+ {
1290
+ let userInfo_resJson = userInfo_res.search_list[0];
1291
+ white_list_user.nickname = userInfo_resJson.nickname;
1292
+ white_list_user.openid = userInfo_resJson.openid;
1293
+ white_list_user.avatar = userInfo_resJson.pic_url;
1294
+ white_list_user.username = userInfo_resJson.username;
1295
+ white_list_user.wx_name = userInfo_resJson.wx_name;
1296
+ white_list.push({
1297
+ ...white_list_user
1298
+ });
1299
+ }
1300
+ }
1301
+ oriWhitelist = white_list.length > 0 ? JSON.stringify({
1302
+ white_list: white_list
1303
+ }) : "";
1304
+ }
1305
+ }
1306
+ let writerid = null;
1307
+ let reply_id = null;
1308
+ if (params.settingInfo.wxCopyright && params.settingInfo.wxRewardTarget) {
1309
+ async function getWriterList() {
1310
+ const res = await http.api({
1311
+ method: "get",
1312
+ url: 'https://mp.weixin.qq.com/acct/writermgr',
1313
+ params: {
1314
+ action: 'get_writer_list',
1315
+ fingerprint,
1316
+ token: params.token,
1317
+ lang: "zh_CN",
1318
+ f: "json",
1319
+ ajax: 1
1320
+ }
1321
+ });
1322
+ return res.pageinfo.writerlist || [];
1323
+ }
1324
+ async function getRewardText() {
1325
+ const res = await http.api({
1326
+ method: "get",
1327
+ url: 'https://mp.weixin.qq.com/merchant/reward',
1328
+ params: {
1329
+ action: 'getautoreply',
1330
+ fingerprint,
1331
+ token: params.token,
1332
+ lang: "zh_CN",
1333
+ f: "json",
1334
+ ajax: 1
1335
+ }
1336
+ });
1337
+ return res.reply_infos;
1338
+ }
1339
+ for(var _type in params.settingInfo.wxRewardTarget)if ("author" === _type) {
1340
+ if (0 == (await getWriterList()).length) {
1341
+ const rewardbind = await http.api({
1342
+ method: "get",
1343
+ url: "https://mp.weixin.qq.com/acct/writermgr",
1344
+ params: {
1345
+ action: "get_rewardbind_qrcode",
1346
+ random: Math.random().toString(),
1347
+ fingerprint,
1348
+ token: params.token,
1349
+ lang: "zh_CN",
1350
+ f: "json",
1351
+ ajax: 1
1352
+ },
1353
+ defaultErrorMsg: GET_QRCODE_DEFAULT_ERROR
1354
+ });
1355
+ const rewardBuffer = Buffer.from(rewardbind.qrcode_base64, 'base64');
1356
+ const rewardFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, "weixin_reward.jpg");
1357
+ __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(rewardFilePath, new Uint8Array(rewardBuffer));
1358
+ params.safeQrcodeCallback?.(rewardFilePath);
1359
+ const task_id = rewardbind.task_id;
1360
+ let code = null;
1361
+ for(let i = 0; i < scanRetryMaxCount; i++){
1362
+ await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.sleep)(2000);
1363
+ const checkScanResult = await http.api({
1364
+ method: "get",
1365
+ url: "https://mp.weixin.qq.com/acct/writermgr",
1366
+ params: {
1367
+ action: "query_rewardbind_qrcode_status",
1368
+ task_id: task_id,
1369
+ fingerprint,
1370
+ lang: "zh_CN",
1371
+ f: "json",
1372
+ ajax: 1,
1373
+ token: params.token,
1374
+ timespam: Date.now()
1375
+ }
1376
+ });
1377
+ code = checkScanResult.qrcode_status;
1378
+ if (2 == code && (await getWriterList()).length > 0) break;
1379
+ if (i === scanRetryMaxCount - 1) return {
1380
+ code: 200,
1381
+ message: "二维码已过期,请重试绑定。",
1382
+ data: ""
1383
+ };
1384
+ }
1385
+ }
1386
+ let _writer = await getWriterList();
1387
+ for (var _writer_item of _writer)if (_writer_item.nickname === params.settingInfo.wxRewardTarget[_type]) writerid = _writer_item.writerid;
1388
+ if (!writerid) return {
1389
+ code: 200,
1390
+ message: "未匹配到赞赏绑定用户,请确认用户名与绑定是否正常!",
1391
+ data: ""
1392
+ };
1393
+ if (params.settingInfo?.wxRewardText) {
1394
+ let rewardList = await getRewardText();
1395
+ let matchdID = rewardList.find((reward)=>reward.text === params.settingInfo.wxRewardText)?.reply_id ?? null;
1396
+ if (0 != rewardList.length && matchdID) reply_id = matchdID;
1397
+ else await http.api({
1398
+ method: "post",
1399
+ url: 'https://mp.weixin.qq.com/merchant/reward',
1400
+ params: {
1401
+ action: 'addautoreply'
1402
+ },
1403
+ data: generatorFormData({
1404
+ type: 1,
1405
+ fingerprint,
1406
+ token: params.token,
1407
+ lang: "zh_CN",
1408
+ f: "json",
1409
+ ajax: 1,
1410
+ text: params.settingInfo.wxRewardText
1411
+ })
1412
+ });
1413
+ if (!matchdID) {
1414
+ for (var _reply_item of (await getRewardText()))reply_id = (await getRewardText()).find((reward)=>reward.text === params.settingInfo.wxRewardText)?.reply_id;
1415
+ if (!reply_id) return {
1416
+ code: 200,
1417
+ message: "赞赏文案添加失败,请重新检查",
1418
+ data: ""
1419
+ };
1420
+ }
1421
+ }
1422
+ }
1423
+ }
1424
+ const wxInteractionInfo = (()=>{
1425
+ const _wxInteraction = {
1426
+ need_open_comment0: 0,
1427
+ only_fans_can_comment0: 0,
1428
+ only_fans_days_can_comment0: 0,
1429
+ reply_flag0: 2,
1430
+ auto_elect_comment0: 0,
1431
+ auto_elect_reply0: 1,
1432
+ open_fansmsg0: 0
1433
+ };
1434
+ const type = params?.settingInfo?.wxInteraction?.Type ?? "";
1435
+ if ("public" === type) {
1436
+ const _opt = params?.settingInfo?.wxInteraction?.Option;
1437
+ if (!_opt || !_opt.Comment || !_opt.reply || null == _opt.elect_comment || null == _opt.elect_reply) return null;
1438
+ const commentType = userTypeMap[_opt.Comment];
1439
+ const replyType = userTypeMap[_opt.reply] + 1;
1440
+ _wxInteraction.need_open_comment0 = 1;
1441
+ switch(commentType){
1442
+ case 1:
1443
+ _wxInteraction.only_fans_can_comment0 = 0;
1444
+ _wxInteraction.only_fans_days_can_comment0 = 0;
1445
+ break;
1446
+ case 2:
1447
+ _wxInteraction.only_fans_can_comment0 = 1;
1448
+ _wxInteraction.only_fans_days_can_comment0 = 0;
1449
+ break;
1450
+ case 3:
1451
+ _wxInteraction.only_fans_can_comment0 = 0;
1452
+ _wxInteraction.only_fans_days_can_comment0 = 1;
1453
+ break;
1454
+ }
1455
+ _wxInteraction.reply_flag0 = replyType;
1456
+ _wxInteraction.auto_elect_comment0 = _opt.elect_comment ? userTypeMap[_opt.Comment] : 0;
1457
+ _wxInteraction.auto_elect_reply0 = _opt.elect_reply ? userTypeMap[_opt.reply] : 1;
1458
+ return _wxInteraction;
1459
+ }
1460
+ if ("private" === type) _wxInteraction.open_fansmsg0 = 1;
1461
+ return _wxInteraction;
1462
+ })();
1463
+ if (!wxInteractionInfo) return {
1464
+ code: 200,
1465
+ message: "互动参数设置错误,请检查参数设置!",
1466
+ data: ""
1467
+ };
1218
1468
  const draftData = {
1219
1469
  lang: "zh_CN",
1220
1470
  f: "json",
@@ -1227,16 +1477,19 @@ const weixinPublish_mock_mockAction = async (task, params)=>{
1227
1477
  is_finder_video0: 0,
1228
1478
  finder_draft_id0: 0,
1229
1479
  applyori0: 0,
1230
- can_reward0: 0,
1480
+ can_reward0: writerid ? 1 : 0,
1231
1481
  pay_gifts_count0: 0,
1232
1482
  is_video_recommend0: -1,
1233
- writerid0: 0,
1483
+ writerid0: writerid ? writerid : 0,
1234
1484
  auto_gen_digest0: 0,
1235
1485
  last_choose_cover_from0: 0,
1236
- need_open_comment0: 0,
1237
- only_fans_can_comment0: 0,
1238
- only_fans_days_can_comment0: 0,
1239
- reply_flag0: 0,
1486
+ need_open_comment0: wxInteractionInfo.need_open_comment0,
1487
+ only_fans_can_comment0: wxInteractionInfo.only_fans_can_comment0,
1488
+ only_fans_days_can_comment0: wxInteractionInfo.only_fans_days_can_comment0,
1489
+ reply_flag0: wxInteractionInfo.reply_flag0,
1490
+ auto_elect_comment0: wxInteractionInfo.auto_elect_comment0,
1491
+ auto_elect_reply0: wxInteractionInfo.auto_elect_reply0,
1492
+ reward_reply_id0: params.settingInfo?.wxRewardText ? reply_id ? reply_id : 0 : 0,
1240
1493
  not_pay_can_comment0: 0,
1241
1494
  data_seq: 0,
1242
1495
  msg_index_id0: "",
@@ -1248,7 +1501,11 @@ const weixinPublish_mock_mockAction = async (task, params)=>{
1248
1501
  content0: content || "",
1249
1502
  sourceurl0: params?.settingInfo?.wxOriginalText || "",
1250
1503
  cdn_url0: coverRes[0].cdn_url || "",
1251
- open_fansmsg0: params?.settingInfo?.wxFansMsg ? 1 : 0,
1504
+ copyright_type0: params?.settingInfo?.wxCopyright ? 1 : 0,
1505
+ allow_reprint0: params?.settingInfo?.wxCopyright ? 0 : '',
1506
+ allow_reprint_modify0: params?.settingInfo?.wxCopyright ? 0 : '',
1507
+ ori_white_list0: params?.settingInfo?.wxCopyright ? oriWhitelist : '',
1508
+ open_fansmsg0: wxInteractionInfo.open_fansmsg0,
1252
1509
  allow_fast_reprint0: params?.settingInfo?.wxQuickReprint ? 1 : 0,
1253
1510
  disable_recommend0: params?.settingInfo?.wxNotAllowRecommend ? 1 : 0,
1254
1511
  claim_source_type0: params?.settingInfo?.wxCreationSource?.[0] || "",
@@ -1599,6 +1856,81 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1599
1856
  timestamp: Date.now(),
1600
1857
  appmsgid: params.appMsgId
1601
1858
  };
1859
+ if (params.settingInfo?.wxRewardTarget) {
1860
+ const urlRewardParams = {
1861
+ action: "inviteauthor",
1862
+ token: params.token,
1863
+ lang: "zh_CN"
1864
+ };
1865
+ const wxRewardPage = await task.createPage({
1866
+ show: task.debug,
1867
+ url: params.url || `https://mp.weixin.qq.com/cgi-bin/safecenterstatus?${Object.entries(urlRewardParams).map((it)=>it.join("=")).join("&")}`,
1868
+ cookies: params.cookies?.map((it)=>({
1869
+ ...commonCookies,
1870
+ ...it
1871
+ })) || []
1872
+ });
1873
+ const reward_page = wxRewardPage.locator("#app");
1874
+ const isAddRewarder = reward_page.locator('.author_card_bd.weui-desktop-vm_primary').filter({
1875
+ hasText: params.settingInfo.wxRewardTarget.author
1876
+ }).count();
1877
+ if (await isAddRewarder == 0) {
1878
+ await reward_page.locator('.weui-desktop-panel__hd-right').click();
1879
+ try {
1880
+ try {
1881
+ await wxRewardPage.waitForSelector('.invite-qrcode', {
1882
+ state: 'visible',
1883
+ timeout: 20000
1884
+ });
1885
+ const qrcodeSrc = await reward_page.locator(".invite-qrcode").getAttribute('src');
1886
+ if (qrcodeSrc) {
1887
+ const rewardBuffer = Buffer.from(qrcodeSrc.replace(/^data:image\/\w+;base64,/, ''), 'base64');
1888
+ const rewardFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, "weixin_reward.jpg");
1889
+ __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(rewardFilePath, new Uint8Array(rewardBuffer));
1890
+ params.safeQrcodeCallback?.(rewardFilePath);
1891
+ }
1892
+ } catch (error) {
1893
+ throw new Error("二维码已过期,请重试绑定。");
1894
+ }
1895
+ for(let i = 0; i < scanRetryMaxCount; i++){
1896
+ await Promise.all([
1897
+ wxRewardPage.reload(),
1898
+ wxRewardPage.waitForLoadState('domcontentloaded')
1899
+ ]);
1900
+ try {
1901
+ await wxRewardPage.waitForSelector(`.author_card_bd.weui-desktop-vm_primary:has-text("${params.settingInfo.wxRewardTarget?.author}")`, {
1902
+ timeout: 1000
1903
+ });
1904
+ break;
1905
+ } catch (error) {}
1906
+ if (i === scanRetryMaxCount - 1) throw new Error("未确认绑定账户,请在手机端确认绑定并重试");
1907
+ }
1908
+ } catch (error) {
1909
+ let errorMessage = "发生未知错误";
1910
+ if (error instanceof Error) errorMessage = error.message;
1911
+ else if ("string" == typeof error) errorMessage = error;
1912
+ await wxRewardPage.close();
1913
+ return {
1914
+ code: 200,
1915
+ message: errorMessage,
1916
+ data: ""
1917
+ };
1918
+ }
1919
+ }
1920
+ if (params.settingInfo.wxRewardText) {
1921
+ await wxRewardPage.locator('[href="/merchant/reward?action=getautoreply"]').click();
1922
+ await wxRewardPage.waitForLoadState('networkidle');
1923
+ const isAddWord = reward_page.locator(".auto-reply__list.edit .auto-reply__hd .auto-reply__text").filter({
1924
+ hasText: new RegExp(`^${params.settingInfo.wxRewardText}$`)
1925
+ }).count();
1926
+ if (await isAddWord == 0) {
1927
+ await reward_page.locator(".emotion_editor .edit_area").fill(params.settingInfo.wxRewardText);
1928
+ await reward_page.locator(".emotion_editor .edit_area").click();
1929
+ await reward_page.locator(".editor_toolbar .weui-desktop-btn.weui-desktop-btn_primary").click();
1930
+ }
1931
+ }
1932
+ await wxRewardPage.close();
1933
+ }
1602
1934
  const page = await task.createPage({
1603
1935
  show: task.debug,
1604
1936
  url: params.url || `https://mp.weixin.qq.com/cgi-bin/appmsg?${Object.entries(urlParams).map((it)=>it.join("=")).join("&")}`,
@@ -1621,6 +1953,10 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1621
1953
  await page.waitForSelector("#editor_pannel", {
1622
1954
  state: "visible"
1623
1955
  });
1956
+ PopupListener(page, '[v-transfer-dom="#vue_app"] .weui-desktop-dialog', "更新", '[v-transfer-dom="#vue_app"] .weui-desktop-icon-btn.weui-desktop-dialog__close-btn', {
1957
+ checkInterval: 1000,
1958
+ stopAfterClick: false
1959
+ });
1624
1960
  const titleInstance = page.locator("#js_title_main textarea#title");
1625
1961
  await titleInstance.click();
1626
1962
  await titleInstance.fill(params.title);
@@ -1662,7 +1998,15 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1662
1998
  await page.waitForSelector(".weui-desktop-img-picker__list .weui-desktop-img-picker__item.selected", {
1663
1999
  state: "visible"
1664
2000
  });
1665
- await page.waitForTimeout(1000);
2001
+ await page.waitForSelector('.weui-desktop-upload__file__progress', {
2002
+ state: 'detached'
2003
+ });
2004
+ const pic_msg = page.locator('.weui-desktop-img-picker__list .weui-desktop-img-picker__item.selected .weui-desktop-upload__file__msg');
2005
+ if (await pic_msg.count() > 0) return {
2006
+ code: 200,
2007
+ message: "图片上传错误:" + (await pic_msg.textContent() || "未知错误,请重试!"),
2008
+ data: ""
2009
+ };
1666
2010
  await dialog.locator(".weui-desktop-dialog__ft .weui-desktop-btn:not(.weui-desktop-btn_disabled)").filter({
1667
2011
  hasText: "下一步"
1668
2012
  }).click();
@@ -1675,6 +2019,124 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1675
2019
  hasText: "确认"
1676
2020
  }).click();
1677
2021
  }
2022
+ if (params.settingInfo.wxCopyright) {
2023
+ await page.locator('#js_original').click();
2024
+ const ori_dialog = page.locator('.claim__original-dialog.original_dialog');
2025
+ const ori_dialog_bd = ori_dialog.locator('.weui-desktop-dialog__bd');
2026
+ const ori_dialog_ft = ori_dialog.locator('.weui-desktop-dialog__ft');
2027
+ await ori_dialog_bd.locator('.weui-desktop-form__check-content').filter({
2028
+ hasText: "文字原创"
2029
+ }).click();
2030
+ if (params.settingInfo?.wxWhitelist) for (var _target of params.settingInfo.wxWhitelist){
2031
+ await ori_dialog_bd.locator('#js_article_whitelist_search').fill(_target);
2032
+ await ori_dialog_bd.locator('.js_search').click();
2033
+ const search_res = ori_dialog_bd.locator('#js_article_whitelist_search_result > div');
2034
+ await page.waitForTimeout(1000);
2035
+ if (await search_res.getAttribute('class') === 'search-result-title search-result-empty') return {
2036
+ code: 200,
2037
+ message: `白名单用户:${_target} 未搜索到,请确定输入是否正确!`,
2038
+ data: ''
2039
+ };
2040
+ {
2041
+ const search_res_name = await search_res.locator('.search-result-name-left').textContent() || void 0;
2042
+ await search_res.click();
2043
+ const whrite_list = ori_dialog_bd.locator('#js_article_whitelist_added tbody');
2044
+ const white_td_isadd = await whrite_list.locator('.table-td-name').filter({
2045
+ hasText: search_res_name
2046
+ }).count();
2047
+ if (!white_td_isadd) return {
2048
+ code: 200,
2049
+ message: '白名单添加失败,请重试!',
2050
+ data: ''
2051
+ };
2052
+ }
2053
+ }
2054
+ if (params.settingInfo?.wxQuickReprint) {
2055
+ const btn_isChecked = await ori_dialog_bd.locator('//span[@class="frm_tips"]').filter({
2056
+ hasText: '已开启'
2057
+ }).count() == 1;
2058
+ if (!btn_isChecked) await ori_dialog_bd.locator('.weui-desktop-switch_loading .weui-desktop-switch__box').click();
2059
+ }
2060
+ const checkbox = ori_dialog_ft.locator('.weui-desktop-icon-checkbox');
2061
+ if (!await checkbox.isChecked()) await checkbox.check();
2062
+ await ori_dialog_ft.locator('.weui-desktop-btn.weui-desktop-btn_primary').click();
2063
+ if (params.settingInfo?.wxRewardTarget) {
2064
+ await page.locator('#js_reward_setting_area').click();
2065
+ const reward_setting = page.locator('.reward-setting-dialog');
2066
+ const reward_setting_bd = reward_setting.locator('.weui-desktop-dialog__bd');
2067
+ const reward_setting_ft = reward_setting.locator('.weui-desktop-dialog__ft');
2068
+ for(var _type in params.settingInfo.wxRewardTarget)if ("author" === _type) {
2069
+ let userName = params.settingInfo.wxRewardTarget[_type];
2070
+ await reward_setting_bd.locator('.weui-desktop-form__check-label', {
2071
+ hasText: '赞赏作者'
2072
+ }).click();
2073
+ await reward_setting_bd.locator('.weui-desktop-form__input').fill(userName);
2074
+ if (params.settingInfo.wxRewardText) {
2075
+ const reward_setting_replay = page.locator('.reward-reply-setting');
2076
+ const switchAuto = reward_setting_replay.locator('.weui-desktop-switch__box');
2077
+ const maxAttempts = 5;
2078
+ const delayMs = 500;
2079
+ let nowCheckTime = 0;
2080
+ for(let attempt = 0; attempt < maxAttempts; attempt++){
2081
+ const isDisabled = await switchAuto.isDisabled();
2082
+ if (!isDisabled) {
2083
+ await switchAuto.isChecked() && nowCheckTime++;
2084
+ if (2 == nowCheckTime) break;
2085
+ }
2086
+ if (attempt === maxAttempts - 1) throw new Error('Checkbox did not become enabled within the timeout.');
2087
+ await new Promise((resolve)=>setTimeout(resolve, delayMs));
2088
+ }
2089
+ const isOneReplay = await reward_setting_replay.locator('.reward-reply-select__wrp >.reward-reply-select__tips').textContent() == "添加新的回复";
2090
+ const isCurrentReplay = await reward_setting_replay.locator('.reward-reply-select__wrp >.reward-reply-select__display .wording').filter({
2091
+ hasText: new RegExp(`^${[
2092
+ params.settingInfo.wxRewardText
2093
+ ]}$`)
2094
+ }).count() == 1;
2095
+ if (!isOneReplay && !isCurrentReplay) {
2096
+ await reward_setting_replay.locator('.reward-reply-select__wrp >.reward-reply-select__tips').click();
2097
+ await reward_setting_replay.locator('.reward-reply-select__display.can-select .wording').filter({
2098
+ hasText: new RegExp(`^${[
2099
+ params.settingInfo.wxRewardText
2100
+ ]}$`)
2101
+ }).click();
2102
+ }
2103
+ } else await reward_setting_bd.locator('.reward-reply-setting .weui-desktop-switch__input').isChecked() && reward_setting_bd.locator('.reward-reply-setting .weui-desktop-switch__box').uncheck();
2104
+ }
2105
+ const checkbox = reward_setting_ft.locator('.weui-desktop-icon-checkbox');
2106
+ if (!await checkbox.isChecked()) await checkbox.check();
2107
+ await reward_setting_ft.locator('.weui-desktop-btn.weui-desktop-btn_primary').click();
2108
+ }
2109
+ }
2110
+ if (params.settingInfo?.wxInteraction) {
2111
+ await page.locator('.appmsg-editor__setting-group.js_interaction_cell').click();
2112
+ const wxInteraction_setting = page.locator('.interaction-dialog');
2113
+ const wxInteraction_bd = wxInteraction_setting.locator('.weui-desktop-dialog__bd');
2114
+ const wxInteraction_ft = wxInteraction_setting.locator('.weui-desktop-dialog__ft');
2115
+ if ("public" == params.settingInfo.wxInteraction.Type) {
2116
+ await wxInteraction_bd.locator('.weui-desktop-form__check-label', {
2117
+ hasText: '留言'
2118
+ }).click();
2119
+ const comment_area = wxInteraction_bd.locator('.comment-options-block.pt0');
2120
+ const reply_area = wxInteraction_bd.locator('.comment-options-block.bb0.pb0');
2121
+ const commont_rply_opt = page.locator('.weui-desktop-popper.options-popover[x-placement="bottom"]');
2122
+ await comment_area.locator('.comment-options__selector-btn').click();
2123
+ await commont_rply_opt.locator('.weui-desktop-form__check-label', {
2124
+ hasText: params.settingInfo.wxInteraction.Option?.Comment
2125
+ }).click();
2126
+ if (params.settingInfo.wxInteraction.Option?.elect_comment) await comment_area.locator('.weui-desktop-switch__box').check();
2127
+ else await comment_area.locator('.weui-desktop-switch__input').isChecked() && comment_area.locator('.weui-desktop-switch__box').uncheck();
2128
+ await page.waitForTimeout(1000);
2129
+ await reply_area.locator('.comment-options__selector-btn').click();
2130
+ await commont_rply_opt.locator('.weui-desktop-form__check-label', {
2131
+ hasText: params.settingInfo.wxInteraction.Option?.reply
2132
+ }).click();
2133
+ if (params.settingInfo.wxInteraction.Option?.elect_reply) await reply_area.locator('.weui-desktop-switch__box').check();
2134
+ else await reply_area.locator('.weui-desktop-switch__input').isChecked() && reply_area.locator('.weui-desktop-switch__box').uncheck();
2135
+ } else if ("private" == params.settingInfo.wxInteraction.Type) await wxInteraction_bd.locator('.weui-desktop-form__check-label', {
2136
+ hasText: '快捷私信'
2137
+ }).click();
2138
+ await wxInteraction_ft.locator('.weui-desktop-btn.weui-desktop-btn_primary').click();
2139
+ }
1678
2140
  if (params.settingInfo.wxOriginalText) {
1679
2141
  await page.locator("#js_article_url_area .allow_click_opr").click();
1680
2142
  await page.waitForTimeout(200);
@@ -2033,7 +2495,8 @@ class XsEncrypt {
2033
2495
  }
2034
2496
  }
2035
2497
  const xiaohongshuPublish_mock_errnoMap = {
2036
- 903: "账户已登出,需重新登陆重试!"
2498
+ 903: "账户已登出,需重新登陆重试!",
2499
+ 902: "登录已过期,请重新登录!"
2037
2500
  };
2038
2501
  const xsEncrypt = new XsEncrypt();
2039
2502
  const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
@@ -2103,13 +2566,62 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
2103
2566
  };
2104
2567
  };
2105
2568
  const coverInfos = await Promise.all(params.banners.map((it, idx)=>uploadFile(it, idx)));
2569
+ const searchTopic = async (topic)=>await http.api({
2570
+ method: "post",
2571
+ url: "https://edith.xiaohongshu.com/web_api/sns/v1/search/topic",
2572
+ data: {
2573
+ keyword: topic,
2574
+ suggest_topic_request: {
2575
+ title: "",
2576
+ desc: `#${topic}`
2577
+ },
2578
+ page: {
2579
+ page_size: 20,
2580
+ page: 1
2581
+ }
2582
+ },
2583
+ defaultErrorMsg: "话题搜索异常,请稍后重试。"
2584
+ });
2585
+ let topicDesc = [];
2586
+ params.topic && params.topic.length > 0 && await Promise.all(params.topic.map(async (topic)=>{
2587
+ let topicInfo = {
2588
+ id: null,
2589
+ name: null,
2590
+ type: "topic"
2591
+ };
2592
+ const _topicInfo = await searchTopic(topic);
2593
+ if (0 === _topicInfo.data.topic_info_dtos.length || _topicInfo.data.topic_info_dtos[0].name !== topic) {
2594
+ const topicData = {
2595
+ topic_names: topic
2596
+ };
2597
+ const topicDataStr = xsEncrypt.dumps(topicData);
2598
+ const publishXt = Date.now().toString();
2599
+ const publishXs = await xsEncrypt.encryptXs(`/web_api/sns/capa/postgw/topic/batch_customized${topicDataStr}`, a1Cookie, publishXt);
2600
+ let createTopic = await http.api({
2601
+ method: "POST",
2602
+ url: "https://edith.xiaohongshu.com/web_api/sns/capa/postgw/topic/batch_customized",
2603
+ headers: {
2604
+ "x-s": publishXs,
2605
+ "x-t": publishXt
2606
+ },
2607
+ data: topicData,
2608
+ defaultErrorMsg: "话题创建异常,请稍后重试。"
2609
+ });
2610
+ Object.assign(topicInfo, createTopic.data.topic_infos[0]);
2611
+ } else {
2612
+ topicInfo.id = _topicInfo.data.topic_info_dtos[0].id;
2613
+ topicInfo.name = _topicInfo.data.topic_info_dtos[0].name;
2614
+ topicInfo.link = _topicInfo.data.topic_info_dtos[0].link;
2615
+ }
2616
+ topicDesc.push(topicInfo);
2617
+ }));
2106
2618
  const publishData = {
2107
2619
  common: {
2108
2620
  ats: [],
2109
2621
  biz_relations: [],
2110
- desc: params?.content,
2622
+ desc: params?.content + (params?.topic?.map((it)=>`#${it}[话题]#`).join("") || ""),
2111
2623
  goods_info: {},
2112
- hash_tag: [],
2624
+ hash_tag: topicDesc,
2113
2625
  note_id: "",
2114
2626
  source: JSON.stringify({
2115
2627
  type: "web",
@@ -2227,6 +2739,7 @@ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
2227
2739
  '/api/galaxy/v2/creator/activity_center/list',
2228
2740
  '/web_api/sns/v5/creator/topic/template/list',
2229
2741
  '/web_api/sns/v5/creator/file/encryption',
2742
+ '/web_api/sns/capa/postgw/topic/batch_customized',
2230
2743
  '/web_api/sns/v2/note'
2231
2744
  ];
2232
2745
  await page.route('**', async (route, request)=>{
@@ -2306,7 +2819,7 @@ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
2306
2819
  data: page.url()
2307
2820
  };
2308
2821
  }
2309
- await page.locator("#content-area .menu-container .publish-video a").click();
2822
+ await page.locator("#content-area .menu-container .publish-video .btn").click();
2310
2823
  await page.locator('.creator-container .header .creator-tab:not([style*="-9999px"]) .title').filter({
2311
2824
  hasText: /^上传图文$/
2312
2825
  }).click();
@@ -2323,7 +2836,15 @@ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
2323
2836
  await titleInstance.fill(params.title);
2324
2837
  const descInstance = page.locator(".editor-container #quillEditor .ql-editor");
2325
2838
  await descInstance.click();
2326
- await descInstance.fill(params.content);
2839
+ await descInstance.pressSequentially(params.content);
2840
+ if (params.topic && params.topic.length > 0) for (const it of params.topic){
2841
+ await descInstance.pressSequentially(`#${it}`);
2842
+ await page.locator('.ql-mention-loading').waitFor({
2843
+ state: 'detached'
2844
+ });
2845
+ await page.waitForTimeout(1000);
2846
+ await page.locator('#quill-mention-item-0 .item-view-num').click();
2847
+ }
2327
2848
  const container = page.locator(".creator-container .content .scroll-content");
2328
2849
  await container.focus();
2329
2850
  await page.mouse.wheel(0, 500);
@@ -2409,9 +2930,7 @@ const xiaohongshuPublish = async (task, params)=>{
2409
2930
  if ("mockApi" === params.actionType) return xiaohongshuPublish_mock_mockAction(task, params);
2410
2931
  return executeAction(xiaohongshuPublish_mock_mockAction, xiaohongshuPublish_rpa_rpaAction)(task, params);
2411
2932
  };
2412
- var package_namespaceObject = {
2413
- i8: "1.2.4"
2414
- };
2933
+ var package_namespaceObject = JSON.parse('{"i8":"1.2.6-beta.0"}');
2415
2934
  class Action {
2416
2935
  constructor(task){
2417
2936
  this.task = task;