-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathindex.html
123 lines (104 loc) · 3.9 KB
/
index.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Wechat.js</title>
<link rel="stylesheet" href="http://typo.sofi.sh/typo.css"/>
<style>
body{padding:20px;}
pre{margin:0 -20px;padding:30px 20px;font-size:14px;border:none;line-height:1;}
code{color:#1a3;border:1px dashed #1a3;padding:1px 3px;}
.reval{float:right;}
</style>
</head>
<body class="typo">
<h1>Wechat.js</h1>
<p>
当前使用的网络是:<code id="network">...</code>。
用微信扫一扫下面的 url,然后分享到朋友圈:
</p>
<p><button onclick="toggle()">隐藏/显示分享按钮</button></p>
<p><button onclick="closeWebView()">关闭webview</button></p>
<p><button onclick="scanQRCode()">跳转到扫描二维码界面</button></p>
<p><button onclick="imagePreview()">图片预览/查看大图</button></p>
<p><button onclick="sendEmail()">分享到邮件</button></p>
<p><img src="http://ww4.sinaimg.cn/large/61b90cbegw1eknqctwzbhj2097097jrx.jpg" alt="sofish/wechat.js"/></p>
<p>详细使用指南请看:<a href="http://github.com/sofish/wechat.js/#readme">说明文档</a>。</p>
<script src="wechat.js"></script>
<script>
// 导入的数据
var data = {
app: '',
img: function() {
return 'http://appled.cc/candy-theme-flat/images/share.jpg'
},
link: 'http://sofish.github.io/wechat.js/',
desc: '用于处理微信分享的等小功能的 js 库。',
title: 'Wechat.js'
};
var callback = function(res) {
alert(JSON.stringify(res));
};
// TODO: 微信 api 2014 年最后一台调整 api 让原来的 api 不能用
// 当只有一个参数,并且是 `data` 的话,执行这个 hack
wechat(data);
// 查看用户当前网络
// TODO: 这返回的数据好恶心
wechat('network', function(res) {
document.getElementById('network').innerHTML = (res.err_msg.split(':')[1]);
});
// 分享
wechat('friend', data, callback); // 朋友
wechat('timeline', data, callback); // 朋友圈
wechat('weibo', data, callback); // 微博
//控制右上角菜单是否显示,防止敏感信息泄露
var show = true;
function toggle(){
var action = show ? 'hideOptionMenu' : 'showOptionMenu';
wechat(action);
show = !show;
}
// 关闭webview
function closeWebView() {
wechat('closeWebView');
}
// 跳转到扫描二维码页面
function scanQRCode() {
wechat('scanQRCode');
}
// 图片预览/查看大图
function imagePreview() {
// 图片地址,恩,这部分漫画还有点意思
var imageUrls = [
"http://pic003.cnblogs.com/2010/66372/201010/2010100914201786.jpg",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914202624.jpg",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914203364.jpg",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914204097.jpg",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914204740.gif",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914205649.jpg",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914211050.gif",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914211871.jpg",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914212444.gif",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914213091.jpg",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914213952.gif",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914214777.gif",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914215454.gif",
"http://pic003.cnblogs.com/2010/66372/201010/2010100914220482.gif",
"http://pic003.cnblogs.com/2012/66372/201208/2012082923435810.gif",
"http://pic003.cnblogs.com/2012/66372/201208/2012082923440536.gif",
"http://pic003.cnblogs.com/2012/66372/201208/2012082923441776.gif"
];
var imgData = {
current: imageUrls[0],
urls: imageUrls
};
wechat('imagePreview', imgData, callback);
}
// 发送邮件
function sendEmail() {
wechat('email', data, callback);
}
</script>
</body>
</html>