Commit a08bab95 by 肖康

获取用户信息JSapi鉴权

parent e41fa984
...@@ -3,11 +3,53 @@ App({ ...@@ -3,11 +3,53 @@ App({
// 第一次打开 // 第一次打开
// options.query == {number:1} // options.query == {number:1}
console.info('App onLaunch'); console.info('App onLaunch');
this.getUserInfos()
}, },
onShow(options) { onShow(options) {
// 从后台被 scheme 重新打开 // 从后台被 scheme 重新打开
// options.query == {number:1} // options.query == {number:1}
}, },
personName: "仓库管理员" personName: "",
getUserInfos() {
var self = this;
dd.getAuthCode({
success: (res) => {
var code = res.authCode;
dd.httpRequest({
url: "https://oapi.dingtalk.com/gettoken?appkey=dingmwxikbdltarcjlb8&appsecret=GUS0_HylYmPcoPYCshqUI3U2ik3r1eu7SyydOCWzUny7SZwDUQb1E1jnW7vpZCvM",
success: function (res) {
var access_token = res.data.access_token;
dd.httpRequest({
url: 'https://oapi.dingtalk.com/user/getuserinfo?access_token=' + access_token + '&code=' + code,
success: function (res) {
dd.httpRequest({
url: 'https://oapi.dingtalk.com/user/get?access_token=' + access_token + '&userid=' + res.data.userid,
success: function (res) {
self.personName = res.data.name
}
});
},
});
}
})
},
fail: (err) => {
dd.alert({ content: JSON.stringify(err) })
}
})
},
setName(self) {
// 页面加载完成
let name_ = setInterval(() => {
self.setData({
personName: getApp().personName
})
if (this.personName) {
clearInterval(name_)
}
}, 1000)
}
}); });
...@@ -18,9 +18,7 @@ Page({ ...@@ -18,9 +18,7 @@ Page({
}, },
onReady() { onReady() {
// 页面加载完成 // 页面加载完成
this.setData({ getApp().setName(this)
personName: getApp().personName
})
}, },
getDateList() { getDateList() {
axios({ axios({
...@@ -170,6 +168,8 @@ Page({ ...@@ -170,6 +168,8 @@ Page({
duration: 3000 duration: 3000
}); });
} }
}) })
}, },
onShareAppMessage() { onShareAppMessage() {
......
...@@ -9,9 +9,7 @@ Page({ ...@@ -9,9 +9,7 @@ Page({
}, },
onReady() { onReady() {
// 页面加载完成 // 页面加载完成
this.setData({ getApp().setName(this)
personName: getApp().personName
})
}, },
gotoList(){ gotoList(){
dd.navigateTo({ dd.navigateTo({
......
...@@ -11,9 +11,7 @@ Page({ ...@@ -11,9 +11,7 @@ Page({
onReady() { onReady() {
// 页面加载完成 // 页面加载完成
this.setData({ getApp().setName(this)
personName: getApp().personName
})
}, },
saoma() { saoma() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment