老鬼的博客 来都来啦,那就随便看看吧~
Hexo+Next配置微信签名分享
发布于: 2019-11-27 更新于: 2019-11-27 分类于: Hexo 阅读次数: 

一:介绍

1
增加微信的自定义签名分享,因为本身的分享不怎么好看,分享图也找不到

二:准备工作

1
2
3
4
5
1.熟悉微信的签名分享流程(自己去看微信官网的api)
2.公众号配置js安全域名
3.准备一个签名的接口
4.修改相关的配置文件
5.备注:我这里是next主题,修改的配置文件是:\themes\next\_layout.swing

三:修改文件

  • _layout.swing
1
2
3
4
在文件底部加入如下代码:
<!-- 微信分享 -->
<script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="/js/src/share.js"></script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>

{% set html_class = 'theme-next ' + theme.scheme %}
{% if theme.motion.enable %}
{% set html_class = html_class + ' use-motion' %}
{% endif %}

<html class="{{ html_class | lower }}" lang="{{ config.language }}">
<head>
{% include '_partials/head.swig' %}
<title>{% block title %}{% endblock %}</title>
{% include '_third-party/analytics/index.swig' %}
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="{{ page.lang || page.language || config.language }}">

{% set container_class = "container " %}
{% if theme.sidebar.position %}
{% set container_class = container_class + 'sidebar-position-' + theme.sidebar.position %}
{% endif %}

<div class="{{ container_class }} {% block page_class %}{% endblock %}">
<div class="headband"></div>

<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"> {%- include '_partials/header.swig' %} </div>
</header>

<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
{% block content %}{% endblock %}
</div>
{% include '_third-party/duoshuo-hot-articles.swig' %}
{% include '_partials/comments.swig' %}
</div>
{% if theme.sidebar.display !== 'remove' %}
{% block sidebar %}{% endblock %}
{% endif %}
</div>
</main>

<footer id="footer" class="footer">
<div class="footer-inner">
{% include '_partials/footer.swig' %}
{% include '_third-party/analytics/analytics-with-widget.swig' %}
{% block footer %}{% endblock %}
</div>
</footer>

{% if not theme.sidebar.b2t %}
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
{% if theme.sidebar.scrollpercent %}
<span id="scrollpercent"><span>0</span>%</span>
{% endif %}
</div>
{% endif %}

{% if theme.needmoreshare2.enable and theme.needmoreshare2.float.enable %}
<div id="needsharebutton-float">
<span class="btn">
<i class="fa fa-share-alt" aria-hidden="true"></i>
</span>
</div>
{% endif %}

</div>

{% include '_scripts/vendors.swig' %}
{% include '_scripts/commons.swig' %}

{% set scheme_script = '_scripts/schemes/' + theme.scheme | lower + '.swig' %}
{% include scheme_script %}

{% block script_extra %}{% endblock %}

{% include '_scripts/boostrap.swig' %}

{% include '_third-party/comments/index.swig' %}
{% include '_third-party/search/index.swig' %}
{% include '_third-party/analytics/lean-analytics.swig' %}
{% include '_third-party/analytics/firestore.swig' %}
{% include '_third-party/seo/baidu-push.swig' %}
{% include '_third-party/needsharebutton.swig' %}
{% include '_third-party/rating.swig' %}
{% include '_third-party/mathjax.swig' %}
{% include '_third-party/scroll-cookie.swig' %}
{% include '_third-party/exturl.swig' %}

<!-- canvos -->
{% if theme.canvas_nest %}
<script type="text/javascript" src="//static.tohours.com/jren/2018/0928/canvas-nest.min.js"></script>
{% endif %}

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>

<!-- 微信分享 -->
<script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="/js/src/share.js"></script>


</body>
</html>
  • 编写share.js
1
share.js的路径是:\themes\next\source\js\src\share.js,完整实例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$(function(){
// 定义分享的方案


var shareobj = {
title:document.title.substring(0,document.title.length-5),
desc:'知识分享,日常记录',
link:location.href,
imgUrl:location.origin + '/images/photo.jpg'
};

var timeObj = {
title:document.title.substring(0,document.title.length-5),
link:location.href,
imgUrl:location.origin + '/images/photo.jpg' // 此路径是在\themes\next\source\images\xx.jpg
}

//获取微信接口相关信息
var url = "https://xxx.com/xxx.action?callback=?&url=" + encodeURIComponent(location.href); // 分享的地址,我这里是java的代码, 手动修改成自己的地址
console.log(url);
$.getJSON(url, function(json) {
if (json.success) {
var cg = json.msg;
cg.debug = false;
wx.config(cg);
wx.ready(function() {
wx.showOptionMenu();
wx.hideMenuItems({
menuList: ['menuItem:share:qq','menuItem:share:weiboApp','menuItem:share:facebook','menuItem:share:QZone']
});
wx.onMenuShareTimeline(timeObj);
wx.onMenuShareAppMessage(shareobj);
});
} else {
alert(json.msg);
}
});
});

四:相关参考文档

*************感谢您的阅读*************