微信分享接口修改文案方法

1.引入相关文件

<script type="tet/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

2.微信分享方法封装:

/**
    微信分享
*/
var wxShare = (function (w) {
    var webApiHost = "";
    var shareData = { title: '', desc: '', img: '', link: '' };


    function wxJSTools() {
    }


    /**
        配置酒名片微信分享接口(需要传入自定义标题等信息)
    */
    wxJSTools.prototype.configJMPShare = function (apiHost, title, desc, img, link) {
        var _this_ = this;


        webApiHost = apiHost;
        shareData.title = title;
        shareData.desc = desc;
        shareData.img = img;
        if (!link) {
            shareData.link = 'http://m.ganjiuhui.com';
        }
        else {
            shareData.link = link.indexOf("http:") >= 0 ? link : ('http://m.ganjiuhui.com' + link);
        }


        _this_.configWxJSSDK();
    }


    /**
        配置微信JSSDK
    */
    wxJSTools.prototype.configWxJSSDK = function () {
        if (!wx)
        { return; }


        $.get(webApiHost + "/api/weixin/jssignature", { url: w.location.href }, function (ret) {
            if (ret && ret.IsSucceed) {
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                    appId: ret.Data.AppId, // 必填,公众号的唯一标识
                    timestamp: ret.Data.Timestamp, // 必填,生成签名的时间戳
                    nonceStr: ret.Data.NonceStr, // 必填,生成签名的随机串
                    signature: ret.Data.Signature,// 必填,签名,见附录1
                    // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
                    jsApiList: [
                    "onMenuShareTimeline",          //朋友圈
                    "onMenuShareAppMessage",         //好友
                    "onMenuShareQQ",                //QQ                    
                    "onMenuShareQZone"                //QQ空间
                    ]
                });


                wx.ready(function () {
                    wx.onMenuShareTimeline({
                        title: shareData.title,
                        link: shareData.link,
                        imgUrl: shareData.img,
                        success: function (res) { },
                        cancel: function (res) { }
                    });
                    wx.onMenuShareAppMessage({
                        title: shareData.title,
                        desc: shareData.desc,
                        link: shareData.link,
                        imgUrl: shareData.img,
                        success: function (res) { },
                        cancel: function (res) { }
                    });
                    wx.onMenuShareQQ({
                        title: shareData.title,
                        desc: shareData.desc,
                        link: shareData.link,
                        imgUrl: shareData.img,
                        success: function (res) { },
                        cancel: function (res) { }
                    });
                    wx.onMenuShareQZone({
                        title: shareData.title,
                        desc: shareData.desc,
                        link: shareData.link,
                        imgUrl: shareData.img,
                        success: function (res) { },
                        cancel: function (res) { }
                    });
                });
            }
        });
    }


    return new wxJSTools();
})(window);

3.直接调用方法,传入参数即可;

wxShare.configJMPShare(APIHost, 标题,文案描素,img,分享地址);


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值