收藏
回答

请问PC端的企业微信从聊天工具栏分享消息到会话H5类型的消息为什么不管用啊?

问题类型 API/组件名称 终端类型 微信版本 基础库版本
Bug sendChatMessage 工具 3.0.30.2005 System: Unknown, WeChat 6.2

在安卓端是完全没问题的, 其它类型的也是完全没问题的, 只有news类型发送不出去..报错如下:

回答关注问题邀请回答
收藏

2 个回答

  • 沧海的雨季
    沧海的雨季
    2020-09-07
        sendMessage(item) {
          const that = this;
          this.$wx.invoke("getContext", {}, function (res) {
            if (res.err_msg == "getContext:ok") {
              const entry = res.entry; //返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools
              if (entry == "single_chat_tools" || entry == "group_chat_tools  ") {
                switch (item.type) {
                  case "文本":
                    that.$wx.invoke(
                      "sendChatMessage",
                      {
                        msgtype: "text"//消息类型,必填
                        text: {
                          content: item.content, //文本内容
                        },
                      },
                      function (res) {
                        if (res.err_msg == "sendChatMessage:ok") {
                          //发送成功
                        } else {
                          this.$toast("发送失败");
                        }
                      }
                    );
                    break;
                  case "图片":
                    that.$wx.invoke(
                      "sendChatMessage",
                      {
                        msgtype: "image"//消息类型,必填
                        image: {
                          mediaid: item.media_id, //图片的素材id
                        },
                      },
                      function (res) {
                        if (res.err_msg == "sendChatMessage:ok") {
                          //发送成功
                        } else {
                          this.$toast("发送失败");
                        }
                      }
                    );
                    break;
                  case "视频":
                    that.$wx.invoke(
                      "sendChatMessage",
                      {
                        msgtype: "video"//消息类型,必填
                        video: {
                          mediaid: item.media_id, //图片的素材id
                        },
                      },
                      function (res) {
                        if (res.err_msg == "sendChatMessage:ok") {
                          //发送成功
                        } else {
                          this.$toast("发送失败");
                        }
                      }
                    );
                    break;
                  case "文件":
                    that.$wx.invoke(
                      "sendChatMessage",
                      {
                        msgtype: "file"//消息类型,必填
                        file: {
                          mediaid: item.media_id, //图片的素材id
                        },
                      },
                      function (res) {
                        if (res.err_msg == "sendChatMessage:ok") {
                          //发送成功
                        } else {
                          this.$toast("发送失败");
                        }
                      }
                    );
                    break;
                  case "链接":
                    console.log("item", item);
                    that.$wx.invoke(
                      "sendChatMessage",
                      {
                        msgtype: "news"//消息类型,必填
                        news: {
                          link: item.link_url, //H5消息页面url 必填
                          title: item.link_title, //H5消息标题
                          desc: item.describe, //H5消息摘要
                          imgUrl: item.url, //H5消息封面图片URL
                        },
                      },
                      function (res) {
                        if (res.err_msg == "sendChatMessage:ok") {
                          //发送成功
                        } else {
                          this.$toast("发送失败");
                        }
                      }
                    );
                    break;
                  default:
                    break;
                }
              }
            } else {
              //错误处理
            }
          });
        },
    
    2020-09-07
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2020-09-07

    看错误提示是 分享链接或者图片链接错误?

    2020-09-07
    有用
    回复 10
    查看更多(5)
登录 后发表内容
问题标签