login-service.js
2.42 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
import BaseService from './base-service.js';
import {MINI_APP_TYPE} from '../../../libs/config.js';
import regeneratorRuntime from '../../libs/regenerator-runtime/index.js';
const WECHAT_SMALLPROGRAM_ONLOGIN = 'wechat.smallProgram.onLogin';
const WECHAT_SMALLPROGRAM_DECODEUSERINFO = 'wechat.smallProgram.decodeUserInfo';
const WECHAT_ADDUNIONUPDUSER = 'app.wechat.addUnionUpdUser';
const WECHAT_PASSPORT_SIGNINBYOPENID = 'app.passport.signinByOpenID';
const WECHAT_PASSPORT_MINIAPPBINDBYAUTO = 'app.passport.miniAppBindByAuto';
const WECHAT_ADDUPDUSER = 'app.wechat.addUpdUser';
const WECHAT_PASSPORT_VERIFY = 'app.passport.verify'
const WechatPath = '/wechat/';
export default class LoginService extends BaseService {
async checkLogin(code) {
return await this.GET({
method: WECHAT_SMALLPROGRAM_ONLOGIN,
jsCode: code,
miniapp_type: MINI_APP_TYPE
}, {
path: WechatPath
})
}
async decodeUserInfo(srdSession, encryptedData, iv) {
return await this.GET({
method: WECHAT_SMALLPROGRAM_DECODEUSERINFO,
srdSession,
encryptedData,
iv
}, {
path: WechatPath
});
}
async checkUidAndSessionKey(uid, session_key) {
let params = {}
if (uid) {
params.uid = uid
}
if (session_key) {
params.session_key = session_key;
}
return await this.GET({
method: WECHAT_PASSPORT_VERIFY,
...params
})
}
async sendWeChatUserDataWithUnionId(unionId, nickname, avatarUrl) {
if (!unionId || !nickname || !avatarUrl || avatarUrl === "images/mine_default_head.png") throw new Error('请检查 unionId 或用户信息是否有误');
return await this.GET({
method: WECHAT_ADDUNIONUPDUSER,
unionId,
headIco: avatarUrl,
nickname
});
}
async sendWeChatUserData(uid, nickname, avatarUrl) {
if (!uid || !nickname || !avatarUrl || avatarUrl === "images/mine_default_head.png") throw new Error('请检查 uid 或用户信息是否有误');
return await this.GET({
method: WECHAT_ADDUPDUSER,
uid,
headIco: avatarUrl,
nickname
});
}
async wechatUserIsBind(unionId) {
return await this.GET({
method: WECHAT_PASSPORT_SIGNINBYOPENID,
openId: unionId,
})
}
async bindMiniAppByAuto(union_id, mobile, areaCode = 86) {
return await this.GET({
method: WECHAT_PASSPORT_MINIAPPBINDBYAUTO,
open_id: union_id,
mobile,
area: areaCode
})
}
}