微信分享和钉钉分享的设置

在天猫超级粉丝日的H5制作中需要同时能分享到钉钉和微信。见代码 在html的head中加入

//钉钉
<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("微信初始化失败");
    });
})();
复制代码

转载于:https://juejin.im/post/5acac1e15188257cc20d92b5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值