织梦程序的内容文章页,分享到微信好友、朋友圈时需默认只显示链接图标,使用此插件,可以实现分享到朋友圈、好友时显示文章页缩略图片,也可以通过修改代码来显示固定的品牌图标。
织梦的微信分享显示缩略图的插件,可以实现自定义微信分享的效果(自定义缩略图,标题,摘要)样式良好,给用户的体验很好,对品牌展示也起到一定的效果。
没使用之前,如下图:
使用插件之后,如下图:
一、在使用此插件之前,需要准备如下工作:
1、PHP 5.3+ 并且 curl扩展已经开启
2、微信服务号一个,并且已经通过了实名认证;
3、一个ICP备案的域名。
二、操作步骤:
1、微信公众号有分享接口权限,如下图:
2、查看AppId,AppSecret、IP白名单(填你服务器外网IP)、绑定你的域名。
3、文章内容页模板微信分享代码,以下代码添加到你的织梦内容文章页模板里面即可。
- <!--如果你的页面上已经有jquery库,请删除下面那一行代码-->
- <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
- <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
- <script type="text/javascript">
- var url = encodeURIComponent(location.href.split("#")[0]);
- $.ajax({
- type: "get",
- url: "{dede:global.cfg_basehost/}/wechat.php?link=" + url,
- dataType: "json",
- contentType: "application/json; charset=utf-8",
- success: function(e) {
- var d = e.appid,
- i = e.timestamp,
- t = e.noncestr,
- n = e.signature;
- wx.config({
- debug: 0,//如果分享失败,把0改成1开启错误提示看看
- appId: d,
- timestamp: i,
- nonceStr: t,
- signature: n,
- jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage"]
- }),
- wx.ready(function() {
- wx.onMenuShareTimeline({
- title: "{dede:field.title function=html2text(@me)/}",
- desc: "{dede:field.description function=html2text(@me)/}",
- link: "{dede:global.cfg_basehost/}{dede:field.id runphp='yes'}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}",
- imgUrl: "{dede:global.cfg_basehost/}{dede:field.litpic/}"
- }),
- wx.onMenuShareAppMessage({
- title: "{dede:field.title function=html2text(@me)/}",
- desc: "{dede:field.description function=html2text(@me)/}",
- link: "{dede:global.cfg_basehost/}{dede:field.id runphp='yes'}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}",
- imgUrl: "{dede:global.cfg_basehost/}{dede:field.litpic/}"
- })
- })
- }
- });
- </script>
4、织梦的分享文件下载,放在网站根目录,即可完成操作。
三、重要提醒与注意点:
1、文章页的js代码里,有几处的代码,其中 {dede:global.cfg_basehost/},是调用后台-系统-基本参数-站点根网址,在后台请填写正确的域名。
2、如果你是手机站内容页,这样的 https://www.uu2018.com/m/view.php?aid=123
那你应该改成
link: "{dede:global.cfg_basehost/}/m/view.php?aid={dede:field.id/}",
3、如果你是手机站内容页,这样的 http://m.uu2018.com/view.php?aid=123
那你应该改成
link: "http://m.uu2018.com/view.php?aid={dede:field.id/}",
4、如果你是手机站内容页,这样的 https://www.uu2018.com/m/news/123.html
那你应该改成
link: "{dede:global.cfg_basehost/}/m/{dede:field.id runphp='yes'}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}",
4、如果你是手机站内容页,这样的 http://m.uu2018.com/news/123.html
那你应该改成
link: "http://m.uu2018.com{dede:field.id runphp='yes'}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}",