@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.js CHANGED
@@ -243,6 +243,24 @@ async function copyHtmlToClipboard(page, html, options = {
243
243
  }, html);
244
244
  }
245
245
  }
246
+ function PopupListener(page, popupSelector, popKey, buttonSelector, options = {}) {
247
+ const { checkInterval = 1000, stopAfterClick = false } = options;
248
+ const popup = page.locator(popupSelector);
249
+ const button = page.locator(buttonSelector);
250
+ const intervalId = setInterval(async ()=>{
251
+ try {
252
+ if (await popup.count() > 0 && await popup.isVisible() && (await popup.textContent() || "").includes(popKey)) {
253
+ await button.click({
254
+ force: true
255
+ });
256
+ if (stopAfterClick) clearInterval(intervalId);
257
+ }
258
+ } catch (err) {}
259
+ }, checkInterval);
260
+ return ()=>{
261
+ clearInterval(intervalId);
262
+ };
263
+ }
246
264
  const parseUrlQueryString = (url)=>{
247
265
  const queryStringObject = {};
248
266
  if (!url || !url.includes("?")) return queryStringObject;
@@ -1149,13 +1167,28 @@ const QuotaType = {
1149
1167
  Normal: "kQuotaTypeMassSendNormal",
1150
1168
  ProductActivity: "kQuotaTypeMassSendProductActivity"
1151
1169
  };
1152
- const GET_QRCODE_DEFAULT_ERROR = "二维码获取异常,请稍后重试发布。";
1170
+ const GET_QRCODE_DEFAULT_ERROR = "二维码获取异常,请稍后重试。";
1153
1171
  const weixinPublish_mock_errnoMap = {
1154
- 200003: "微信公众号号登录状态失效,请重新绑定账号后重试。"
1172
+ 200003: "微信公众号号登录状态失效,请重新绑定账号后重试。",
1173
+ 420001: "封面图不支持GIF,请更换后重试。",
1174
+ 200002: "上传图片参数错误,请检查后重试。",
1175
+ 200039: "上传图片高度(像素)与宽度(像素)的乘积不能超过600万,请更换后重试。",
1176
+ 153201: "不支持发布审核中或转码中的视频",
1177
+ 200007: "登陆失败,请重新登陆账户后重试。",
1178
+ 64703: "摘要超出120字长度限制,请修改摘要后重试。",
1179
+ "-4": "不支持发布审核中或转码中的视频",
1180
+ "-2": "不支持发布审核中或转码中的视频",
1181
+ 770001: "不支持发布审核中或转码中的视频",
1182
+ 200074: "系统繁忙,请稍后重试!"
1155
1183
  };
1156
1184
  const ignoreErrno = [
1157
1185
  154019
1158
1186
  ];
1187
+ const userTypeMap = {
1188
+ 所有用户: 1,
1189
+ 已关注的用户: 2,
1190
+ 已关注7天及以上的用户: 3
1191
+ };
1159
1192
  const generatorFormData = (data)=>{
1160
1193
  const formData = new URLSearchParams();
1161
1194
  for (const [key, value] of Object.entries(data))formData.append(key, String(value));
@@ -1263,6 +1296,223 @@ const weixinPublish_mock_mockAction = async (task, params)=>{
1263
1296
  const coverRes = await uploadImages([
1264
1297
  params.settingInfo.wxCover
1265
1298
  ]);
1299
+ let oriWhitelist = null;
1300
+ if (params.settingInfo?.wxCopyright && params.settingInfo?.wxWhitelist) {
1301
+ const _oriWhitelist = params.settingInfo.wxWhitelist;
1302
+ if (_oriWhitelist && _oriWhitelist.length > 0) {
1303
+ const white_list = [];
1304
+ const white_list_user = {
1305
+ nickname: "",
1306
+ title: "可修改文章",
1307
+ openid: "",
1308
+ wx_name: "",
1309
+ username: "",
1310
+ avatar: "",
1311
+ can_modify: "1",
1312
+ can_hide_source: "0",
1313
+ can_reward: "0"
1314
+ };
1315
+ for (const _user of _oriWhitelist){
1316
+ const userInfo_res = await http.api({
1317
+ method: "post",
1318
+ url: "https://mp.weixin.qq.com/cgi-bin/appmsgcopyright?action=searchacct",
1319
+ params: {
1320
+ action: "searchacct"
1321
+ },
1322
+ data: generatorFormData({
1323
+ lang: "zh_CN",
1324
+ f: "json",
1325
+ ajax: 1,
1326
+ token: params.token,
1327
+ random: Math.random().toString(),
1328
+ username: _user
1329
+ }),
1330
+ defaultErrorMsg: "搜索用户信息失败"
1331
+ });
1332
+ if (!(userInfo_res.search_list.length > 0)) return {
1333
+ code: 200,
1334
+ message: `白名单用户:${_user} 未搜索到,请确定输入是否正确!`,
1335
+ data: ''
1336
+ };
1337
+ {
1338
+ let userInfo_resJson = userInfo_res.search_list[0];
1339
+ white_list_user.nickname = userInfo_resJson.nickname;
1340
+ white_list_user.openid = userInfo_resJson.openid;
1341
+ white_list_user.avatar = userInfo_resJson.pic_url;
1342
+ white_list_user.username = userInfo_resJson.username;
1343
+ white_list_user.wx_name = userInfo_resJson.wx_name;
1344
+ white_list.push({
1345
+ ...white_list_user
1346
+ });
1347
+ }
1348
+ }
1349
+ oriWhitelist = white_list.length > 0 ? JSON.stringify({
1350
+ white_list: white_list
1351
+ }) : "";
1352
+ }
1353
+ }
1354
+ let writerid = null;
1355
+ let reply_id = null;
1356
+ if (params.settingInfo.wxCopyright && params.settingInfo.wxRewardTarget) {
1357
+ async function getWriterList() {
1358
+ const res = await http.api({
1359
+ method: "get",
1360
+ url: 'https://mp.weixin.qq.com/acct/writermgr',
1361
+ params: {
1362
+ action: 'get_writer_list',
1363
+ fingerprint,
1364
+ token: params.token,
1365
+ lang: "zh_CN",
1366
+ f: "json",
1367
+ ajax: 1
1368
+ }
1369
+ });
1370
+ return res.pageinfo.writerlist || [];
1371
+ }
1372
+ async function getRewardText() {
1373
+ const res = await http.api({
1374
+ method: "get",
1375
+ url: 'https://mp.weixin.qq.com/merchant/reward',
1376
+ params: {
1377
+ action: 'getautoreply',
1378
+ fingerprint,
1379
+ token: params.token,
1380
+ lang: "zh_CN",
1381
+ f: "json",
1382
+ ajax: 1
1383
+ }
1384
+ });
1385
+ return res.reply_infos;
1386
+ }
1387
+ for(var _type in params.settingInfo.wxRewardTarget)if ("author" === _type) {
1388
+ if (0 == (await getWriterList()).length) {
1389
+ const rewardbind = await http.api({
1390
+ method: "get",
1391
+ url: "https://mp.weixin.qq.com/acct/writermgr",
1392
+ params: {
1393
+ action: "get_rewardbind_qrcode",
1394
+ random: Math.random().toString(),
1395
+ fingerprint,
1396
+ token: params.token,
1397
+ lang: "zh_CN",
1398
+ f: "json",
1399
+ ajax: 1
1400
+ },
1401
+ defaultErrorMsg: GET_QRCODE_DEFAULT_ERROR
1402
+ });
1403
+ const rewardBuffer = Buffer.from(rewardbind.qrcode_base64, 'base64');
1404
+ const rewardFilePath = external_node_path_default().join(tmpCachePath, "weixin_reward.jpg");
1405
+ external_node_fs_default().writeFileSync(rewardFilePath, new Uint8Array(rewardBuffer));
1406
+ params.safeQrcodeCallback?.(rewardFilePath);
1407
+ const task_id = rewardbind.task_id;
1408
+ let code = null;
1409
+ for(let i = 0; i < scanRetryMaxCount; i++){
1410
+ await (0, share_namespaceObject.sleep)(2000);
1411
+ const checkScanResult = await http.api({
1412
+ method: "get",
1413
+ url: "https://mp.weixin.qq.com/acct/writermgr",
1414
+ params: {
1415
+ action: "query_rewardbind_qrcode_status",
1416
+ task_id: task_id,
1417
+ fingerprint,
1418
+ lang: "zh_CN",
1419
+ f: "json",
1420
+ ajax: 1,
1421
+ token: params.token,
1422
+ timespam: Date.now()
1423
+ }
1424
+ });
1425
+ code = checkScanResult.qrcode_status;
1426
+ if (2 == code && (await getWriterList()).length > 0) break;
1427
+ if (i === scanRetryMaxCount - 1) return {
1428
+ code: 200,
1429
+ message: "二维码已过期,请重试绑定。",
1430
+ data: ""
1431
+ };
1432
+ }
1433
+ }
1434
+ let _writer = await getWriterList();
1435
+ for (var _writer_item of _writer)if (_writer_item.nickname === params.settingInfo.wxRewardTarget[_type]) writerid = _writer_item.writerid;
1436
+ if (!writerid) return {
1437
+ code: 200,
1438
+ message: "未匹配到赞赏绑定用户,请确认用户名与绑定是否正常!",
1439
+ data: ""
1440
+ };
1441
+ if (params.settingInfo?.wxRewardText) {
1442
+ let rewardList = await getRewardText();
1443
+ let matchdID = rewardList.find((reward)=>reward.text === params.settingInfo.wxRewardText)?.reply_id ?? null;
1444
+ if (0 != rewardList.length && matchdID) reply_id = matchdID;
1445
+ else await http.api({
1446
+ method: "post",
1447
+ url: 'https://mp.weixin.qq.com/merchant/reward',
1448
+ params: {
1449
+ action: 'addautoreply'
1450
+ },
1451
+ data: generatorFormData({
1452
+ type: 1,
1453
+ fingerprint,
1454
+ token: params.token,
1455
+ lang: "zh_CN",
1456
+ f: "json",
1457
+ ajax: 1,
1458
+ text: params.settingInfo.wxRewardText
1459
+ })
1460
+ });
1461
+ if (!matchdID) {
1462
+ for (var _reply_item of (await getRewardText()))reply_id = (await getRewardText()).find((reward)=>reward.text === params.settingInfo.wxRewardText)?.reply_id;
1463
+ if (!reply_id) return {
1464
+ code: 200,
1465
+ message: "赞赏文案添加失败,请重新检查",
1466
+ data: ""
1467
+ };
1468
+ }
1469
+ }
1470
+ }
1471
+ }
1472
+ const wxInteractionInfo = (()=>{
1473
+ const _wxInteraction = {
1474
+ need_open_comment0: 0,
1475
+ only_fans_can_comment0: 0,
1476
+ only_fans_days_can_comment0: 0,
1477
+ reply_flag0: 2,
1478
+ auto_elect_comment0: 0,
1479
+ auto_elect_reply0: 1,
1480
+ open_fansmsg0: 0
1481
+ };
1482
+ const type = params?.settingInfo?.wxInteraction?.Type ?? "";
1483
+ if ("public" === type) {
1484
+ const _opt = params?.settingInfo?.wxInteraction?.Option;
1485
+ if (!_opt || !_opt.Comment || !_opt.reply || null == _opt.elect_comment || null == _opt.elect_reply) return null;
1486
+ const commentType = userTypeMap[_opt.Comment];
1487
+ const replyType = userTypeMap[_opt.reply] + 1;
1488
+ _wxInteraction.need_open_comment0 = 1;
1489
+ switch(commentType){
1490
+ case 1:
1491
+ _wxInteraction.only_fans_can_comment0 = 0;
1492
+ _wxInteraction.only_fans_days_can_comment0 = 0;
1493
+ break;
1494
+ case 2:
1495
+ _wxInteraction.only_fans_can_comment0 = 1;
1496
+ _wxInteraction.only_fans_days_can_comment0 = 0;
1497
+ break;
1498
+ case 3:
1499
+ _wxInteraction.only_fans_can_comment0 = 0;
1500
+ _wxInteraction.only_fans_days_can_comment0 = 1;
1501
+ break;
1502
+ }
1503
+ _wxInteraction.reply_flag0 = replyType;
1504
+ _wxInteraction.auto_elect_comment0 = _opt.elect_comment ? userTypeMap[_opt.Comment] : 0;
1505
+ _wxInteraction.auto_elect_reply0 = _opt.elect_reply ? userTypeMap[_opt.reply] : 1;
1506
+ return _wxInteraction;
1507
+ }
1508
+ if ("private" === type) _wxInteraction.open_fansmsg0 = 1;
1509
+ return _wxInteraction;
1510
+ })();
1511
+ if (!wxInteractionInfo) return {
1512
+ code: 200,
1513
+ message: "互动参数设置错误,请检查参数设置!",
1514
+ data: ""
1515
+ };
1266
1516
  const draftData = {
1267
1517
  lang: "zh_CN",
1268
1518
  f: "json",
@@ -1275,16 +1525,19 @@ const weixinPublish_mock_mockAction = async (task, params)=>{
1275
1525
  is_finder_video0: 0,
1276
1526
  finder_draft_id0: 0,
1277
1527
  applyori0: 0,
1278
- can_reward0: 0,
1528
+ can_reward0: writerid ? 1 : 0,
1279
1529
  pay_gifts_count0: 0,
1280
1530
  is_video_recommend0: -1,
1281
- writerid0: 0,
1531
+ writerid0: writerid ? writerid : 0,
1282
1532
  auto_gen_digest0: 0,
1283
1533
  last_choose_cover_from0: 0,
1284
- need_open_comment0: 0,
1285
- only_fans_can_comment0: 0,
1286
- only_fans_days_can_comment0: 0,
1287
- reply_flag0: 0,
1534
+ need_open_comment0: wxInteractionInfo.need_open_comment0,
1535
+ only_fans_can_comment0: wxInteractionInfo.only_fans_can_comment0,
1536
+ only_fans_days_can_comment0: wxInteractionInfo.only_fans_days_can_comment0,
1537
+ reply_flag0: wxInteractionInfo.reply_flag0,
1538
+ auto_elect_comment0: wxInteractionInfo.auto_elect_comment0,
1539
+ auto_elect_reply0: wxInteractionInfo.auto_elect_reply0,
1540
+ reward_reply_id0: params.settingInfo?.wxRewardText ? reply_id ? reply_id : 0 : 0,
1288
1541
  not_pay_can_comment0: 0,
1289
1542
  data_seq: 0,
1290
1543
  msg_index_id0: "",
@@ -1296,7 +1549,11 @@ const weixinPublish_mock_mockAction = async (task, params)=>{
1296
1549
  content0: content || "",
1297
1550
  sourceurl0: params?.settingInfo?.wxOriginalText || "",
1298
1551
  cdn_url0: coverRes[0].cdn_url || "",
1299
- open_fansmsg0: params?.settingInfo?.wxFansMsg ? 1 : 0,
1552
+ copyright_type0: params?.settingInfo?.wxCopyright ? 1 : 0,
1553
+ allow_reprint0: params?.settingInfo?.wxCopyright ? 0 : '',
1554
+ allow_reprint_modify0: params?.settingInfo?.wxCopyright ? 0 : '',
1555
+ ori_white_list0: params?.settingInfo?.wxCopyright ? oriWhitelist : '',
1556
+ open_fansmsg0: wxInteractionInfo.open_fansmsg0,
1300
1557
  allow_fast_reprint0: params?.settingInfo?.wxQuickReprint ? 1 : 0,
1301
1558
  disable_recommend0: params?.settingInfo?.wxNotAllowRecommend ? 1 : 0,
1302
1559
  claim_source_type0: params?.settingInfo?.wxCreationSource?.[0] || "",
@@ -1647,6 +1904,81 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1647
1904
  timestamp: Date.now(),
1648
1905
  appmsgid: params.appMsgId
1649
1906
  };
1907
+ if (params.settingInfo?.wxRewardTarget) {
1908
+ const urlRewardParams = {
1909
+ action: "inviteauthor",
1910
+ token: params.token,
1911
+ lang: "zh_CN"
1912
+ };
1913
+ const wxRewardPage = await task.createPage({
1914
+ show: task.debug,
1915
+ url: params.url || `https://mp.weixin.qq.com/cgi-bin/safecenterstatus?${Object.entries(urlRewardParams).map((it)=>it.join("=")).join("&")}`,
1916
+ cookies: params.cookies?.map((it)=>({
1917
+ ...commonCookies,
1918
+ ...it
1919
+ })) || []
1920
+ });
1921
+ const reward_page = wxRewardPage.locator("#app");
1922
+ const isAddRewarder = reward_page.locator('.author_card_bd.weui-desktop-vm_primary').filter({
1923
+ hasText: params.settingInfo.wxRewardTarget.author
1924
+ }).count();
1925
+ if (await isAddRewarder == 0) {
1926
+ await reward_page.locator('.weui-desktop-panel__hd-right').click();
1927
+ try {
1928
+ try {
1929
+ await wxRewardPage.waitForSelector('.invite-qrcode', {
1930
+ state: 'visible',
1931
+ timeout: 20000
1932
+ });
1933
+ const qrcodeSrc = await reward_page.locator(".invite-qrcode").getAttribute('src');
1934
+ if (qrcodeSrc) {
1935
+ const rewardBuffer = Buffer.from(qrcodeSrc.replace(/^data:image\/\w+;base64,/, ''), 'base64');
1936
+ const rewardFilePath = external_node_path_default().join(tmpCachePath, "weixin_reward.jpg");
1937
+ external_node_fs_default().writeFileSync(rewardFilePath, new Uint8Array(rewardBuffer));
1938
+ params.safeQrcodeCallback?.(rewardFilePath);
1939
+ }
1940
+ } catch (error) {
1941
+ throw new Error("二维码已过期,请重试绑定。");
1942
+ }
1943
+ for(let i = 0; i < scanRetryMaxCount; i++){
1944
+ await Promise.all([
1945
+ wxRewardPage.reload(),
1946
+ wxRewardPage.waitForLoadState('domcontentloaded')
1947
+ ]);
1948
+ try {
1949
+ await wxRewardPage.waitForSelector(`.author_card_bd.weui-desktop-vm_primary:has-text("${params.settingInfo.wxRewardTarget?.author}")`, {
1950
+ timeout: 1000
1951
+ });
1952
+ break;
1953
+ } catch (error) {}
1954
+ if (i === scanRetryMaxCount - 1) throw new Error("未确认绑定账户,请在手机端确认绑定并重试");
1955
+ }
1956
+ } catch (error) {
1957
+ let errorMessage = "发生未知错误";
1958
+ if (error instanceof Error) errorMessage = error.message;
1959
+ else if ("string" == typeof error) errorMessage = error;
1960
+ await wxRewardPage.close();
1961
+ return {
1962
+ code: 200,
1963
+ message: errorMessage,
1964
+ data: ""
1965
+ };
1966
+ }
1967
+ }
1968
+ if (params.settingInfo.wxRewardText) {
1969
+ await wxRewardPage.locator('[href="/merchant/reward?action=getautoreply"]').click();
1970
+ await wxRewardPage.waitForLoadState('networkidle');
1971
+ const isAddWord = reward_page.locator(".auto-reply__list.edit .auto-reply__hd .auto-reply__text").filter({
1972
+ hasText: new RegExp(`^${params.settingInfo.wxRewardText}$`)
1973
+ }).count();
1974
+ if (await isAddWord == 0) {
1975
+ await reward_page.locator(".emotion_editor .edit_area").fill(params.settingInfo.wxRewardText);
1976
+ await reward_page.locator(".emotion_editor .edit_area").click();
1977
+ await reward_page.locator(".editor_toolbar .weui-desktop-btn.weui-desktop-btn_primary").click();
1978
+ }
1979
+ }
1980
+ await wxRewardPage.close();
1981
+ }
1650
1982
  const page = await task.createPage({
1651
1983
  show: task.debug,
1652
1984
  url: params.url || `https://mp.weixin.qq.com/cgi-bin/appmsg?${Object.entries(urlParams).map((it)=>it.join("=")).join("&")}`,
@@ -1669,6 +2001,10 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1669
2001
  await page.waitForSelector("#editor_pannel", {
1670
2002
  state: "visible"
1671
2003
  });
2004
+ PopupListener(page, '[v-transfer-dom="#vue_app"] .weui-desktop-dialog', "更新", '[v-transfer-dom="#vue_app"] .weui-desktop-icon-btn.weui-desktop-dialog__close-btn', {
2005
+ checkInterval: 1000,
2006
+ stopAfterClick: false
2007
+ });
1672
2008
  const titleInstance = page.locator("#js_title_main textarea#title");
1673
2009
  await titleInstance.click();
1674
2010
  await titleInstance.fill(params.title);
@@ -1710,7 +2046,15 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1710
2046
  await page.waitForSelector(".weui-desktop-img-picker__list .weui-desktop-img-picker__item.selected", {
1711
2047
  state: "visible"
1712
2048
  });
1713
- await page.waitForTimeout(1000);
2049
+ await page.waitForSelector('.weui-desktop-upload__file__progress', {
2050
+ state: 'detached'
2051
+ });
2052
+ const pic_msg = page.locator('.weui-desktop-img-picker__list .weui-desktop-img-picker__item.selected .weui-desktop-upload__file__msg');
2053
+ if (await pic_msg.count() > 0) return {
2054
+ code: 200,
2055
+ message: "图片上传错误:" + (await pic_msg.textContent() || "未知错误,请重试!"),
2056
+ data: ""
2057
+ };
1714
2058
  await dialog.locator(".weui-desktop-dialog__ft .weui-desktop-btn:not(.weui-desktop-btn_disabled)").filter({
1715
2059
  hasText: "下一步"
1716
2060
  }).click();
@@ -1723,6 +2067,124 @@ const weixinPublish_rpa_rpaAction = async (task, params)=>{
1723
2067
  hasText: "确认"
1724
2068
  }).click();
1725
2069
  }
2070
+ if (params.settingInfo.wxCopyright) {
2071
+ await page.locator('#js_original').click();
2072
+ const ori_dialog = page.locator('.claim__original-dialog.original_dialog');
2073
+ const ori_dialog_bd = ori_dialog.locator('.weui-desktop-dialog__bd');
2074
+ const ori_dialog_ft = ori_dialog.locator('.weui-desktop-dialog__ft');
2075
+ await ori_dialog_bd.locator('.weui-desktop-form__check-content').filter({
2076
+ hasText: "文字原创"
2077
+ }).click();
2078
+ if (params.settingInfo?.wxWhitelist) for (var _target of params.settingInfo.wxWhitelist){
2079
+ await ori_dialog_bd.locator('#js_article_whitelist_search').fill(_target);
2080
+ await ori_dialog_bd.locator('.js_search').click();
2081
+ const search_res = ori_dialog_bd.locator('#js_article_whitelist_search_result > div');
2082
+ await page.waitForTimeout(1000);
2083
+ if (await search_res.getAttribute('class') === 'search-result-title search-result-empty') return {
2084
+ code: 200,
2085
+ message: `白名单用户:${_target} 未搜索到,请确定输入是否正确!`,
2086
+ data: ''
2087
+ };
2088
+ {
2089
+ const search_res_name = await search_res.locator('.search-result-name-left').textContent() || void 0;
2090
+ await search_res.click();
2091
+ const whrite_list = ori_dialog_bd.locator('#js_article_whitelist_added tbody');
2092
+ const white_td_isadd = await whrite_list.locator('.table-td-name').filter({
2093
+ hasText: search_res_name
2094
+ }).count();
2095
+ if (!white_td_isadd) return {
2096
+ code: 200,
2097
+ message: '白名单添加失败,请重试!',
2098
+ data: ''
2099
+ };
2100
+ }
2101
+ }
2102
+ if (params.settingInfo?.wxQuickReprint) {
2103
+ const btn_isChecked = await ori_dialog_bd.locator('//span[@class="frm_tips"]').filter({
2104
+ hasText: '已开启'
2105
+ }).count() == 1;
2106
+ if (!btn_isChecked) await ori_dialog_bd.locator('.weui-desktop-switch_loading .weui-desktop-switch__box').click();
2107
+ }
2108
+ const checkbox = ori_dialog_ft.locator('.weui-desktop-icon-checkbox');
2109
+ if (!await checkbox.isChecked()) await checkbox.check();
2110
+ await ori_dialog_ft.locator('.weui-desktop-btn.weui-desktop-btn_primary').click();
2111
+ if (params.settingInfo?.wxRewardTarget) {
2112
+ await page.locator('#js_reward_setting_area').click();
2113
+ const reward_setting = page.locator('.reward-setting-dialog');
2114
+ const reward_setting_bd = reward_setting.locator('.weui-desktop-dialog__bd');
2115
+ const reward_setting_ft = reward_setting.locator('.weui-desktop-dialog__ft');
2116
+ for(var _type in params.settingInfo.wxRewardTarget)if ("author" === _type) {
2117
+ let userName = params.settingInfo.wxRewardTarget[_type];
2118
+ await reward_setting_bd.locator('.weui-desktop-form__check-label', {
2119
+ hasText: '赞赏作者'
2120
+ }).click();
2121
+ await reward_setting_bd.locator('.weui-desktop-form__input').fill(userName);
2122
+ if (params.settingInfo.wxRewardText) {
2123
+ const reward_setting_replay = page.locator('.reward-reply-setting');
2124
+ const switchAuto = reward_setting_replay.locator('.weui-desktop-switch__box');
2125
+ const maxAttempts = 5;
2126
+ const delayMs = 500;
2127
+ let nowCheckTime = 0;
2128
+ for(let attempt = 0; attempt < maxAttempts; attempt++){
2129
+ const isDisabled = await switchAuto.isDisabled();
2130
+ if (!isDisabled) {
2131
+ await switchAuto.isChecked() && nowCheckTime++;
2132
+ if (2 == nowCheckTime) break;
2133
+ }
2134
+ if (attempt === maxAttempts - 1) throw new Error('Checkbox did not become enabled within the timeout.');
2135
+ await new Promise((resolve)=>setTimeout(resolve, delayMs));
2136
+ }
2137
+ const isOneReplay = await reward_setting_replay.locator('.reward-reply-select__wrp >.reward-reply-select__tips').textContent() == "添加新的回复";
2138
+ const isCurrentReplay = await reward_setting_replay.locator('.reward-reply-select__wrp >.reward-reply-select__display .wording').filter({
2139
+ hasText: new RegExp(`^${[
2140
+ params.settingInfo.wxRewardText
2141
+ ]}$`)
2142
+ }).count() == 1;
2143
+ if (!isOneReplay && !isCurrentReplay) {
2144
+ await reward_setting_replay.locator('.reward-reply-select__wrp >.reward-reply-select__tips').click();
2145
+ await reward_setting_replay.locator('.reward-reply-select__display.can-select .wording').filter({
2146
+ hasText: new RegExp(`^${[
2147
+ params.settingInfo.wxRewardText
2148
+ ]}$`)
2149
+ }).click();
2150
+ }
2151
+ } 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();
2152
+ }
2153
+ const checkbox = reward_setting_ft.locator('.weui-desktop-icon-checkbox');
2154
+ if (!await checkbox.isChecked()) await checkbox.check();
2155
+ await reward_setting_ft.locator('.weui-desktop-btn.weui-desktop-btn_primary').click();
2156
+ }
2157
+ }
2158
+ if (params.settingInfo?.wxInteraction) {
2159
+ await page.locator('.appmsg-editor__setting-group.js_interaction_cell').click();
2160
+ const wxInteraction_setting = page.locator('.interaction-dialog');
2161
+ const wxInteraction_bd = wxInteraction_setting.locator('.weui-desktop-dialog__bd');
2162
+ const wxInteraction_ft = wxInteraction_setting.locator('.weui-desktop-dialog__ft');
2163
+ if ("public" == params.settingInfo.wxInteraction.Type) {
2164
+ await wxInteraction_bd.locator('.weui-desktop-form__check-label', {
2165
+ hasText: '留言'
2166
+ }).click();
2167
+ const comment_area = wxInteraction_bd.locator('.comment-options-block.pt0');
2168
+ const reply_area = wxInteraction_bd.locator('.comment-options-block.bb0.pb0');
2169
+ const commont_rply_opt = page.locator('.weui-desktop-popper.options-popover[x-placement="bottom"]');
2170
+ await comment_area.locator('.comment-options__selector-btn').click();
2171
+ await commont_rply_opt.locator('.weui-desktop-form__check-label', {
2172
+ hasText: params.settingInfo.wxInteraction.Option?.Comment
2173
+ }).click();
2174
+ if (params.settingInfo.wxInteraction.Option?.elect_comment) await comment_area.locator('.weui-desktop-switch__box').check();
2175
+ else await comment_area.locator('.weui-desktop-switch__input').isChecked() && comment_area.locator('.weui-desktop-switch__box').uncheck();
2176
+ await page.waitForTimeout(1000);
2177
+ await reply_area.locator('.comment-options__selector-btn').click();
2178
+ await commont_rply_opt.locator('.weui-desktop-form__check-label', {
2179
+ hasText: params.settingInfo.wxInteraction.Option?.reply
2180
+ }).click();
2181
+ if (params.settingInfo.wxInteraction.Option?.elect_reply) await reply_area.locator('.weui-desktop-switch__box').check();
2182
+ else await reply_area.locator('.weui-desktop-switch__input').isChecked() && reply_area.locator('.weui-desktop-switch__box').uncheck();
2183
+ } else if ("private" == params.settingInfo.wxInteraction.Type) await wxInteraction_bd.locator('.weui-desktop-form__check-label', {
2184
+ hasText: '快捷私信'
2185
+ }).click();
2186
+ await wxInteraction_ft.locator('.weui-desktop-btn.weui-desktop-btn_primary').click();
2187
+ }
1726
2188
  if (params.settingInfo.wxOriginalText) {
1727
2189
  await page.locator("#js_article_url_area .allow_click_opr").click();
1728
2190
  await page.waitForTimeout(200);
@@ -2084,7 +2546,8 @@ class XsEncrypt {
2084
2546
  }
2085
2547
  }
2086
2548
  const xiaohongshuPublish_mock_errnoMap = {
2087
- 903: "账户已登出,需重新登陆重试!"
2549
+ 903: "账户已登出,需重新登陆重试!",
2550
+ 902: "登录已过期,请重新登录!"
2088
2551
  };
2089
2552
  const xsEncrypt = new XsEncrypt();
2090
2553
  const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
@@ -2154,13 +2617,62 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
2154
2617
  };
2155
2618
  };
2156
2619
  const coverInfos = await Promise.all(params.banners.map((it, idx)=>uploadFile(it, idx)));
2620
+ const searchTopic = async (topic)=>await http.api({
2621
+ method: "post",
2622
+ url: "https://edith.xiaohongshu.com/web_api/sns/v1/search/topic",
2623
+ data: {
2624
+ keyword: topic,
2625
+ suggest_topic_request: {
2626
+ title: "",
2627
+ desc: `#${topic}`
2628
+ },
2629
+ page: {
2630
+ page_size: 20,
2631
+ page: 1
2632
+ }
2633
+ },
2634
+ defaultErrorMsg: "话题搜索异常,请稍后重试。"
2635
+ });
2636
+ let topicDesc = [];
2637
+ params.topic && params.topic.length > 0 && await Promise.all(params.topic.map(async (topic)=>{
2638
+ let topicInfo = {
2639
+ id: null,
2640
+ name: null,
2641
+ type: "topic"
2642
+ };
2643
+ const _topicInfo = await searchTopic(topic);
2644
+ if (0 === _topicInfo.data.topic_info_dtos.length || _topicInfo.data.topic_info_dtos[0].name !== topic) {
2645
+ const topicData = {
2646
+ topic_names: topic
2647
+ };
2648
+ const topicDataStr = xsEncrypt.dumps(topicData);
2649
+ const publishXt = Date.now().toString();
2650
+ const publishXs = await xsEncrypt.encryptXs(`/web_api/sns/capa/postgw/topic/batch_customized${topicDataStr}`, a1Cookie, publishXt);
2651
+ let createTopic = await http.api({
2652
+ method: "POST",
2653
+ url: "https://edith.xiaohongshu.com/web_api/sns/capa/postgw/topic/batch_customized",
2654
+ headers: {
2655
+ "x-s": publishXs,
2656
+ "x-t": publishXt
2657
+ },
2658
+ data: topicData,
2659
+ defaultErrorMsg: "话题创建异常,请稍后重试。"
2660
+ });
2661
+ Object.assign(topicInfo, createTopic.data.topic_infos[0]);
2662
+ } else {
2663
+ topicInfo.id = _topicInfo.data.topic_info_dtos[0].id;
2664
+ topicInfo.name = _topicInfo.data.topic_info_dtos[0].name;
2665
+ topicInfo.link = _topicInfo.data.topic_info_dtos[0].link;
2666
+ }
2667
+ topicDesc.push(topicInfo);
2668
+ }));
2157
2669
  const publishData = {
2158
2670
  common: {
2159
2671
  ats: [],
2160
2672
  biz_relations: [],
2161
- desc: params?.content,
2673
+ desc: params?.content + (params?.topic?.map((it)=>`#${it}[话题]#`).join("") || ""),
2162
2674
  goods_info: {},
2163
- hash_tag: [],
2675
+ hash_tag: topicDesc,
2164
2676
  note_id: "",
2165
2677
  source: JSON.stringify({
2166
2678
  type: "web",
@@ -2278,6 +2790,7 @@ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
2278
2790
  '/api/galaxy/v2/creator/activity_center/list',
2279
2791
  '/web_api/sns/v5/creator/topic/template/list',
2280
2792
  '/web_api/sns/v5/creator/file/encryption',
2793
+ '/web_api/sns/capa/postgw/topic/batch_customized',
2281
2794
  '/web_api/sns/v2/note'
2282
2795
  ];
2283
2796
  await page.route('**', async (route, request)=>{
@@ -2357,7 +2870,7 @@ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
2357
2870
  data: page.url()
2358
2871
  };
2359
2872
  }
2360
- await page.locator("#content-area .menu-container .publish-video a").click();
2873
+ await page.locator("#content-area .menu-container .publish-video .btn").click();
2361
2874
  await page.locator('.creator-container .header .creator-tab:not([style*="-9999px"]) .title').filter({
2362
2875
  hasText: /^上传图文$/
2363
2876
  }).click();
@@ -2374,7 +2887,15 @@ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
2374
2887
  await titleInstance.fill(params.title);
2375
2888
  const descInstance = page.locator(".editor-container #quillEditor .ql-editor");
2376
2889
  await descInstance.click();
2377
- await descInstance.fill(params.content);
2890
+ await descInstance.pressSequentially(params.content);
2891
+ if (params.topic && params.topic.length > 0) for (const it of params.topic){
2892
+ await descInstance.pressSequentially(`#${it}`);
2893
+ await page.locator('.ql-mention-loading').waitFor({
2894
+ state: 'detached'
2895
+ });
2896
+ await page.waitForTimeout(1000);
2897
+ await page.locator('#quill-mention-item-0 .item-view-num').click();
2898
+ }
2378
2899
  const container = page.locator(".creator-container .content .scroll-content");
2379
2900
  await container.focus();
2380
2901
  await page.mouse.wheel(0, 500);
@@ -2460,9 +2981,7 @@ const xiaohongshuPublish = async (task, params)=>{
2460
2981
  if ("mockApi" === params.actionType) return xiaohongshuPublish_mock_mockAction(task, params);
2461
2982
  return executeAction(xiaohongshuPublish_mock_mockAction, xiaohongshuPublish_rpa_rpaAction)(task, params);
2462
2983
  };
2463
- var package_namespaceObject = {
2464
- i8: "1.2.4"
2465
- };
2984
+ var package_namespaceObject = JSON.parse('{"i8":"1.2.6-beta.0"}');
2466
2985
  class Action {
2467
2986
  constructor(task){
2468
2987
  this.task = task;