收藏
回答

微信公众号自定义菜单问题

var menu = {
    button: [
      {
        type: "view", //view表示跳转
        name: "历史文章",
        url:
          "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI4MTkwMTk5OA==&scene=124#wechat_redirect"
      },
      {
        name: "茄叔电影",
        sub_button: [
          //二级菜单
          {
            type: "miniprogram",
            name: "在线观影",
            url:
              "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI4MTkwMTk5OA==&scene=124#wechat_redirect",
            appid: "*********",
            pagepath: "pages/home_page/home_page"
          },
          {
            type: "click",
            name: "看电影App",
            key: "SEND_APP"
          },
          {
            type: "click", //view表示跳转
            name: "商务合作",
            key: "CONTACT_US"
          }
        ]
      }
    ]
  };

自定义菜单栏我是这样设置的,然后根据click的key值做相应事件:

if (json.xml.MsgType == 'event') {
          if (json.xml.EventKey == 'CONTACT_US') {
            res.send(getImgXmlContact(json, backTime)); //发送联系我们图片
          }
          if (json.xml.EventKey == 'SEND_APP') {
            res.send(getImgXmlApp(json, backTime)); //发送app下载二维码
          }
          if (json.xml.EventKey == 'send_img') {
            //发送默认图片
            res.send(getImgXml(json, backTime));
          }
          //如果是订阅事件
          if (json.xml.Event === "subscribe") {
            res.send(subscribeFun(json, backTime));
          }
        }

如下这是我定义的方法:

function getImgXmlContact(json, backTime) {
 
    var backXML = `
    <xml>
    <ToUserName><![CDATA[${json.xml.FromUserName}]]></ToUserName>
    <FromUserName><![CDATA[${json.xml.ToUserName}]]></FromUserName>
    <CreateTime>${backTime}</CreateTime>
    <MsgType><![CDATA[text]]></MsgType>
    <Content><![CDATA[谢谢你对影视烂番茄的青睐。和我合作,联系我们的对外商务!微信号:fay1786\n文章授权、入驻联系微信:qieshuweixin\n投稿请投送至:zhoujiale@mvmtv.cn]]></Content>
    </xml>
            `;
    return backXML;
  }

基本都是按照文档来的,可是点一下菜单就会出现对应按钮的key值,这不正常吧


商务合作的按钮对应的key值就是CONTACT_US,会以文本的形式自己发一次,麻烦大家给看看为啥!

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

1 个回答

登录 后发表内容
问题标签