Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wxapp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
亲子游项目
wxapp
Commits
42e9e73e
Commit
42e9e73e
authored
Jan 03, 2019
by
汪睦雄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'修复了授权手机号的问题'
parent
8e1653f6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
267 additions
and
109 deletions
+267
-109
pages/detail/appoint/index.js
+110
-2
pages/detail/appoint/index.wxml
+3
-3
pages/detail/enroll/index.js
+66
-85
pages/detail/enroll/index.wxml
+6
-4
pages/me/vip/index.js
+80
-13
project.config.json
+2
-2
No files found.
pages/detail/appoint/index.js
View file @
42e9e73e
...
...
@@ -20,6 +20,7 @@ Page({
date
:
''
,
remark
:
''
,
loading
:
false
,
sessionId
:
''
},
/**
...
...
@@ -31,6 +32,14 @@ Page({
id
:
options
.
id
})
}
// 获取session id
let
that
=
this
this
.
getSessionKey
(
function
(
sid
)
{
that
.
setData
({
sessionId
:
sid
})
})
},
/**
...
...
@@ -82,10 +91,109 @@ Page({
})
},
handlePhoneAuth
:
function
(
event
)
{
Wx
.
login
().
then
(
res
=>
{
// 获取session key
let
encryptedData
=
event
.
detail
.
encryptedData
let
iv
=
event
.
detail
.
iv
this
.
decodePhoneData
(
res
.
code
,
encryptedData
,
iv
)
let
that
=
this
// 检查session key是否过期,如果过期的话,那么就获取新的再请求,否则直接请求
wx
.
checkSession
({
success
:
function
(
res
)
{
//session_key未过期,直接操作
let
sessionId
=
that
.
data
.
sessionId
api
.
getPhoneNumber
({
sessionId
:
sessionId
,
encryptedData
:
encryptedData
,
iv
:
encodeURIComponent
(
iv
)
}).
then
(
res
=>
{
if
(
!
res
.
code
)
{
$Toast
({
content
:
'手机号授权成功'
,
type
:
'success'
});
that
.
setData
({
phone
:
res
.
data
.
phone
})
// 将刚拿到的手机号码放到全局数据中,否则phone数据只会是当前页面数据
if
(
app
.
globalData
.
userInfo
)
{
app
.
globalData
.
userInfo
.
phone
=
res
.
data
.
phone
}
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
},
fail
:
function
()
{
console
.
log
(
'checkSession fail!'
)
// session_key 已过期,进行登录操作,提示错误
// 获取session id
let
that
=
this
this
.
getSessionKey
(
function
(
sid
)
{
that
.
setData
({
sessionId
:
sid
})
// 授权手机号
api
.
getPhoneNumber
({
sessionId
:
sid
,
encryptedData
:
encryptedData
,
iv
:
encodeURIComponent
(
iv
)
}).
then
(
res
=>
{
if
(
!
res
.
code
)
{
$Toast
({
content
:
'手机号授权成功'
,
type
:
'success'
});
that
.
setData
({
phone
:
res
.
data
.
phone
})
// 将刚拿到的手机号码放到全局数据中,否则phone数据只会是当前页面数据
if
(
app
.
globalData
.
userInfo
)
{
app
.
globalData
.
userInfo
.
phone
=
res
.
data
.
phone
}
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
})
}
})
// Wx.login().then(res => {
// let encryptedData = event.detail.encryptedData
// let iv = event.detail.iv
// this.decodePhoneData(res.code, encryptedData, iv)
// })
},
/**
* 获取服务器端 session key
*/
getSessionKey
(
callback
)
{
Wx
.
login
().
then
(
res
=>
{
if
(
res
.
errMsg
==
'login:ok'
)
{
api
.
getSessionKey
({
code
:
res
.
code
}).
then
(
res
=>
{
if
(
res
.
code
==
0
)
{
typeof
callback
==
"function"
&&
callback
(
res
.
data
)
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
}
else
{
$Toast
({
content
:
'wx.login失败'
,
type
:
'error'
});
}
})
},
...
...
pages/detail/appoint/index.wxml
View file @
42e9e73e
...
...
@@ -31,12 +31,12 @@
<input slot="footer" class='input' type='text' placeholder='请输入您的姓名' bindinput='handleNickname' value='{{nickname}}'></input>
</i-cell>
<i-cell title="手机号" i-class="cell-class">
<
block wx:if="{{phone.length == 0}}"
>
<
!-- <block wx:if="{{phone.length == 0}}"> --
>
<button slot="footer" bindgetphonenumber="handlePhoneAuth" type="info" open-type="getPhoneNumber" class="btn-auth-phone">授权手机号</button>
</block>
<
!-- <
/block>
<block wx:else>
<text slot="footer">{{phone}}</text>
</block>
</block>
-->
</i-cell>
<i-cell title="期望时间" is-link i-class="cell-class">
<picker slot="footer" class='input' mode="date" value="{{date}}" bindchange="handleDateChange" class="picker">
...
...
pages/detail/enroll/index.js
View file @
42e9e73e
...
...
@@ -41,28 +41,11 @@ Page({
}
// 获取session id
Wx
.
login
().
then
(
res
=>
{
if
(
res
.
errMsg
==
'login:ok'
)
{
api
.
getSessionKey
({
code
:
res
.
code
}).
then
(
res
=>
{
if
(
res
.
code
==
0
)
{
this
.
setData
({
sessionid
:
res
.
data
let
that
=
this
this
.
getSessionKey
(
function
(
sid
)
{
that
.
setData
({
sessionId
:
sid
})
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
}
else
{
$Toast
({
content
:
'wx.login失败'
,
type
:
'error'
});
}
})
},
...
...
@@ -110,23 +93,22 @@ Page({
})
},
// 获取手机号
handlePhoneAuth
:
function
(
event
)
{
// 获取session key
let
encryptedData
=
event
.
detail
.
encryptedData
let
iv
=
event
.
detail
.
iv
let
that
=
this
// 检查session key是否过期,如果过期的话,那么就获取新的再请求,否则直接请求
wx
.
checkSession
({
success
:
function
(
res
)
{
if
(
res
.
errMsg
==
'checkSession:ok'
){
let
sessionId
=
that
.
data
.
sessionid
console
.
log
(
'sessionId'
,
sessionId
)
//session_key未过期,直接操作
let
sessionId
=
that
.
data
.
sessionId
api
.
getPhoneNumber
({
sessionId
:
sessionId
,
encryptedData
:
encryptedData
,
iv
:
encodeURIComponent
(
iv
)
}).
then
(
res
=>
{
console
.
log
(
'iv: '
,
iv
,
' res.code: '
,
res
.
code
)
if
(
!
res
.
code
)
{
$Toast
({
content
:
'手机号授权成功'
,
...
...
@@ -146,72 +128,71 @@ Page({
});
}
})
}
else
{
},
fail
:
function
()
{
console
.
log
(
'checkSession fail!'
)
// session_key 已过期,进行登录操作,提示错误
// 获取session id
let
that
=
this
this
.
getSessionKey
(
function
(
sid
)
{
that
.
setData
({
sessionId
:
sid
})
// 授权手机号
api
.
getPhoneNumber
({
sessionId
:
sid
,
encryptedData
:
encryptedData
,
iv
:
encodeURIComponent
(
iv
)
}).
then
(
res
=>
{
if
(
!
res
.
code
)
{
$Toast
({
content
:
res
.
errMsg
,
content
:
'手机号授权成功'
,
type
:
'success'
});
console
.
log
(
'checkSession'
,
res
.
errMsg
)
that
.
setData
({
phone
:
res
.
data
.
phone
})
// 将刚拿到的手机号码放到全局数据中,否则phone数据只会是当前页面数据
if
(
app
.
globalData
.
userInfo
)
{
app
.
globalData
.
userInfo
.
phone
=
res
.
data
.
phone
}
},
fail
:
function
()
{
console
.
log
(
'checkSession'
,
'fail'
)
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
})
}
})
},
// Wx.login().then(res => {
// console.log('wx.login', res, ' event:', event)
// if (res.errMsg == 'login:ok') {
// api.getSessionKey({
// code: res.code
// }).then(res => {
// if (!res.code) {
// let sessionId = res.data
// let that = this
// api.getPhoneNumber({
// sessionId: sessionId,
// encryptedData: encryptedData,
// iv: encodeURIComponent(iv)
// }).then(res => {
// console.log('iv: ', iv, ' res.code: ', res.code)
// if (!res.code) {
// $Toast({
// content: '手机号授权成功',
// type: 'success'
// });
// this.setData({
// phone: res.data.phone
// })
// // 将刚拿到的手机号码放到全局数据中,否则phone数据只会是当前页面数据
// if (app.globalData.userInfo) {
// app.globalData.userInfo.phone = res.data.phone
// }
// } else {
// $Toast({
// content: res.msg,
// type: 'error'
// });
// }
// })
// } else {
// $Toast({
// content: res.msg,
// type: 'error'
// });
// }
// })
// } else {
// $Toast({
// content: 'wx.login失败',
// type: 'error'
// });
// }
// // let encryptedData = event.detail.encryptedData
// // let iv = event.detail.iv
// // this.decodePhoneData(res.code, encryptedData, iv)
// })
/**
* 获取服务器端 session key
*/
getSessionKey
(
callback
)
{
Wx
.
login
().
then
(
res
=>
{
if
(
res
.
errMsg
==
'login:ok'
)
{
api
.
getSessionKey
({
code
:
res
.
code
}).
then
(
res
=>
{
if
(
res
.
code
==
0
)
{
typeof
callback
==
"function"
&&
callback
(
res
.
data
)
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
}
else
{
$Toast
({
content
:
'wx.login失败'
,
type
:
'error'
});
}
})
},
/**
...
...
pages/detail/enroll/index.wxml
View file @
42e9e73e
<!--pages/detail/enroll/index.wxml-->
<wxs src="../../common.wxs" module="common"></wxs>
<view class='page-wrapper'>
<view class='project-title'>
...
...
@@ -41,12 +43,12 @@
<input slot="footer" class='input' type='text' placeholder='请输入您的姓名' bindinput='handleNickname' value='{{nickname}}'></input>
</i-cell>
<i-cell title="手机号" i-class="cell-class">
<
!-- <block wx:if="{{phone.length == 0}}"> --
>
<
block wx:if="{{phone.length == 0}}"
>
<button slot="footer" bindgetphonenumber="handlePhoneAuth" type="info" open-type="getPhoneNumber" class="btn-auth-phone">授权手机号</button>
<
!-- <
/block>
</block>
<block wx:else>
<text slot="footer">{{phone}}</text>
</block>
-->
</block>
</i-cell>
<i-cell title="成人人数" is-link i-class="cell-class">
<picker slot="footer" class="num-picker" bindchange="handleAdultNum" range="{{nums}}" value="{{adultNum}}">
...
...
@@ -74,7 +76,7 @@
<i-col span="20" offset='2' i-class="col-class">
<i-button bind:click="handleSubmit" type="info" shape="circle" loading="{{loading}}">
立即支付
<text class='margin-left-10'>¥ {{user.is_vip != 0 ?
detail.vip_price*(familyNum+1) : detail.price*(familyNum+1
)}}</text>
<text class='margin-left-10'>¥ {{user.is_vip != 0 ?
common.numFixed(detail.vip_price*(familyNum+1), 2) : common.numFixed(detail.price*(familyNum+1), 2
)}}</text>
</i-button>
</i-col>
</i-row>
...
...
pages/me/vip/index.js
View file @
42e9e73e
...
...
@@ -20,7 +20,7 @@ Page({
name
:
''
,
address
:
''
,
wx_number
:
''
,
sessionId
:
''
},
handleChange1
({
...
...
@@ -71,6 +71,14 @@ Page({
onLoad
:
function
(
options
)
{
this
.
getUserInfo
()
this
.
getVipPrice
()
// 获取session id
let
that
=
this
this
.
getSessionKey
(
function
(
sid
)
{
that
.
setData
({
sessionId
:
sid
})
})
},
// 获取个人资料
...
...
@@ -91,28 +99,59 @@ Page({
},
handlePhoneAuth
:
function
(
event
)
{
Wx
.
login
().
then
(
res
=>
{
// 获取session key
let
encryptedData
=
event
.
detail
.
encryptedData
let
iv
=
event
.
detail
.
iv
this
.
decodePhoneData
(
res
.
code
,
encryptedData
,
iv
)
let
that
=
this
// 检查session key是否过期,如果过期的话,那么就获取新的再请求,否则直接请求
wx
.
checkSession
({
success
:
function
(
res
)
{
//session_key未过期,直接操作
let
sessionId
=
that
.
data
.
sessionId
api
.
getPhoneNumber
({
sessionId
:
sessionId
,
encryptedData
:
encryptedData
,
iv
:
encodeURIComponent
(
iv
)
}).
then
(
res
=>
{
if
(
!
res
.
code
)
{
that
.
setData
({
visible1
:
false
})
if
(
res
.
is_relation
)
{
that
.
setData
({
visible2
:
true
})
}
//更新下用户数据
that
.
getUserInfo
()
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
},
/**
* 解密手机号数据
*/
decodePhoneData
:
function
(
code
,
encryptedData
,
iv
)
{
fail
:
function
()
{
// session_key 已过期,进行登录操作,提示错误
// 获取session id
console
.
log
(
'checkSession fail!'
)
let
that
=
this
this
.
getSessionKey
(
function
(
sid
)
{
that
.
setData
({
sessionId
:
sid
})
// 授权手机号
api
.
getPhoneNumber
({
code
:
code
,
sessionId
:
sid
,
encryptedData
:
encryptedData
,
iv
:
iv
iv
:
encodeURIComponent
(
iv
)
}).
then
(
res
=>
{
if
(
!
res
.
code
)
{
that
.
setData
({
visible1
:
false
})
if
(
res
.
is_relation
)
{
if
(
res
.
is_relation
)
{
that
.
setData
({
visible2
:
true
})
...
...
@@ -121,14 +160,42 @@ Page({
that
.
getUserInfo
()
}
else
{
$Toast
({
content
:
'手机号授权失败'
,
content
:
res
.
msg
,
type
:
'error'
});
}
})
})
}
})
},
/**
* 获取服务器端 session key
*/
getSessionKey
(
callback
)
{
Wx
.
login
().
then
(
res
=>
{
if
(
res
.
errMsg
==
'login:ok'
)
{
api
.
getSessionKey
({
code
:
res
.
code
}).
then
(
res
=>
{
if
(
res
.
code
==
0
)
{
typeof
callback
==
"function"
&&
callback
(
res
.
data
)
}
else
{
$Toast
({
content
:
res
.
msg
,
type
:
'error'
});
}
})
}
else
{
$Toast
({
content
:
'wx.login失败'
,
type
:
'error'
});
}
})
},
// 获取VIP单价
getVipPrice
:
function
()
{
...
...
project.config.json
View file @
42e9e73e
...
...
@@ -37,7 +37,7 @@
"list"
:
[]
},
"miniprogram"
:
{
"current"
:
1
0
,
"current"
:
1
1
,
"list"
:
[
{
"id"
:
0
,
...
...
@@ -109,7 +109,7 @@
"id"
:
11
,
"name"
:
"预约下次"
,
"pathName"
:
"pages/detail/appoint/index"
,
"query"
:
"id=
173
"
"query"
:
"id=
298
"
},
{
"id"
:
-1
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment