const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext();
const now = new Date();
const hour = now.getHours() + 8;
const weekDay = now.getDay();
if ((now.getMonth() == 5) && (now.getDate() == 25 || now.getDate() == 26 || now.getDate() == 27)) {
await sendQRCode(wxContext);
return "success"
}
if (0 == weekDay || 6 == weekDay) {
await sendQRCode(wxContext);
return "success"
}
if (!(hour >= 9 && hour < 12) && !(hour >= 14 && hour < 19)) {
await sendQRCode(wxContext);
return "success"
}
return transferCustomerService(wxContext);
}
async function sendQRCode(wxContext) {
await cloud.openapi.customerServiceMessage.send({
touser: wxContext.OPENID,
msgtype: "image",
image: {
mediaId: "xL15SxwV_d9eO5m9V-svpIiCXCkKqS39SbzFjR2z7M7Wq9FFcYZV6dsO7J922yhB"
}
})
}
function transferCustomerService(wxContext) {
return {
MsgType: 'transfer_customer_service',
ToUserName: wxContext.OPENID,
FromUserName: "dsadas",
CreateTime: parseInt( +new Date / 1000),
}
}
level:error
function:sendCustomerServiceMsg
requestId:7d73bbb9-af78-11ea-aee9-52540083628c
msg:ERROR RequestId:7d73bbb9-af78-11ea-aee9-52540083628c Result:{"errCode":1,"errMsg":"user code exception caught","stackTrace":"errCode: -1 unknown error | errMsg: openapi.customerServiceMessage.send:fail system error hint: [dwc1ta0262kv22]\nError: errCode: -1 unknown error | errMsg: openapi.customerServiceMessage.send:fail system error hint: [dwc1ta0262kv22]\n at callWXOpenAPI (/var/user/node_modules/wx-server-sdk/index.js:2227:31)\n at \u003canonymous\u003e\n at process._tickCallback (internal/process/next_tick.js:188:7)"}
检查下参数呢?用 http 方式能调通吗?