HTML5H5学习笔记前端知识

ShareSDK

2018-01-12  本文已影响87人  代码锋

基于h5页面调取手机app的分享功能,直接上代码:
需要引用<script src="./js/ShareSDK.js"></script>
下载地址:https://github.com/MobClub/New-JS-For-ShareSDK

  function getQueryString(name) {//去url上的id
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    const userId = getQueryString("userId");

    function init() { //1、配置平台信息,有开放平台账号系统的平台需要自行去申请账号
        var weixinConf = {}; //微信
        weixinConf["app_id"] = "";//此处需要app开发者给你
        weixinConf["app_secret"] = "";//此处需要app开发者给你
        platformConfig[$sharesdk.PlatformID.WechatPlatform] = weixinConf;
        //2、初始化ShareSDK
        $sharesdk.initSDKAndSetPlatfromConfig("213083b247cb1", platformConfig);
    }
    $(".btnImg").click(function () {
        var params = {
            "text": "你请客,我买单,呼朋唤友一起去(趣)约车", // 分享的文字
            "imageUrl": "http://yueche-1254224848.cossh.myqcloud.com/che/%E5%B0%8F%E5%9B%BE.jpg", // 分享的图片Url
            "title": "趣约车-星海广场站等你", //分享的标题
            "titleUrl": "http://agent.qyueche.com/sup/ShareSdk/xing.html",
            "description": "你请客,我买单,呼朋唤友一起去(趣)约车",
            "site": "ShareSDK",
            "siteUrl": "http://agent.qyueche.com/sup/ShareSdk/xing.html",
            "url": "http://agent.qyueche.com/sup/ShareSdk/xing.html",
            "type": $sharesdk.ContentType.webPage
        };

      
        $sharesdk.showShareMenu([$sharesdk.PlatformID.WeChat, $sharesdk.PlatformID.WeChatMoments], params, 100,
            100,
            function (platform, state, shareInfo, error) {
                if (shareInfo == 1) {//分享成功
                    alert('领取成功!');
                } else {
                    alert('领取失败!');
                }
            });

    })
image.png
红框位置是你想要分享的途径
image.png
圆圈位置是分享后的回调方法,最坑的就是这里,为啥,我也想问为啥
我想在分享成功之后执行点别的,比如分享成功的用户给人家个优惠券啥的,BUT,看图吧
image.png
后来换的另一种方法实现了:https://www.jianshu.com/p/2b2b566107dc
上一篇下一篇

猜你喜欢

热点阅读