微信小程序开发(六)第六章APIAPI框架总览(绘图API专列章学习,暂略)网络API媒体API数据API位置API窗口API绘图API开放API设备API第1节网络API1.发送请求:wx.request(object)+数据请求Wx.request({url:url,data:{object},method:get|post,dataType:json,header:{content-type:application/json},success:function(res){vardata=res.data},fail:function(){},complate:function(){}})+选取一个图片上传Wx.chooseImage({Success:function(res){Vartmp=res.tempFilePathsWx.uploadFile({url:url,filePath:tmp[0],name:”file”,formData:{user:test}})}})+下载一段音乐播放Wx.downloadFile({url:url,type:audio,success:function(res){wx.playVoice({filePath:res.tmpFilePath})}})2.上传下载:wx.upload(object)|wx.download(object)3.嵌套字:+连接Wx.connectSocket({url:url,data:{data},header:{},method:get|post})+打开Wx.onSocketOpen(function(res){…})+出错Wx.onSocketError(function(res){…})+发数据Wx.sendSocketMessage({data:msg})+发消息(回调)Wx.onSocketMessage(function(res){…})+关闭Wx.closeSocket({url:url})+关闭(回调)Wx.onSocketClose(function(res){…})+选图Wx.chooseImage({count:1,sizetype:[],sourceType:[album,camera],success:function(res){…}})+预览Wx.previewImage({current:’’,urls:[]})第2节媒体API1.图片:2.录音:+录音Wx.startRecord({success:function(){},fail:function(){}})+停止Wx.stopRecord()+播放Wx.playVoice({filePath:xxxx,comlete:function(){…}})+暂停Wx.pauseVoice()+停止Wx.stopVoice()+获状态Wx.getBackgroundAudioPlayState({success:function(res){res.status|dataUrl|currentPosition|duration}})+播放Wx.playBackgroundAudio({dataUrl:xx,title:xx,coverImgUrl:xx})+暂停Wx.pauseBackgroundAudio()+定位Wx.seekBackgroundAudio({position:60})+停止Wx.stopBackgroundAudion()3.音频控制:4.音乐控制:5.视频:+表现层get+逻辑层Page({Data:{src:xxx},getVideo:function(){varthat=this;wx.chooseVideo({sourceType:[],success:function(res){that.setData({src:res.tempfilePath})}})}})+创建上下文Varctx=wx.createAudioContext(audioId)+播放Ctx.paly()+暂停Ctx.pause()+进到Ctx.seek(n)+从头Ctx.seek(0)+停止Ctx.stop()+创建上下文Varctx=wx.createVedioContext(videoId)+发送弹幕Ctx.sendDanmu({text:xxxx,color:#xxxxxx})6.音频组件控制:7.视频组件控制:8.文件:+保存文件Wx.saveFile({tempFilePath:xxx,success:function(res){…}})+获已保存文件列表Wx.getSavedFileList({success:function(res){varlist=res.fileList}})+获已保存文件信息Wx.getSavedFileInfo({filePath:xxx,success:function(res){…}})+移除已保存文件Wx.removeSavedFile({filePath:xxx,complete:function(res){…}})+打开文件Wx.openDocument({filePath:xxx,success:function(res){…}})+设置数据Wx.setStorage({key:xxx,value:xxx})+获取数据Wx.getStorage({key:xxx,success:function(res){…}})+清空数据Wx.clearStorage()+设;置数据(异步)Wx.setStorageSync({key:xxx,value:xxx})+获取数据(异步)Wx.getStorageSync({key:xxx,success:function(res){…}})+清空数据(异步)Wx.clearStorageSync()第3节数据API第4节位置API1.位置:+获取位置Wx.getLocation({type:xxx,success:function(res){…}})+打开位置Wx.openLocation({latitude:xx,longItude:xx,scale:xx})+选择位置Wx.chooseLocation({success:function(res){…}})+创建上下文Varctx=wx.createMapContext(mapId)+中心打开Ctx.openCenterLocation({success:function(res){…}})+移动位置Ctx.moveToLocation({success:function(res){…}})+同步获取信息wx.getSystemInfo({success:function(res){console.log(res.model)console.log(res.pixelRatio)console.log(res.windowWidth)console.log(res.windowHeight)...