https://developers.weixin.qq.com/minigame/dev/wxcloud/basis/message-push.html#option-cloud
我根据上面这个教程,我使用小程序A共享了云环境给公众号B,使用一个云函数来处理用户给公众号发的消息,现在的情况是
文字消息可以接收并处理
但语音消息只能拿到 mediaid,无法再往下处理了,尝试了各种接口比如,获取临时素材,以及公众号接口云调用都不行
尝试过的做法
const result = await cloud.openapi.customerServiceMessage.getTempMedia({
mediaId: event.mediaId });// 从消息事件中获取的媒体IDh
还有
const c = new cloud.Cloud({
appid: '---',
resourceAppid: '--',
resourceEnv: 'cloud1-xxx',
})
const response = await cloud.openapi({
appid: '---'
}).officialAccount.media.get({
media_id: event.mediaId
})
还有只有使用 http 请求,但是没有 access token
const url = `https://api.weixin.qq.com/cgi-bin/media/get?access_token=${access_token}&media_id=${media_id}`
const response = await axios({
method: 'get',
url: url,
responseType: 'arraybuffer' // 处理二进制数据
})
const result = await cloud.openapi({ appid: '公众号的appid' }).customerServiceMessage.getTempMedia({ mediaId: event.mediaId });
首先云环境共享的情况下,云调用写法需要带入appid才行。比如这句应该这么写。
但是这个api是小程序内获取客服消息临时素材不确定行不行。你可能是得调公众号的获取素材接口。https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html
如果接口不支持云调用且没有accessToken,那么就需要你在云函数里面开一个触发器专门用来获取公众号的accessToken
具体要什么触发器获取 token,能讲一讲吗?🙏
https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloud/guide/functions/triggers.html
每个接口文档里,有标注支持云调用的,才可以在云函数中免鉴权调用openapi,否则必须通过http调用。没有access_toke,当然需要去通过接口获取了。