index.js 960 B

123456789101112131415161718192021222324252627282930
  1. const got = require("got");
  2. const axios = require("axios");
  3. const APPID = "wxf22759845920b6f3";
  4. const SECRET = "149873f78958781cd1693c1238deaebc";
  5. exports.main = async (event, context) => {
  6. let tokenUrl = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${APPID}&secret=${SECRET}`;
  7. let res = await got(tokenUrl);
  8. let { access_token } = JSON.parse(res.body);
  9. let res0 = await axios.post(
  10. `https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=${access_token}`,
  11. {
  12. template_id: "YTj1RsoMlJW1PFV0JoozU3UTZ4DY-eVvvdK_6OSWBws",
  13. touser: "oiOWR5ch3L_mD2uYwSemzedDdG8I",
  14. page: "pages/demo/demo",
  15. miniprogram_state: "developer",
  16. lang: "zh_CN",
  17. data: {
  18. thing1: { value: "发财998" },
  19. thing4: { value: "开始装货" },
  20. thing9: { value: "请穿戴安全装备" },
  21. time5: { value: "2024-01-01 18:29" },
  22. },
  23. }
  24. );
  25. return res0;
  26. };