<script src="https://pjax.cc/doc/app.api.js"> <script>
ms.getLocation({
success : function(p){
alert(JSON.stringify(p) );
var latitude = p.coords.latitude ;
var longitude = p.coords.longitude ;
var altitude = p.coords.altitude ;
alert('Geolocation\nLatitude:' + latitude + '\nLongitude:' + longitude + '\nAltitude:' + altitude);
},
fail : function(err){
alert("获取地理位置失败:"+ JSON.stringify(err) );
}
});
ms.scanCode({
style : {
background : '#000', //扫码控件背景色
frameColor : '#07c160', //扫码控件边框颜色
scanbarColor : '#07c160' , //扫码控件扫描条颜色
top:'100px', //距离顶部的位置
left:'0px', //距离左侧的位置
width: '100%', //宽度
height: '500px' //高度
},
success : function(code){
alert("扫码识别文本:" + code);
},
fail : function(err){
alert("扫码失败:"+ JSON.stringify(err) );
}
});
ms.closeBarcode();
ms.scanFromGallery({
success : function(code){
alert("相册扫码识别文本:" + code);
},
fail : function(err){
alert("相册扫码失败:"+ JSON.stringify(err) );
}
});
ms.getContacts({
success : function(contacts){
alert(JSON.stringify(contacts) );
},
fail : function(err){
alert("获取通讯录失败:"+ JSON.stringify(err) );
}
});
ms.takePhoto({
success : function(path){
alert( "拍照完成,本地图片路径:\n" + path );
},
fail : function(err){
alert("拍照失败:"+ JSON.stringify(err) );
}
});
ms.chooseImage({
count : 9 , //最大数量,不填则不限制
success : function(path){
if(typeof path == 'string'){
alert( "选取一张图片时返回图片地址:\n" + path );
}else{
alert( "选取多张图片时,返回路径列表:\n" + JSON.stringify(path) );
}
},
fail : function(err){
alert("选取图片失败:"+ JSON.stringify(err) );
}
});
ms.saveImage({
filePath : 'data:image/jpeg;base64,/9j/4AAQSk.......' , //保存的图片路径,支持网络图片与base64路径
success : function(path){
alert( "图片保存成功,本地路径为:\n" + path );
},
fail : function(err){
alert("保存图片失败:"+ JSON.stringify(err) );
}
});
var uploadTask = ms.uploadFile({
url : 'https://xxxx.yourdomain.com/api/saveFile' ,
filePath : downloadFilePath ,
name : 'upfile' ,
mimeType : "image/png" , //指定上传文件的类型,不指定会读取文件名的后缀,可能会导致上传文件无法读取的错误。
options : {
method : "POST" , //仅支持“POST”请求。
blocksize : 102400 , //上传任务每次上传的文件块大小(仅在支持断点续传的服务有效),若设置值小于等于0则表示不分块上传。
priority : 100 , //数值越大优先级越高,默认优先级值为100。
timeout : 120 , // 超时时间为服务器响应请求的时间(不是上传任务完成的总时间),如果设置为0则表示永远不超时。
retry : 3 , //上传任务重试次数
retryInterval : 30 //上传任务重试间隔时间
},
formData : {
type : '测试类型' //自定义的附加数据
},
header : {
customer : "customerValuexxxxx" //不支持设置“Content-Type”、“User-Agent”、“Cookie”的值。
},
onProgress : function(uploadSize , totalSize , percent){
//已上传文件大小,文件总大小,上传百分比
console.log("上传进度:" + uploadSize + "/" + totalSize + ",已上传:" + percent );
},
success : function(res){
alert(JSON.stringify(res));
},
fail : function(err){
alert(JSON.stringify(err));
}
});
setTimeout(function(){
uploadTask.abort(); //取消未完成上传任务
},4000);
var downloadTask = ms.downloadFile({
url : 'https://xxxx.com/download/xxxxx.zip' , //文件的网络链接
onProgress : function(downloadSize , totalSize , percent){
//已下载文件大小,文件总大小,下载百分比
console.log("下载进度:" + downloadSize + "/" + totalSize );
console.log("下载进度百分比:" + percent );
},
success : function(path){
alert( "文件下载成功,本地路径为:\n" + path );
},
fail : function(err){
alert("文件下载失败:"+ JSON.stringify(err) );
}
});
setTimeout(function(){
downloadTask.abort(); //取消未完成下载任务
},4000);
ms.readTxtFile({
filePath : '_doc/xxxxx.txt' , //仅支持本地文件路径
success : function(res){
alert("文件大小:\n" + res.size + "\n文件路径:\n" + res.name + "\n文件内容:\n" + res.content );
},
fail : function(err){
alert("文件读取失败:"+ JSON.stringify(err) );
}
});
ms.setStorage( 'name' , '小明');
var localName = ms.getStorage( 'name' );
//请求微信预付订单信息
sendGetRequest(
"https://xxxxx.com/wxPay" ,
function(res){
ms.wxPay({
statement : res , //服务端返回的支付订单参数
success : function(res){
alert(JSON.stringify(res));
},
fail : function(err){
alert(JSON.stringify(err));
}
});
}
);
//请求微信预付订单信息
sendGetRequest(
"https://xxxxx.com/alipay" ,
function(res){
ms.alipay({
statement : res , //服务端返回的支付订单参数
success : function(res){
alert(JSON.stringify(res));
},
fail : function(err){
alert(JSON.stringify(err));
}
});
}
);