微信分享请引用 PHP 文件!
<!-- include file=wxconfig -->
然后打开 inc/wxconfig.php 文件,将
$app->lib('weixin')->app_id('wxf84d920dc558bd08');
里面的 wxf84d920dc558bd08 换成您的!
如果没有找到这个文件,请自行创建,文件内容如下:
<?php /** * 微信分享专用 * @作者 qinggan <admin@phpok.com> * @版权 深圳市锟铻科技有限公司 * @主页 http://www.phpok.com * @版本 5.x * @授权 http://www.phpok.com/lgpl.html 开源授权协议:GNU Lesser General Public License * @时间 2019年9月24日 **/ /** * 安全限制,防止直接访问 **/ if(!defined("PHPOK_SET")){ exit("<h1>Access Denied</h1>"); } $app->lib('weixin')->app_id('wxf84d920dc558bd08'); $wxurl = $rs ? $rs['url'] : ($cate_rs ? $cate_rs['url'] : ($page_rs ? $page_rs['url'] : $app->url)); $wxconfig = $app->lib('weixin')->jsapi_config($wxurl);
接下来在模板里写上以下代码
<script type="text/javascript"> $(document).ready(function(){ wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: '{$wxconfig.appid}', // 必填,公众号的唯一标识 timestamp: {$wxconfig.timestamp}, // 必填,生成签名的时间戳 nonceStr: '{$wxconfig.noncestr}', // 必填,生成签名的随机串 signature: '{$wxconfig.sign}', // 必填,签名 jsApiList: ['updateAppMessageShareData','updateTimelineShareData'] // 必填,需要使用的JS接口列表 }); wx.ready(function() { //需在用户可能点击分享按钮前就先调用 wx.updateAppMessageShareData({ title: '{$rs.title}', // 分享标题 desc: '{$rs.note}', // 分享描述 link: '{$rs.url}', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: '{$sys.url}{$rs.thumb.filename}', // 分享图标 success: function() { // 设置成功 } }); wx.updateTimelineShareData({ title: '{$rs.title}', // 分享标题 desc: '{$rs.note}', // 分享描述 link: '{$rs.url}', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: '{$sys.url}{$rs.thumb.filename}', // 分享图标 success: function() { // 设置成功 } }); }); }); </script>
这样就可以实现公众号分享带有标题+图片+描述