当前位置:   article > 正文

微信小程序客服自动回复二维码或者H5图文连接_小程序通过客服消息-回复公众号二维码

小程序通过客服消息-回复公众号二维码

微信小程序客服默认后台只支持回复文字。

如果你想自动回复二维码图片,或者一个H5页面的连接怎么办。之前要用自己服务器写接口,现在有了云函数简单多了。

第一步,添加一个云函数msgPush

直接上代码

  1. // 云函数入口文件
  2. const cloud = require('wx-server-sdk')
  3. cloud.init()
  4. //<!--下载云存储图片-->
  5. let downLoad = async (event, context) => {
  6. const res = await cloud.downloadFile({
  7. fileID: 'cloud://bvread-test-hvcev.6276-bvread-test-hvcev-1302378864/640.png', // 图片的File ID,提前通过云开发控制台上传的图片fileId
  8. })
  9. const buffer = res.fileContent
  10. console.log(buffer)
  11. return buffer
  12. }
  13. //<!--把媒体文件上传到微信服务器-->
  14. let upload = async (Buffer) => {
  15. return await cloud.openapi.customerServiceMessage.uploadTempMedia({
  16. type: 'image',
  17. media: {
  18. contentType: 'image/png',
  19. value: Buffer
  20. }
  21. })
  22. }
  23. // 云函数入口函数
  24. exports.main = async (event, context) => {
  25. const wxContext = cloud.getWXContext()
  26. if (event.MsgType == 'miniprogrampage') {
  27. await cloud.openapi.customerServiceMessage.send({
  28. touser: wxContext.OPENID,
  29. msgtype: 'text',
  30. text: {
  31. content: '收到 MsgType=' + event.MsgType + ';content=' + event.Content,
  32. },
  33. })
  34. } else if (event.MsgType == 'image') {
  35. let Buffer = await downLoad()
  36. let meida = await upload(Buffer)
  37. await cloud.openapi.customerServiceMessage.send({
  38. "touser": wxContext.OPENID,
  39. "msgtype": "image",
  40. "image": {
  41. "media_id": meida.mediaId
  42. }
  43. })
  44. } else {
  45. await cloud.openapi.customerServiceMessage.send({
  46. 'touser': wxContext.OPENID,
  47. 'msgtype': 'link',
  48. 'link':{
  49. 'title': '标题1',
  50. 'url': 'https://www.baidu.com',
  51. 'description': '描述',
  52. 'thumb_url': 'url'
  53. }
  54. })
  55. }
  56. return 'success'
  57. }

第二步,打开云开发,添加云函数消息推送

 记得添加EVENT事件

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/341498
推荐阅读
相关标签
  

闽ICP备14008679号