收藏
回答

云函数发送硬件消息,本地调试成功,云端执行报错,为什么?

框架类型 问题类型 终端类型 AppID 环境ID 基础库版本
小程序 Bug 工具 wxfa8ef18012f54150 muye-1g15f7t488fb4f6c 2.32.3


try {

      var alarm_time_temp= new Date()

      var alarm_time_month=alarm_time_temp.getMonth()+1

      var alarm_time=alarm_time_temp.getFullYear()+"-"+alarm_time_month+"-"+alarm_time_temp.getDate()+" "+ alarm_time_temp.getHours()+ ":" + alarm_time_temp.getMinutes() + ":" + alarm_time_temp.getSeconds()

      console.log("alarm_time=",alarm_time)

      var datax = {

        "template_id": "9f_ioRXJ1LwX5r123FzIwUAVEr_QgY4VZNsFzvZOE_Y",

        "sn": status_report[index].onenet_id,

        "page": "page/map/map",

        "to_openid_list": [

          status_report[index].openid

        ],

        "modelId": "DD1EnNuPXeaKypIflweYvw",

        "lang": "zh_CN",

        "data": {"character_string2": {"value":status_report[index].onenet_id},"time1": {"value":alarm_time}}

      }

      var accessstoken="xxxxxxxxxxxxxxx"

      var urlink = "https://api.weixin.qq.com/cgi-bin/message/device/subscribe/send?access_token="+accessstoken

      const resp = await Axios.post(urlink, datax)

      return resp

      console.log(resp)

    } catch (err{

      console.log(err)

      return err

    }

云函数本地调试执行成功

  1. [info] 函数执行成功(耗时 863ms) {status: 200, statusText: "OK", headers: {…}, config: {…}, request: ClientRequest, …}
  2. config: {url"https://api.weixin.qq.com/cgi-bin/message/device/s…H4BhT4c-gO7Etnk3frW7KyKHsyc2pvDr9BvsqB8ENNaAEAJSS"method"post"data"{"template_id":"9f_ioRXJ1LwX5r123FzIwUAVEr_QgY4VZN…7467438"},"time1":{"value":"2023-7-3 18:22:27"}}}"headers: {…}, transformRequest: Array(1), …}
  3. data: {errcode0errmsg"ok"list: Array(1)}
  4. headers: {connection"close"content-type"application/json; encoding=utf-8"date"Mon, 03 Jul 2023 10:22:29 GMT"content-length"121"}
  5. requestClientRequest {_events: {…}, _eventsCount8_maxListenersundefinedoutputData: Array(0), outputSize0, …}
  6. status200
  7. statusText"OK"
  8. [[Prototype]]: Object

手机端也收到了系统推送的订阅消息。

但是云函数运行日志显示如下错误, 手机端也收不到消息。请指导

alarm_time= 2023-7-3 10:15:1

REPORT RequestId:5549b12d-6c0f-4455-a46d-f93b744ffafd Duration:748ms Memory:512MB MemUsage:30.855469MB

END

ERROR RequestId:5549b12d-6c0f-4455-a46d-f93b744ffafd Result:{"errCode":1,"errMsg":"user code exception caught","stackTrace":"TypeError: Converting circular structure to JSON\n --\u003e starting at object with constructor 'ClientRequest'\n | property 'socket' -\u003e object with constructor 'TLSSocket'\n --- property '_httpMessage' closes the circle\n at JSON.stringify (\u003canonymous\u003e)\n at callback (/var/runtime/node12/CallbackContext.js:31:23)\n at /var/runtime/node12/CallbackContext.js:81:16\n at /var/runtime/node12/Runtime.engine.js:237:13\n at processTicksAndRejections (internal/process/task_queues.js:97:5)"}

回答关注问题邀请回答
收藏
登录 后发表内容
问题标签