Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xiaoxiaole
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wildfirecode13
xiaoxiaole
Commits
b20b3c40
Commit
b20b3c40
authored
Apr 14, 2020
by
zjz1994
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新post请求方式
parent
3a47b7b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
5 deletions
+58
-5
ABNetManager.ts
egret/libs/tc/manager/ABNetManager.ts
+58
-5
No files found.
egret/libs/tc/manager/ABNetManager.ts
View file @
b20b3c40
...
@@ -65,12 +65,19 @@ export abstract class ABNetManager {
...
@@ -65,12 +65,19 @@ export abstract class ABNetManager {
if
(
net
.
type
==
"post"
){
if
(
net
.
type
==
"post"
){
var
testplatform
=
!
iswx
()
&&
getIsIOS
()
&&
window
[
'SNNativeClient'
]
&&
window
[
'SNNativeClient'
].
callNativeFormDataReq
&&
getIOSversion
()
&&
parseInt
(
getIOSversion
().
split
(
'.'
)[
0
])
<
11
?
true
:
false
;
var
testplatform
=
!
iswx
()
&&
getIsIOS
()
&&
window
[
'SNNativeClient'
]
&&
window
[
'SNNativeClient'
].
callNativeFormDataReq
&&
getIOSversion
()
&&
parseInt
(
getIOSversion
().
split
(
'.'
)[
0
])
<
11
?
true
:
false
;
console
.
log
(
"平台测试"
,
testplatform
,
iswx
(),
getIsIOS
(),
window
[
'SNNativeClient'
],
getIOSversion
());
// console.log("平台测试",testplatform);
// console.log("isWX",iswx());
// console.log("isIOS",getIsIOS(),"IOSver",getIOSversion());
// console.log("新post是否存在1",window['SNNativeClient']);
// console.log("新post是否存在2",callNativePost);
console
.
log
(
"新post是否存在3"
,
window
[
'SNNativeClient'
].
callNativeFormDataReq
);
console
.
log
(
"net"
,
net
,
"obj"
,
obj
);
testplatform
=
true
;
if
(
testplatform
){
if
(
testplatform
){
//ios 11以下
//ios 11以下
var
netpro
=
new
Promise
(
function
(
resolve
,
reject
){
var
netpro
=
new
Promise
(
function
(
resolve
,
reject
){
if
(
net
.
name
==
'imgURL'
)
{
if
(
net
.
name
==
'imgURL'
)
{
callNativePost
(
this
.
callNativePost
(
obj
.
url
,
obj
.
url
,
{},
{},
{
{
...
@@ -88,7 +95,9 @@ export abstract class ABNetManager {
...
@@ -88,7 +95,9 @@ export abstract class ABNetManager {
reject
(
err
)
reject
(
err
)
})
})
}
else
{
}
else
{
callNativePost
(
// console.log("test----newPost");
// console.log(this.callNativePost);
this
.
callNativePost
(
obj
.
url
,
obj
.
url
,
obj
.
data
obj
.
data
)
)
...
@@ -99,9 +108,9 @@ export abstract class ABNetManager {
...
@@ -99,9 +108,9 @@ export abstract class ABNetManager {
reject
(
err
);
reject
(
err
);
})
})
}
}
}
)
}
.
bind
(
this
));
netpro
.
then
((
result
:
IData
)
=>
{
netpro
.
then
((
result
:
IData
)
=>
{
console
.
log
(
"post-----success"
,
obj
.
url
);
console
.
log
(
"post-----success"
,
result
);
this
.
onResponse
(
net
,
result
);
this
.
onResponse
(
net
,
result
);
},
err
=>
{
},
err
=>
{
console
.
error
(
"post-----error"
,
obj
.
url
)
console
.
error
(
"post-----error"
,
obj
.
url
)
...
@@ -116,6 +125,50 @@ export abstract class ABNetManager {
...
@@ -116,6 +125,50 @@ export abstract class ABNetManager {
}
}
protected
callNativePost
(
url
,
postData
,
photoInfo
=
null
,
needSuAES
:
boolean
=
false
)
{
// console.log("新post------callNativePost",url,postData,photoInfo,needSuAES);
var
dataArr
=
[],
photoInfo
=
typeof
photoInfo
==
'object'
?
photoInfo
:
null
,
//非图片上传 默认null
// needSuAES = needSuAES !== false && SuAES && typeof SuAES.encrypt == 'function' ? true : false, //判断是否加密
_href
=
window
.
location
.
href
,
_refer
=
_href
.
indexOf
(
'#'
)
>
-
1
?
_href
.
split
(
'#'
)[
0
]
:
_href
;
//客户端需要refer
// if (needSuAES) {
// //加密时拼接建值
// for (var key in postData) {
// dataArr.push(encodeURIComponent(key) + '=' + encodeURIComponent(postData[key]))
// }
// //拼接地址,加协议头
// url = url.indexOf('http:') > -1 || url.indexOf('https:') > -1 ? url + '?_x_req_block_=' + encodeURIComponent(SuAES.encrypt(dataArr.join("&"))) + '&_x_resp_flag_=2' : window.location.protocol + url + '?_x_req_block_=' + encodeURIComponent(SuAES.encrypt(dataArr.join("&"))) + '&_x_resp_flag_=2';
// } else {
//修改
url
=
"https://activity.m.duibatest.com.cn"
+
url
;
url
=
url
.
indexOf
(
'http:'
)
>
-
1
||
url
.
indexOf
(
'https:'
)
>
-
1
?
url
:
window
.
location
.
protocol
+
url
;
// }
console
.
log
(
"新post------发送请求"
,
url
,
_refer
,
photoInfo
,
postData
);
var
upload
=
new
Promise
(
function
(
resolve
,
reject
)
{
//调用客户端方法,根据加密与否修改传参
window
[
'SNNativeClient'
].
callNativeFormDataReq
(
url
,
_refer
,
photoInfo
,
postData
,
function
callback
(
res
)
{
console
.
log
(
"新post------res"
,
res
);
//ios返回为字符串 需格式化
res
=
JSON
.
parse
(
res
)
//加密数据解密
// if(needSuAES && res && res.x_response_security == 1 && res.security_data) {
// res = JSON.parse(decodeURIComponent(SuAES.decrypt(res.security_data)))
// }
//返回处理逻辑
if
(
!
res
||
(
res
&&
res
.
statusCode
>=
400
))
{
console
.
error
(
"新post---error"
,
res
);
reject
(
res
)
}
else
if
(
res
)
{
console
.
log
(
"新post---response"
,
res
);
resolve
(
res
)
}
});
});
return
upload
;
}
/**
/**
* 消息响应
* 消息响应
* @param net
* @param net
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment