微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

【技】微信开发,分享到朋友圈、QQ、空间等api接口方法使用

项目在微信端开发,要求在宝贝详情页,分享到朋友圈等渠道,别人点击分享跳到网站,带该邀请人的邀请id等

添加注册渠道标示
   function init (){
         var invite_type = 2;   //如果该宝贝被分享,则记录邀请类型,邀请类型为2,是宝贝分享邀请
         inviteCode(invite_type);
   }
分享商品邀请好友]
 * @param  {[type]} invite_type [邀请的类型 2:为宝贝分享邀请]
 * @return {[type]}             [description]
 */

function inviteCode(invite_type) {
$.ajax({
url: '/invite/getInvitedCode',type: 'post',dataType: 'json',success: function(data) {
var iv_text = $('#ivCode').html();
var invite_path = 'http://' + document.domain;
var invite_code = data.data.invite_code;

        var invite_link = invite_path + '/guide_page?ivCode=' + invite_code + 'ivtype=' + invite_type;

        // <a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" class="keywords">生成</a>邀请<a href="https://www.jb51.cc/tag/erweima/" target="_blank" class="keywords">二维码</a>
        //  qrCode(invite_link);
        // <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/lianjie/" target="_blank" class="keywords">链接</a>
        sharelink(invite_link);
    }
});

}

imgurl = rootPath + '/images/invite_friends/share_240.jpg';
                // 注册微信分享
                initWX(appid,timestamp,signature,lineLink,descContent,shareTitle,imgurl);
        }
    }
});

}

imgurl) {
wx.con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>({
    debug: false,// 开启调试模式,<a href="https://www.jb51.cc/tag/diaoyong/" target="_blank" class="keywords">调用</a>的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    appId: appid,// 必填,公众号的唯一标识
    timestamp: timestamp,// 必填,<a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" class="keywords">生成</a>签名的时间戳
    nonceStr: 'shike',// 必填,<a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" class="keywords">生成</a>签名的<a href="https://www.jb51.cc/tag/suiji/" target="_blank" class="keywords">随机</a>串
    signature: signature,// 必填,签名,见附录1
    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'
        ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});

wx.ready(function() {
    /* <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a>到朋友圈 */
    wx.onMenuShareTimeline({
        title: descContent,// <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/biaoti/" target="_blank" class="keywords">标题</a>
        link: lineLink,// <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/lianjie/" target="_blank" class="keywords">链接</a>,该<a href="https://www.jb51.cc/tag/lianjie/" target="_blank" class="keywords">链接</a>域名或路径必须与<a href="https://www.jb51.cc/tag/dangqianyemian/" target="_blank" class="keywords">当前页面</a>对应的公众号JS安全域名一致
        <a href="https://www.jb51.cc/tag/imgur/" target="_blank" class="keywords">imgur</a>l: <a href="https://www.jb51.cc/tag/imgur/" target="_blank" class="keywords">imgur</a>l,success: function(res) {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>确认<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>

        },cancel: function() {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>取消<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>
        }
    });

    /* <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a>给朋友 */
    wx.onMenuShareAppMessage({
        title: shareTitle,// <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/biaoti/" target="_blank" class="keywords">标题</a>
        desc: descContent,// <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a>描述
        link: lineLink,//     type: '',// <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a>类型,music、video或link,不填<a href="https://www.jb51.cc/tag/mo/" target="_blank" class="keywords">默</a>认为link
        //     dataUrl: '',// 如果type是music或video,则要提供数据<a href="https://www.jb51.cc/tag/lianjie/" target="_blank" class="keywords">链接</a>,<a href="https://www.jb51.cc/tag/mo/" target="_blank" class="keywords">默</a>认为空
        success: function(ret) {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>确认<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>

        },cancel: function() {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>取消<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>
        }
    });


    /*<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a>到qq */
    wx.onMenuShareQQ({
        title: shareTitle,// <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/lianjie/" target="_blank" class="keywords">链接</a>
        <a href="https://www.jb51.cc/tag/imgur/" target="_blank" class="keywords">imgur</a>l: <a href="https://www.jb51.cc/tag/imgur/" target="_blank" class="keywords">imgur</a>l,success: function(ret) {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>确认<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>
        },cancel: function() {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>取消<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>

        }
    });


    /* <a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a>到qq空间 */
    wx.onMenuShareQZone({
        title: shareTitle,success: function(ret) {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>确认<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>   
        },cancel: function() {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>取消<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>
        }
    });

    wx.onMenuShareWeibo({
        title: shareTitle,cancel: function() {
            // <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" class="keywords">用户</a>取消<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a><a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" class="keywords">后执行</a>的回调<a href="https://www.jb51.cc/tag/hanshu/" target="_blank" class="keywords">函数</a>
        }
    });

});

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。