kd.js
2.34 KB
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
let appId = 'e13baf8d4a0d468eae005935332c5429';
let appKey = '1c60d1543db640e5970ffa4a794eb5c6';
KD.init(appId, appKey);
let weixin = new KD.weixin();
weixin.initConfig();
// window.weixin = weixin;
let openId = weixin.getOpenId();
window.openId = openId;
window.openid = openId;
window.wxUserInfo = null;
let urlShortCode = 's2n7/';
let href = location.href;
if (href.indexOf("192.168.") != -1 || href.indexOf("172.20.") != -1) {
urlShortCode = "";
}
let domain = `${location.protocol}//${document.domain}/${urlShortCode}`;
let shareTitle = "";
let shareDesc = "";
let shareLink = `${domain}index.html`;
let shareImgUrl = `${domain}share.png`;
window.shareCodeLink = shareLink;
var KdIns = window.KdIns || ({});
// 设置分享
KdIns.setShare = function (title, desc, link, imgUrl) {
if (!title) title = shareTitle;
if (!desc) desc = shareDesc;
if (!link) link = shareLink;
if (!imgUrl) imgUrl = shareImgUrl;
weixin.setShare(title, desc, link, imgUrl, (pos) => {})
}
console.log("domain:", domain);
KdIns.setShare(``, ``, ``, ``);
// KdIns.setShareShareCode = function (shareCode) {
// let shareCodeLink = `${shareLink}#/coop?shareCode=${shareCode}`;
// window.shareCodeLink = shareCodeLink;
// KdIns.setShare(``, ``, shareCodeLink, ``);
// }
// KdIns.getShareLink = function (shareCode) {
// let shareCodeLink = `${shareLink}#/coop?shareCode=${shareCode}`;
// return shareCodeLink;
// }
//
KdIns.setShareShareCode = function (shareCode) {
let shareCodeLink = `${shareLink}?f=coop&shareCode=${shareCode}`;
window.shareCodeLink = shareCodeLink;
KdIns.setShare(``, ``, shareCodeLink, ``);
}
KdIns.getShareLink = function (shareCode) {
let shareCodeLink = `${shareLink}?f=coop&shareCode=${shareCode}`;
return shareCodeLink;
}
// 读取微信身份
KdIns.getUserInfo = function () {
return new Promise((resolve, reject) => {
weixin.getUserInfo((res) => {
window.wxUserInfo = res;
window.wxUserInfo.avatar = window.wxUserInfo.headimgurl;
resolve(res);
});
});
}
// 读取微信身份CGI模式,需要用户显示授权后才能获得数据。获取信息中包含了用户的关注信息与unionid
KdIns.getCgiUserInfo = function () {
return new Promise((resolve, reject) => {
weixin.getCgiUserInfo((res) => {
resolve(res);
});
});
}