readfile.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import fs from 'fs';
  2. import https from 'https';
  3. var sendCount=0;//发送次数
  4. async function start() {
  5. const data = fs.readFileSync("stock.txt", "utf-8");
  6. //console.log("🚀 ~ start ~ data:", data);
  7. if (data){
  8. let arr=data.split("\n");
  9. let arrResult=[];
  10. for(let i=0;i<arr.length;i++){
  11. if (arr[i].indexOf("CJ_ADVISE_SEL")>0){
  12. let str=arr[i].substring(0,6);
  13. arrResult.push(str);
  14. }
  15. }
  16. for(let i=0;i<arrResult.length;i++){
  17. const url = 'https://www.kylx365.com/api/SendWXServiceTemplateMessage?UserID=1&TemplateID=ErrorRemind&ParamStr=' + arrResult[i];
  18. console.log("🚀 ~ start ~ url:", url);
  19. // 使用 https.get 发起 GET 请求
  20. const result = await new Promise((resolve, reject) => {
  21. https.get(url, (res) => {
  22. let responseData = '';
  23. res.on('data', (chunk) => {
  24. responseData += chunk;
  25. });
  26. res.on('end', () => {
  27. resolve(responseData);
  28. });
  29. sendCount++;
  30. }).on('error', (err) => {
  31. reject(err);
  32. });
  33. });
  34. console.log("🚀 ~ start ~ result:", result);
  35. }
  36. }
  37. }
  38. start();
  39. var interval1=setInterval(function(){
  40. start();
  41. if (sendCount>6){
  42. clearInterval(interval1);
  43. }
  44. },10000);