微信分享和釘釘分享的設置

在天貓超級粉絲日的H5製做中須要同時能分享到釘釘和微信。見代碼 在html的head中加入javascript

//釘釘
<script type="text/javascript" src="https://g.alicdn.com/dingding/open-develop/1.9.0/dingtalk.js"></script>
//微信
<script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
複製代碼
let imgUrl = require('./images/shareIcon.jpg');
(function () {
    // alert(dd.isDingtalk());
    dd.ready(function () {
        dd.biz.navigation.setRight({
            show: true,//控制按鈕顯示, true 顯示, false 隱藏, 默認true
            control: true,//是否控制點擊事件,true 控制,false 不控制, 默認false
            text: '...',//控制顯示文本,空字符串表示顯示默認文本
            onSuccess: function (result) {
                //若是control爲true,則onSuccess將在發生按鈕點擊事件被回調
                dd.biz.util.share({
                    type: 0, //分享類型,0:所有組件 默認; 1:只能分享到釘釘;2:不能分享,只有刷新按鈕
                    url: window.location.href,
                    content: '分享描述',
                    title: '分享標題',
                    image: 'https://XXXX' + imgUrl,
                    onSuccess: function () {
                        //onSuccess將在分享完成以後回調
                        /**/
                    },
                    onFail: function (err) { }
                })
            },
            onFail: function (err) { }
        });
    })
})();
(function () {

    window.getConfig = function (config) {
        config = Object.assign({}, config, {
            debug: false,
            jsApiList: [
                "onMenuShareTimeline",
                "onMenuShareAppMessage",
                "hideAllNonBaseMenuItem",
                "showMenuItems",
                "showOptionMenu",
                "hideOptionMenu"
            ]
        })
        return config;
    }

    window.wxShareOpt = {
        title: "分享標題",
        imgUrl: 'https://xxx' + imgUrl,
        desc: "分享描述",
    }
    window.wxShareOpt.link = window.location.href;
    window.addEventListener('hashchange', () => {
        window.wxShareOpt.link = window.location.href;
        wx.onMenuShareTimeline(window.wxShareOpt);
        wx.onMenuShareAppMessage(window.wxShareOpt);
    })

    let tkurl='xxxx';//微信驗證地址
    axios.get('tkurl', {
        params: {
            appId: 'XXXXXXXXX',
            url: window.location.href,
        }
    }).then((data) => {
        // console.log(data);
        wx.config(window.getConfig(data.data.result));
    })
    wx.ready(() => {
        wx.onMenuShareTimeline(window.wxShareOpt);
        wx.onMenuShareAppMessage(window.wxShareOpt);
    });

    wx.error(() => {
        //alert("微信初始化失敗");
    });
})();
複製代碼
相關文章
相關標籤/搜索