2.mjs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import axios from "axios";
  2. import https from "https";
  3. import { load } from "cheerio";
  4. import stringHash from "string-hash";
  5. import fs from "fs";
  6. const { data: res } = await axios.get(
  7. "https://accounts.pcid.ca/oauth2/v1/authorize",
  8. {
  9. params: {
  10. client_id: "ed22f54785b74fe688011366a65ed5fb",
  11. response_type: "code",
  12. scope: "openid api.loblaw.digitalpco offline_access",
  13. redirect_uri: "https://pcoptimum.ca/login",
  14. },
  15. }
  16. );
  17. const $ = load(res);
  18. const form = {};
  19. $("form input").each((i, e) => {
  20. form[$(e).attr("name")] = $(e).attr("value");
  21. });
  22. const email = "linxiaojoe@hotmail.com";
  23. const password = "Andy123456$";
  24. const hashEmail = (email = "") => {
  25. const [username, domain] = email.split("@");
  26. return `${stringHash(username)}@${domain}`;
  27. };
  28. try {
  29. const httpsAgent = new https.Agent({
  30. rejectUnauthorized: false,
  31. host: "192.168.50.202",
  32. port: 9090,
  33. });
  34. const data = {
  35. email,
  36. password,
  37. loginCtx: form.loginCtx,
  38. rememberMe: false,
  39. sso: false,
  40. mandatory2fa: true,
  41. trustToken: null,
  42. deviceDetails:
  43. '{"currentTime":"Sun Mar 10 2024 02:51:27 GMT+0800 (中国标准时间)","screenWidth":390,"screenHeight":844,"screenColorDepth":24,"screenPixelDepth":24,"windowPixelRatio":3,"language":"zh-CN","userAgent":"Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1","cookieEnabled":true,"mimeTypes":0,"plugins":0,"timeZone":-480}',
  44. hashedEmail: hashEmail(email),
  45. encodedEmail: btoa(email),
  46. };
  47. console.log(JSON.stringify(data, null, 4));
  48. const { data: loginData } = await axios.post(
  49. "https://accounts.pcid.ca/login",
  50. data
  51. );
  52. console.log(loginData);
  53. } catch (error) {
  54. console.log(error.message);
  55. }