Commit 933632f0 authored by zjz1994's avatar zjz1994

调整post

parent a45598d5
import getIsIOS from "./getIsIOS";
const getIOSversion = ()=>{
if(getIsIOS()){
var str= navigator.userAgent.toLowerCase();
var ver=str.match(/cpu iphone os (.*?) like mac os/);
var iosversion = ver[1].replace(/_/g,".")
return iosversion;
}else {
return null;
}
}
export default getIOSversion
\ No newline at end of file
......@@ -61,10 +61,105 @@ export abstract class ABNetManager {
'Authorization': 'my-auth-token'
}
}
if(net.type=="post"){
var testplatform = !iswx()&&getIsIOS()&&window['SNNativeClient'] && window['SNNativeClient'].callNativeFormDataReq && getIOSversion() && parseInt(getIOSversion().split('.')[0]) < 11 ? true : false;
console.log("平台测试",testplatform);
console.log("isWX",iswx());
console.log("isIOS",getIsIOS(),"IOSver",getIOSversion());
testplatform = true;
if(testplatform){
//ios 11以下
var netpro = new Promise(function(resolve,reject){
if (net.name == 'imgURL') {
this.callNativePost(
obj.url,
{},
{
imagePostKey:'picture',
name:"test",
type:'png',
dataUrl:obj.data
},
false
)
.then(res=>{
resolve(res)
})
.catch(err=>{
reject(err)
})
}else{
this.callNativePost(
obj.url,
obj.data
)
.then(res=>{
resolve(res);
})
.catch(err=>{
reject(err);
})
}
}.bind(this));
netpro.then((result:IData)=>{
this.onResponse(net, result);
},err=>{
console.error("post-----error",obj.url)
this.onError(net);
});
return;
}
}
window['$'].ajax(obj);
}
protected callNativePost(url, postData, photoInfo=null, needSuAES:boolean=false) {
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) {
// console.log("加密请求post");
// //加密时拼接建值
// 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 {
// console.log("不加密请求post");
//修改
url = "https://"+window.location.host+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;
}
/**
* 消息响应
......
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