PHP 微信分享(及二次分享)

js部分:

<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
var appid = appid;
var timestamp = timestamp;
var nonceStr = nonceStr;
var signature = signature;
wx.config({
    debug: false,
    appId: appid,
    timestamp: timestamp,
    nonceStr: nonceStr,
    signature: signature,
    jsApiList: [
        "onMenuShareAppMessage",
        "onMenuShareTimeline",
        "chooseImage",
        "uploadImage",
        "downloadImage"
    ]
});
wx.ready(function(){
	  wx.onMenuShareTimeline({
		    title: title,
		    desc: desc,
		    link: link, // 分享链接
		    imgUrl: imgUrl,// 分享图标
		    
		});
	  
	  wx.onMenuShareAppMessage({
	      title: title,
	      desc:  desc,
	      link: link,
	      imgUrl: imgUrl,
	    });
});
</script>

 php部分:就是微信demo 里面的代码

开发的时候 把  debug:true 开启调试

问题一:输出的调试信息 config:invalid signature

解决方案:所有代码都对的情况,发现access_token获取不到,可以确定下访问IP是否添加到白名单

问题二:二次分享无法正确配置错误信息

原因:二次分享后的--->url:xxxxxxxxx&from=singlemessage&isappinstalled=0

   朋友圈   from=timeline&isappinstalled=0
   微信群   from=groupmessage&isappinstalled=0
   好友分享 from=singlemessage&isappinstalled=0

 

   在连接后加上&再进行分享,分享成功中红色链接内容,是微信自动为分享链接添加的内容,目的是为了记录分享来源

解决方案:a.获取二次分享的URL先去掉微信加的参数

        b.服务端做 redirect::to(url);

问题三:前面两步都确定没有问题后,发现分享时好时坏

解决方案:可以检测下分享 的 title或desc 是否有特殊字符(换行等)

posted @ 2017-08-17 11:02  桔子木木  阅读(426)  评论(0编辑  收藏  举报