• 微信朋友圈分享--代码分享


    1.首先,html页面要链接

    <script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    
    
    
    
    
    2.判断是否为微信里浏览器打开?
    //使用用微信打开
    var checkPlat = {
    isAndroid: function (ua) {
    ua = ua || navigator.userAgent;
    return ua.toLowerCase().indexOf('android') > -1;
    },

    isIOS: function (platform) {
    if (navigator && navigator.platform) {
    platform = platform || navigator.platform;
    // return /iP(?:hone|od|ad)/.test(platform);
    return /iP(?:hone|od|ad)/.test(navigator.userAgent);
    } else {
    return false;
    }
    },

    isWeixin: function (ua) {
    ua = ua || navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
    return true;
    } else {
    return false;
    }
    }
    }



    
    
    

    3.使用以下js:

    function shareFn(returnObj, callback) {
    $.ajax({
    url: "/zm_bonus/getConfigInfo",
    type: "post",
    dataType: "json",
    async: false,
    data: {"url": window.location.href},
    success: function (r) {
    wx.config({
    //debug: true, //开启调试模式
    appId: r.msg.appId, // 必填,公众号的唯一标识
    timestamp: r.msg.timestamp, // 必填,生成签名的时间戳
    nonceStr: r.msg.nonceStr, // 必填,生成签名的随机串
    signature: r.msg.signature,// 必填,签名,见附录1
    // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
    jsApiList: [
    'checkJsApi',
    'onMenuShareTimeline',
    'onMenuShareAppMessage',
    'onMenuShareQQ',
    'onMenuShareWeibo',
    'getNetworkType',
    'previewImage',
    'hideOptionMenu',
    'showOptionMenu'
    ]
    });

    wx.ready(function () {
    wx.showOptionMenu();
    var obj = returnObj.call(null, r);
    wx.onMenuShareAppMessage(obj);
    wx.onMenuShareTimeline(obj);
    wx.onMenuShareWeibo(obj);
    wx.onMenuShareQQ(obj);
    wx.showMenuItems({
    menuList: [
    "menuItem:share:appMessage",
    "menuItem:share:timeline",
    "menuItem:share:qq",
    "menuItem:share:weiboApp",
    "menuItem:share:QZone"
    ]
    });
    callback.call(null);
    });
    },
    error: function () {
    alert("网络错误请重试");
    }
    });
    }

    shareFn(function (data) {
    // var _link = window.location.host + "/register.html?inviter=" + encodeURIComponent(r.msg.userName || "");
    var _link = window.location.href;
    return {
    title: "让爱传递",//分享的主题
    desc: "帮孩子实现梦想",//分享的内容
    link: _link,//分享后的跳转的页面链接
    imgUrl: "xxxxx/images/com-dev-share.png",//分享后显示的icon
    success: function () {
          if (!checkPlat.isWeixin()) {return alert("请在微信客户端打开链接,邀请好友!");} 
          else if (!checkPlat.isWeixin()) {return alert("请在微信客户端打开链接,立即分享!");}
          else if(checkPlat.isWeixin()){//成功后的提示alert(分享成功);}
            },
    cancel: function () {
    },
    fail: function () {
    alert("邀请失败请重试!");
    }
    }
    });
    
    


  • 相关阅读:
    XCOJ1250: 语言战争
    XCOJ 1249: 全自动奖学金计算系统
    杭电 2159 fate(二维背包费用问题)
    杭电 1059 Dividing
    背包问题的模版
    Shell解析器
    Shell简介
    SpringBoot配置文件占位符
    @ImportResource、@Bean
    @ImportResource注解;
  • 原文地址:https://www.cnblogs.com/fcan/p/4739051.html
Copyright © 2020-2023  润新知