Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

JS-SDK config:invalid signature 一直报这个?代码有什么问题吗?

var current_url = location.href.split('#')[0];
var encodeUri = encodeURIComponent(current_url);
var ua=window.navigator.userAgent.toLowerCase();
getSign();
//分享
function getSign(){
    //分享获取签名时间戳appid
    $.ajax({
    type:'POST',
    url"http://xxxx",
    async:false,
    dataType:'json',
    contentType:'application/json',
    data:JSON.stringify({url:encodeUri}),
    success:function(res,textStatus){
    let data = res.dt;
    if (textStatus == "success"){
        wx.config({
           debug: true,
           appId: "xxxxx", 
           timestamp: data.timestamp, 
           nonceStr: data.noncestr, 
           signature: data.signature,
           jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData']
    }); 
  wx.ready(function(){
        share(); 
    });
    wx.error(function(res) {
         console.log('error')
         alert(res.errMsg);
    });
}
 }
})
}
    function share(){
            var title = "官方下载";
            var content = "xxxxx";
            var shareImage = '//xxx.png';
            wx.updateAppMessageShareData({
                title: title , 
                desc: content , 
                link: current_url, 
                imgUrl: shareImage, 
                success: function () {
                    // 用户确认分享后执行的回调函数
                    console.log("分享成功========>>");
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                    console.log("取消分享========>>");
                }
            });
            //自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容
            wx.updateTimelineShareData({
                title: title , // 分享标题
                desc:content, // 分享描述
                link: current_url, // 分享链接
                imgUrl: shareImage, // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                    console.log("分享成功========>>");
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                    console.log("取消分享========>>");

                }
            });
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

如果确认你的参数都是正确的没有问题的话可以看看张老师的这篇文章可能会帮到你


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...