API
發(fā)起請(qǐng)求
wx.request({
url: 'test.php',
data: { x: '' , y: '' },
header: { 'content-type': 'application/json' },
success: function(res) { console.log(res.data) }
})
*** 一個(gè)小程序一次最多只能發(fā)起5次請(qǐng)求***
上傳和下載
wx.chooseImage({
success: function(res) {
var tempFilePaths = res.tempFilePaths
wx.uploadFile({ url: 'http://example.weixin.qq.com/upload',
filePath: tempFilePaths[0],
name: 'file',
formData:{ 'user': 'test' },
success: function(res){ var data = res.data //do something }
})
}})
wx.downloadFile({
url: 'http://example.com/audio/123',
success: function(res) {
wx.playVoice({ filePath: res.tempFilePath })
}
})
WebSocket
WebSocket一種在單個(gè)TCP 連接上進(jìn)行全雙工通訊的協(xié)議。一個(gè)微信小程序同時(shí)只能有一個(gè) WebSocket 連接,如果當(dāng)前已存在一個(gè) WebSocket 連接,會(huì)自動(dòng)關(guān)閉該連接,并重新創(chuàng)建一個(gè) WebSocket 連接。
wx.connectSocket({
url: 'test.php',
data:{ x: '', y: '' },
header:{ 'content-type': 'application/json' },
method:"GET"
})
媒體
- 圖片
- 錄音
- 文件
- 視頻
數(shù)據(jù)
每個(gè)微信小程序都可以有自己的本地緩存,可以通過(guò) wx.setStorage(wx.setStorageSync)、wx.getStorage(wx.getStorageSync)、wx.clearStorage(wx.clearStorageSync)可以對(duì)本地緩存進(jìn)行設(shè)置、獲取和清理。本地緩存最大為10MB。
位置
wx.getLocation({
type: 'wgs84',
success: function(res) {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
}
})
設(shè)備
- 網(wǎng)絡(luò)
- 數(shù)據(jù)
- 重力
- 打電話(huà)
界面
- 交互反饋
- 導(dǎo)航
- 動(dòng)畫(huà)
- 繪圖
開(kāi)放接口
- 登錄
- 用戶(hù)信息
- 微信支付
- 模板消息
總結(jié)
微信小程序的開(kāi)發(fā)接口是比較豐富的,幾乎涵蓋了APP所具備的所有特性;