一、云函数message
1、index.js
const cloud = require('wx-server-sdk')
cloud.init('xxxxxxxxxxxx')
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.customerServiceMessage.send({
touser: 'OPENID',
msgtype: 'text',
text: {
content: 'Hello World'
}
})
return result
} catch (err) {
return err
}
}
2、config.json
{
"permissions": {
"openapi": [
"templateMessage.send"
]
}
}
二、页面
1、index.js
Page({
onCon:function() {
wx.cloud.callFunction({
name: 'message',
complete: res => {
console.log('云函数 ', res)
}
})
}
})
2、index.wxml
测试
------------------------------------------------------------------------------
运行后提示错误:errCode: 45015, errMsg: "openapi.customerServiceMessage.send:fail response …ption is canceled rid: xxxxxx-xxxxxxaa-xxxxxxxxx