Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dxw_sdk_release
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
JIRA
JIRA
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
open
dxw_sdk_release
Commits
ff9a1c46
提交
ff9a1c46
authored
4月 28, 2021
作者:
王进
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新用户授权接口
1. 增加getUserProfile兼容 2. 优化getUserInfo代码
上级
ade6972a
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
43 行删除
+48
-43
SDK.ts
SDK.ts
+48
-43
没有找到文件。
SDK.ts
浏览文件 @
ff9a1c46
...
...
@@ -311,22 +311,28 @@ class WechatSDK {
});
}
// 获取用户信息
public
getUserInfo
=
async
()
=>
{
let
status
=
await
this
.
_getSetting
();
public
getUserInfo
=
():
Promise
<
any
>
=>
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
if
((
wx
as
any
).
getUserProfile
)
{
const
userInfo
=
await
this
.
_getUserProfile
();
resolve
(
userInfo
);
return
;
}
const
status
=
await
this
.
_getSetting
();
const
w
=
(
wx
as
any
).
getSystemInfoSync
().
windowWidth
;
const
h
=
(
wx
as
any
).
getSystemInfoSync
().
windowHeight
;
if
(
status
==
1
)
{
// 用户已授权,可以直接调用相关 API
let
userInfo
=
await
this
.
_getUserInfo
();
const
userInfo
=
await
this
.
_getUserInfo
();
if
(
userInfo
.
nickname
)
{
// 上报用户授权
this
.
ReportData
({
userInfo
:
{
...
userInfo
,
nickName
:
encodeURI
(
userInfo
.
nickName
)
},
action
:
'authorize'
,
})
return
userInfo
;
}
else
if
(
status
==
0
)
{
resolve
(
userInfo
);
}
else
if
(
status
==
0
)
{
// 用户已拒绝授权,再调用相关 API 或者 wx.authorize 会失败,需要引导用户到设置页面打开授权开关
const
w
=
(
wx
as
any
).
getSystemInfoSync
().
windowWidth
;
const
h
=
(
wx
as
any
).
getSystemInfoSync
().
windowHeight
;
let
OpenSettingButton
=
(
wx
as
any
).
createOpenSettingButton
({
type
:
"text"
,
text
:
""
,
...
...
@@ -339,11 +345,10 @@ class WechatSDK {
});
OpenSettingButton
.
onTap
(
async
(
res
)
=>
{
let
t_status
=
await
this
.
_getSetting
();
console
.
log
(
"--SDK点击设置按钮返回t_status="
,
t_status
);
if
(
t_status
==
1
)
{
OpenSettingButton
.
offTap
(
this
);
OpenSettingButton
.
destroy
();
OpenSettingButton
=
null
;
if
(
t_status
==
1
)
{
let
userInfo
=
await
this
.
_getUserInfo
();
// 上报用户授权
this
.
ReportData
({
...
...
@@ -351,18 +356,27 @@ class WechatSDK {
action
:
'authorize'
,
nickName
:
encodeURI
(
userInfo
.
nickName
)
})
return
userInfo
;
resolve
(
userInfo
)
;
}
});
}
else
if
(
status
==
-
1
)
{
let
userBtn
=
this
.
createUserInfoButton
();
let
userBtn
=
(
wx
as
any
).
createUserInfoButton
({
type
:
"text"
,
text
:
""
,
withCredentials
:
false
,
style
:
{
left
:
0
,
top
:
0
,
width
:
w
,
height
:
h
,
},
});
userBtn
.
onTap
((
res
)
=>
{
if
(
res
.
userInfo
)
{
//上报授权
userBtn
.
offTap
(
this
);
userBtn
.
destroy
();
userBtn
=
null
;
if
(
res
.
userInfo
)
{
let
userInfo
=
res
[
"userInfo"
];
// 上报用户授权
this
.
ReportData
({
...
...
@@ -370,27 +384,26 @@ class WechatSDK {
action
:
'authorize'
,
nickName
:
encodeURI
(
userInfo
.
nickName
)
})
return
userInfo
;
resolve
(
userInfo
)
;
}
});
}
}
private
createUserInfoButton
()
{
// 未询问过用户授权,调用相关 API 或者 wx.authorize 会弹窗询问用户
let
w
=
(
wx
as
any
).
getSystemInfoSync
().
windowWidth
;
let
h
=
(
wx
as
any
).
getSystemInfoSync
().
windowHeight
;
let
userBtn
=
(
wx
as
any
).
createUserInfoButton
({
type
:
"text"
,
text
:
""
,
withCredentials
:
false
,
style
:
{
left
:
0
,
top
:
0
,
width
:
w
,
height
:
h
});
};
private
async
_getUserProfile
():
Promise
<
any
>
{
return
new
Promise
(
async
function
(
resolve
,
reject
)
{
(
wx
as
any
).
getUserProfile
({
desc
:
'完善用户资料'
,
success
:
(
res
)
=>
{
let
userInfo
=
res
[
"userInfo"
];
resolve
(
userInfo
);
},
fail
:
(
res
:
any
)
=>
{
console
.
log
(
"--SDK:玩家头像等数据失败,用户未授权"
);
resolve
();
}
});
});
return
userBtn
}
private
async
_getUserInfo
():
Promise
<
any
>
{
return
new
Promise
(
async
function
(
resolve
,
reject
)
{
...
...
@@ -402,7 +415,7 @@ class WechatSDK {
},
fail
:
(
res
:
any
)
=>
{
console
.
log
(
"--SDK:玩家头像等数据失败,用户未授权"
);
reject
();
resolve
();
}
});
});
...
...
@@ -412,19 +425,11 @@ class WechatSDK {
(
wx
as
any
).
getSetting
({
success
:
function
(
res
)
{
let
authSetting
=
res
.
authSetting
;
if
(
authSetting
[
'scope.userInfo'
]
===
true
)
{
resolve
(
1
);
}
else
if
(
authSetting
[
'scope.userInfo'
]
===
false
)
{
resolve
(
0
);
}
else
{
resolve
(
-
1
);
}
},
fail
:
function
()
{
reject
();
if
(
authSetting
[
'scope.userInfo'
]
===
true
)
resolve
(
1
);
else
if
(
authSetting
[
'scope.userInfo'
]
===
false
)
resolve
(
0
);
else
resolve
(
-
1
);
},
fail
:
reject
,
});
});
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论