Commit b20b3c40 authored by zjz1994's avatar zjz1994

新post请求方式

parent 3a47b7b3
......@@ -65,12 +65,19 @@ export abstract class ABNetManager {
if(net.type=="post"){
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){
//ios 11以下
var netpro = new Promise(function(resolve,reject){
if (net.name == 'imgURL') {
callNativePost(
this.callNativePost(
obj.url,
{},
{
......@@ -88,7 +95,9 @@ export abstract class ABNetManager {
reject(err)
})
}else{
callNativePost(
// console.log("test----newPost");
// console.log(this.callNativePost);
this.callNativePost(
obj.url,
obj.data
)
......@@ -99,9 +108,9 @@ export abstract class ABNetManager {
reject(err);
})
}
})
}.bind(this));
netpro.then((result:IData)=>{
console.log("post-----success",obj.url);
console.log("post-----success",result);
this.onResponse(net, result);
},err=>{
console.error("post-----error",obj.url)
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment