forked from ss1121/FKP-REST
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserinfo.js
More file actions
57 lines (48 loc) · 1.59 KB
/
userinfo.js
File metadata and controls
57 lines (48 loc) · 1.59 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
//微信 web端根据web-access-token 获取用户信息
// oauth2 原理实现
var path = require('path')
var libs = require('../../libs/libs')
var api = require('../../apis/javaapi');
var config = require('../../config')
// var rct = require('../../modules/parseReact');
function *demoIndexData(oridata){
libs.wlog('pages/weixin/userinfo')
var mtd = this.method;
var _this_sess = this.sess;
var postdata = {}
var _this = this;
function *dealWith(){
if(_this_sess.wwx){
postdata={
access_token: _this_sess.wwx.token,
openid: _this_sess.wwx.openid,
lang: 'zh_CN'
}
// console.log(postdata);
var web_userinfo = yield api.pullWxData.call(_this, 'userinfo_web', postdata)
web_userinfo = web_userinfo[0].body
libs.clog('============ 从微信拉取用户信息')
console.log(web_userinfo);
return web_userinfo;
}
else{
return {error: 1, message: '从微信号拿去数据出错'}
}
}
//
var body = yield libs.$parse(this);
if( body && body.code ){
postdata = body;
var web_token = yield api.pullWxData.call(this, 'wx_web_token', postdata)
console.log('============= 有code的session =============');
console.log(this.sess);
return yield dealWith()
}else{
console.log('============ 没有code的session ===========');
console.log(this.sess);
return yield dealWith();
}
}
module.exports = {
getData : demoIndexData
}