zoukankan      html  css  js  c++  java
  • 手机端微网站调取微信分享接口

    $.ajax({
        url: netUrl('getShareParam'),
        type: 'post',
        dataType: 'json',
        data: {
            url: location.href.split('#')[0]
        },
        xhrFields: {
            withCredentials: true
        },
        success: function(data) {
            var data = data.infor[0];
            wx.config({
                debug: false,
                appId: 'wxec28c9eb71df4cfb',
                timestamp: data.timestamp,
                nonceStr: data.nonceStr,
                signature: data.signature,
                jsApiList: [
                    'checkJsApi',
                    'onMenuShareTimeline', //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口  
                    'onMenuShareAppMessage', //获取“分享给朋友”按钮点击状态及自定义分享内容接口  
                    'onMenuShareQQ', //获取“分享到QQ”按钮点击状态及自定义分享内容接口  
                    'onMenuShareQZone', //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口  
                    'onMenuShareWeibo' //分享到微博
                ]
            });
            wx.ready(function() {
                // 分享到朋友
                wx.onMenuShareAppMessage({
                    title: s_title, // 分享标题
                    desc: s_desc, // 分享描述
                    link: s_link, // 分享链接
                    imgUrl: preUrl('assets/i/logo.png'), // 分享图标
                    type: 'link', // 分享类型,music、video或link,不填默认为link
                    dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
                    success: function() {
                        alert("ok")
                        window.location.href = history.go(-1);
    
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                        alert('取消')
    
                    }
                });
    
                // 分享到朋友圈
                wx.onMenuShareTimeline({
                    title: s_title, // 分享标题
                    desc: s_desc, // 分享描述
                    link: s_link, // 分享链接
                    imgUrl: preUrl('assets/i/logo.png'), // 分享图标
                    success: function() {
                        alert("ok")
                        window.location.href = history.go(-1);
    
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                        alert('取消')
    
                    }
                });
                // 分享到QQ
                wx.onMenuShareQQ({
                    title: s_title, // 分享标题
                    desc: s_desc, // 分享描述
                    link: s_link, // 分享链接
                    imgUrl: preUrl('assets/i/logo.png'), // 分享图标
                    success: function() {
                        alert("ok")
                        window.location.href = history.go(-1);
    
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                        alert('取消')
    
                    }
                });
                // 分享到腾讯微博
                wx.onMenuShareWeibo({
                    title: s_title, // 分享标题
                    desc: s_desc, // 分享描述
                    link: s_link, // 分享链接
                    imgUrl: preUrl('assets/i/logo.png'), // 分享图标
                    success: function() {
                        alert("ok")
                        window.location.href = history.go(-1);
    
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                        alert('取消')
    
                    }
                });
                // 分享到QQ空间
                wx.onMenuShareQZone({
                    title: s_title, // 分享标题
                    desc: s_desc, // 分享描述
                    link: s_link, // 分享链接
                    imgUrl: preUrl('assets/i/logo.png'), // 分享图标
                    success: function() {
                        alert("ok")
                        window.location.href = history.go(-1);
    
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                        alert('取消')
    
                    }
                });
            });
    
            wx.error(function(res) {
    
            });
    
        },
        error: function(e, request, settings) {
            alert(settings);
        }
    });

    微信分享使用微信默认分享,但我们可以设置分享的内容和分享到那个平台

  • 相关阅读:
    js深入研究之自定义混合Mixin函数
    js深入研究之克隆,属性,数组,对象,函数
    PHP交易详情有感
    PHP统计排行,分页
    php获取当前月月初至月末的时间戳,上个月月初至月末的时间戳
    php编程规范
    js深入研究之无法理解的js类代码,extend扩展
    js深入研究之神奇的匿名函数类生成方式
    【编程之美】双线程高效下载
    转: 连续数打乱判断出少了哪些数?
  • 原文地址:https://www.cnblogs.com/ouchen0312/p/7365842.html
Copyright © 2011-2022 走看看