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
f1975ebb
提交
f1975ebb
authored
9月 25, 2018
作者:
王进
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
暴露上报注册和登录接口
上级
155b3925
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
88 行增加
和
84 行删除
+88
-84
SDK.ts
20180925/SDK.ts
+88
-84
没有找到文件。
20180925/SDK.ts
浏览文件 @
f1975ebb
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
* @time: 2018-09-19
* @time: 2018-09-19
*/
*/
class
WechatSDK
{
class
WechatSDK
{
private
sdkVersion
:
string
=
'1.2'
public
constructor
()
{
public
constructor
()
{
this
.
sdkInit
()
this
.
sdkInit
()
}
}
...
@@ -11,7 +12,7 @@ class WechatSDK {
...
@@ -11,7 +12,7 @@ class WechatSDK {
const
_selt
=
this
const
_selt
=
this
_selt
.
ReportParams
.
productCode
=
_selt
.
sdkParams
.
product_code
=
SDKConfig
.
productCode
_selt
.
ReportParams
.
productCode
=
_selt
.
sdkParams
.
product_code
=
SDKConfig
.
productCode
_selt
.
sdkParams
.
appid
=
SDKConfig
.
appid
_selt
.
sdkParams
.
appid
=
SDKConfig
.
appid
_selt
.
sdkParams
.
version
=
SDKConfig
.
sdkVersion
_selt
.
sdkParams
.
version
=
_selt
.
sdkVersion
const
options
=
_selt
.
getOptionsInfo
()
// 返回参数对象
const
options
=
_selt
.
getOptionsInfo
()
// 返回参数对象
_selt
.
ReportParams
.
from
=
options
.
from
||
0
_selt
.
ReportParams
.
from
=
options
.
from
||
0
_selt
.
ReportParams
.
tag
=
options
.
tag
||
0
_selt
.
ReportParams
.
tag
=
options
.
tag
||
0
...
@@ -47,9 +48,7 @@ class WechatSDK {
...
@@ -47,9 +48,7 @@ class WechatSDK {
_selt
.
sdkParams
.
pay_channel
=
res
.
data
.
default_pay_channel
_selt
.
sdkParams
.
pay_channel
=
res
.
data
.
default_pay_channel
_selt
.
getAuthorize
=
res
.
data
.
weixin_from
_selt
.
getAuthorize
=
res
.
data
.
weixin_from
_selt
.
sdkLogin
(
LoginCallBack
)
_selt
.
sdkLogin
(
LoginCallBack
)
_selt
.
ReportData
({
// 上报激活
_selt
.
ActiReport
()
// 上报激活
action
:
'activation'
})
},
err
=>
{
console
.
log
(
err
)
})
},
err
=>
{
console
.
log
(
err
)
})
}
}
private
sdkLogin
(
LoginCallBack
)
{
private
sdkLogin
(
LoginCallBack
)
{
...
@@ -60,15 +59,8 @@ class WechatSDK {
...
@@ -60,15 +59,8 @@ class WechatSDK {
.
then
(
res
=>
{
.
then
(
res
=>
{
if
(
res
.
code
==
0
)
{
if
(
res
.
code
==
0
)
{
// 根据SDK返回用户状态来判断用户是否注册
// 根据SDK返回用户状态来判断用户是否注册
const
type
=
res
.
data
.
action
==
'login'
?
'login'
:
'register'
_selt
.
sdkParams
.
token
=
res
.
data
.
token
// 记录用户toekn
_selt
.
sdkParams
.
token
=
res
.
data
.
token
// 记录用户toekn
_selt
.
ReportParams
.
userId
=
res
.
data
.
uid
// 记录用户ID
_selt
.
ReportParams
.
userId
=
res
.
data
.
uid
// 记录用户ID
if
(
type
==
'register'
)
{
_selt
.
ReportData
({
action
:
'register'
})
// 上报注册
}
// 所有用户(包括注册)也需要上报登录
_selt
.
ReportData
({
action
:
'login'
})
// 上报登录
LoginCallBack
(
_selt
.
deepCopy
({},
res
.
data
,
{
LoginCallBack
(
_selt
.
deepCopy
({},
res
.
data
,
{
os
:
_selt
.
sdkParams
.
os
,
// 返回系统类型IOS或者android
os
:
_selt
.
sdkParams
.
os
,
// 返回系统类型IOS或者android
session_key
:
_selt
.
sdkParams
.
session_key
// 返回session_key
session_key
:
_selt
.
sdkParams
.
session_key
// 返回session_key
...
@@ -329,6 +321,18 @@ class WechatSDK {
...
@@ -329,6 +321,18 @@ class WechatSDK {
console
.
log
(
"##SDK激活上报参数"
,
portData
)
console
.
log
(
"##SDK激活上报参数"
,
portData
)
return
this
.
request
(
link
,
portData
)
return
this
.
request
(
link
,
portData
)
}
}
// 上报激活
public
ActiReport
()
{
this
.
ReportData
({
action
:
'activation'
})
}
// 上报注册
public
RegisterReport
()
{
this
.
ReportData
({
action
:
'register'
})
}
// 上报登录
public
LoginReport
()
{
this
.
ReportData
({
action
:
'login'
})
}
// 数据上报接口,外部调用,参数中必须含有action值
// 数据上报接口,外部调用,参数中必须含有action值
public
ReportData
(
portData
)
{
public
ReportData
(
portData
)
{
const
that
=
this
const
that
=
this
...
@@ -405,41 +409,73 @@ class WechatSDK {
...
@@ -405,41 +409,73 @@ class WechatSDK {
const
_selt
=
this
const
_selt
=
this
// const isAuthorize = _selt.ReportParams.from && (Object.keys(_selt.getAuthorize).length > 0) ? _selt.getAuthorize[_selt.ReportParams.from] : false
// const isAuthorize = _selt.ReportParams.from && (Object.keys(_selt.getAuthorize).length > 0) ? _selt.getAuthorize[_selt.ReportParams.from] : false
// if (isAuthorize) {
// if (isAuthorize) {
return
new
Promise
(
async
function
(
resolve
,
reject
)
{
return
new
Promise
(
async
function
(
resolve
,
reject
)
{
let
status
=
await
_selt
.
_getSetting
();
let
status
=
await
_selt
.
_getSetting
();
switch
(
status
)
{
switch
(
status
)
{
case
1
:
case
1
:
// 用户已授权,可以直接调用相关 API
// 用户已授权,可以直接调用相关 API
var
userInfo
=
await
_selt
.
_getUserInfo
();
var
userInfo
=
await
_selt
.
_getUserInfo
();
// 上报用户授权
// 上报用户授权
_selt
.
ReportData
(
_selt
.
deepCopy
({},
userInfo
,
{
_selt
.
ReportData
(
_selt
.
deepCopy
({},
userInfo
,
{
action
:
'authorize'
,
action
:
'authorize'
,
nickName
:
encodeURI
(
userInfo
.
nickName
)
nickName
:
encodeURI
(
userInfo
.
nickName
)
}))
}))
resolve
(
userInfo
);
resolve
(
userInfo
);
break
;
break
;
case
0
:
case
0
:
// 用户已拒绝授权,再调用相关 API 或者 wx.authorize 会失败,需要引导用户到设置页面打开授权开关
// 用户已拒绝授权,再调用相关 API 或者 wx.authorize 会失败,需要引导用户到设置页面打开授权开关
var
w
=
(
wx
as
any
).
getSystemInfoSync
().
windowWidth
;
var
w
=
(
wx
as
any
).
getSystemInfoSync
().
windowWidth
;
var
h
=
(
wx
as
any
).
getSystemInfoSync
().
windowHeight
;
var
h
=
(
wx
as
any
).
getSystemInfoSync
().
windowHeight
;
var
OpenSettingButton
=
(
wx
as
any
).
createOpenSettingButton
({
var
OpenSettingButton
=
(
wx
as
any
).
createOpenSettingButton
({
type
:
"text"
,
type
:
"text"
,
text
:
""
,
text
:
""
,
style
:
{
style
:
{
left
:
0
,
left
:
0
,
top
:
0
,
top
:
0
,
width
:
w
,
width
:
w
,
height
:
h
height
:
h
}
}
});
});
OpenSettingButton
.
onTap
(
async
function
(
res
)
{
OpenSettingButton
.
onTap
(
async
function
(
res
)
{
let
t_status
=
await
_selt
.
_getSetting
();
let
t_status
=
await
_selt
.
_getSetting
();
console
.
log
(
"@@SDK:点击设置按钮返回t_status="
,
t_status
);
console
.
log
(
"@@SDK:点击设置按钮返回t_status="
,
t_status
);
if
(
t_status
==
1
)
{
if
(
t_status
==
1
)
{
OpenSettingButton
.
offTap
(
this
);
OpenSettingButton
.
offTap
(
this
);
OpenSettingButton
.
destroy
();
OpenSettingButton
.
destroy
();
OpenSettingButton
=
null
;
OpenSettingButton
=
null
;
var
userInfo
=
await
_selt
.
_getUserInfo
();
var
userInfo
=
await
_selt
.
_getUserInfo
();
// 上报用户授权
_selt
.
ReportData
(
_selt
.
deepCopy
({},
userInfo
,
{
action
:
'authorize'
,
nickName
:
encodeURI
(
userInfo
.
nickName
)
}))
resolve
(
userInfo
);
}
});
break
;
case
-
1
:
// 未询问过用户授权,调用相关 API 或者 wx.authorize 会弹窗询问用户
var
w
=
(
wx
as
any
).
getSystemInfoSync
().
windowWidth
;
var
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
},
});
userBtn
.
onTap
(
function
(
res
)
{
if
(
res
.
userInfo
)
{
//上报授权
userBtn
.
offTap
(
this
);
userBtn
.
destroy
();
userBtn
=
null
;
var
userInfo
=
res
[
"userInfo"
];
// 上报用户授权
// 上报用户授权
_selt
.
ReportData
(
_selt
.
deepCopy
({},
userInfo
,
{
_selt
.
ReportData
(
_selt
.
deepCopy
({},
userInfo
,
{
action
:
'authorize'
,
action
:
'authorize'
,
...
@@ -447,43 +483,11 @@ class WechatSDK {
...
@@ -447,43 +483,11 @@ class WechatSDK {
}))
}))
resolve
(
userInfo
);
resolve
(
userInfo
);
}
}
});
}
break
;
);
case
-
1
:
break
;
// 未询问过用户授权,调用相关 API 或者 wx.authorize 会弹窗询问用户
}
var
w
=
(
wx
as
any
).
getSystemInfoSync
().
windowWidth
;
})
var
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
},
});
userBtn
.
onTap
(
function
(
res
)
{
if
(
res
.
userInfo
)
{
//上报授权
userBtn
.
offTap
(
this
);
userBtn
.
destroy
();
userBtn
=
null
;
var
userInfo
=
res
[
"userInfo"
];
// 上报用户授权
_selt
.
ReportData
(
_selt
.
deepCopy
({},
userInfo
,
{
action
:
'authorize'
,
nickName
:
encodeURI
(
userInfo
.
nickName
)
}))
resolve
(
userInfo
);
}
}
);
break
;
}
})
// } else {
// } else {
// console.log("##SDK--> 渠道并未开启授权")
// console.log("##SDK--> 渠道并未开启授权")
// }
// }
...
@@ -543,7 +547,7 @@ class WechatSDK {
...
@@ -543,7 +547,7 @@ class WechatSDK {
},
},
complete
()
{
complete
()
{
console
.
log
(
"##SDK分享发起"
)
console
.
log
(
"##SDK分享发起"
)
resolve
(
0
)
resolve
(
0
)
;
}
}
}))
}))
}
catch
(
err
)
{
}
catch
(
err
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论