首先在页面引用jssdk.php文件
我将文件是vendor/share/jssdk.php
use share\jssdk;
//引入文件
$jssdk = new JSSDK("","");
$signPackage = $jssdk->GetSignPackage();
$this->assign("signPackage",$signPackage);
同时将access_token.json 和jsapi_ticket.json放在根目录下 tp5.1的根目录是public
然后应用js和jq
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src='__PUBLIC__/Home/js/jquery-1.js'></script>
在js里面:
//微信分享
wx.config({
debug: false,
appId: '{$signPackage.appId}',
timestamp: '{$signPackage.timestamp}',
nonceStr: '{$signPackage.nonceStr}',
signature: '{$signPackage.signature}',
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage',
]
});
wx.ready(function () {
wx.checkJsApi({
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage'
],
});
//分享到微讯朋友圈
wx.onMenuShareTimeline({
title: '测试',
desc: '测试',
link: "", //当前目录的路径
imgUrl: '', //图片
success: function (res) {
alert("成功")
}else{
alert('用户取消分享');
}
}
});
//分享到微信朋友
wx.onMenuShareAppMessage({
title: '测试',
desc: '测试',
link: '',
imgUrl:"",
success: function (res) {
alert("成功")
}else{
alert('用户取消分享');
}
}
});
});