index.js
2.4 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
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
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
url: '',
thumb: '',
title: '',
type:0,
openid:'',
session_key:''
},
onLoad: function (options) {
console.log('99999',options)
if(options.title!=undefined){
this.setData({
url:options.url,
thumb:options.thumb,
title:options.title
})
}
this.getsessionkey()
},
onShow(){
},
// 获取openid和sessionkey
getsessionkey(){
let that=this;
wx.login({
provider: "weixin",
success(r) {
console.log(r)
let url = "user/getSessionKey";
app.post(url, {
code: r.code
},"post").then(r => {
console.log(r)
that.session_key=r.session_key;
that.openid=r.openid
}).catch(err => {})
}
})
},
// 登录
start(e) {
console.log(e)
let that = this;
wx.getSetting({
success(res) {
// console.log("res", res)
if (res.authSetting['scope.userInfo']) {
console.log("已授权=====")
wx.login({
success: (res) => {
console.log(res)
// wx.setStorageSync("code", res.code)
let url = 'user/login';
let params = {
openid:that.openid,
session_key:that.session_key,
encrypted_data:e.detail.encryptedData,
iv:e.detail.iv
}
app.post(url, params, 'post').then((res) => {
console.log(res)
wx.setStorageSync('token', res.token);
if(that.data.title==''){
wx.navigateTo({
url: '/pages/getphone/getphone',
})
}else{
wx.navigateTo({
url: '/pages/videoplay/videoplay?url=' + that.data.url + '&thumb=' + that.data.thumb + '&title=' + that.data.title,
})
}
}).catch((errMsg) => {
console.log(errMsg)
wx.navigateTo({
url: '/pages/homepage/homepage',
})
})
}
});
} else {
console.log("未授权=====")
wx.navigateTo({
url: '/pages/homepage/homepage',
})
}
}
})
},
})