wx.chooseLocation(OBJECT)打开地图选择位置 OBJECT参数说明: | 参数 | 类型 | 必填 | 说明 |
|---|
| success | Function | 是 | 接口调用成功的回调函数,返回内容详见返回参数说明。 | | cancel | Function | 否 | 用户取消时调用 | | fail | Function | 否 | 接口调用失败的回调函数 | | complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数说明: | 参数 | 说明 |
|---|
| name | 位置名称 | | address | 详细地址 | | latitude | 纬度,浮点数,范围为-90~90,负数表示南纬 | | longitude | 经度,浮点数,范围为-180~180,负数表示西经 |
wx.getImageInfo(OBJECT)获取图片信息 OBJECT参数说明: | 参数 | 类型 | 必填 | 说明 |
|---|
| src | String | 是 | 图片的路径,可以是相对路径,临时文件路径,存储文件路径 | | success | Function | 否 | 接口调用成功的回调函数 | | fail | Function | 否 | 接口调用失败的回调函数 | | complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数说明: | 参数 | 类型 | 说明 |
|---|
| width | Number | 图片宽度,单位px | | height | Number | 图片高度 单位px |
示例代码: wx.getImageInfo({
src: 'images/a.jpg',
success: function (res) {
console.log(res.width)
console.log(res.height)
}
})
wx.chooseImage({
success: function (res) {
wx.getImageInfo({
src: res.tempFilePaths[0],
success: function (res) {
console.log(res.width)
console.log(res.height)
}
})
}
})
wx.createAudioContext(audioId)创建并返回 audio 上下文 audioContext 对象 audioContextaudioContext 通过 audioId 跟一个 audio 组件绑定,通过它可以操作一个 audio 组件。
audioContext对象的方法列表: | 方法 | 参数 | 说明 |
|---|
| play | 无 | 播放 | | pause | 无 | 暂停 | | seek | position | 跳转到指定位置,单位 s |
示例代码:
<audio src="{{src}}" id="myAudio" ></audio>
<button type="primary" bindtap="audioPlay">播放</button>
<button type="primary" bindtap="audioPause">暂停</button>
<button type="primary" bindtap="audio14">设置当前播放时间为14秒</button>
<button type="primary" bindtap="audioStart">回到开头</button>
Page({
onReady: function (e) {
this.audioCtx = wx.createAudioContext('myAudio')
},
data: {
src: ',
},
audioPlay: function () {
this.audioCtx.play()
},
audioPause: function () {
this.audioCtx.pause()
},
audio14: function () {
this.audioCtx.seek(14)
},
audioStart: function () {
this.audioCtx.seek(0)
}
})
wx.createVideoContext(videoId)创建并返回 video 上下文 videoContext 对象 videoContextvideoContext 通过 videoId 跟一个 video 组件绑定,通过它可以操作一个 video 组件。
videoContext对象的方法列表: | 方法 | 参数 | 说明 |
|---|
| play | 无 | 播放 | | pause | 无 | 暂停 | | seek | position | 跳转到指定位置,单位 s | | sendDanmu | danmu | 发送弹幕,danmu 包含两个属性 text, color。 |
示例代码: <view class="section tc">
<video id="myVideo" src="" enable-danmu danmu-btn controls></video>
<view class="btn-area">
<input bindblur="bindInputBlur"/>
<button bindtap="bindSendDanmu">发送弹幕</button>
</view>
</view>
function getRandomColor () {
let rgb = []
for (let i = 0 ; i < 3; ++i){
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
Page({
onReady: function (res) {
this.videoContext = wx.createVideoContext('myVideo')
},
inputValue: '',
bindInputBlur: function(e) {
this.inputValue = e.detail.value
},
bindSendDanmu: function () {
this.videoContext.sendDanmu({
text: this.inputValue,
color: getRandomColor()
})
}
})
wx.getSystemInfoSync()获取系统信息同步接口 示例代码: try {
var res = wx.getSystemInfoSync()
console.log(res.model)
console.log(res.pixelRatio)
console.log(res.windowWidth)
console.log(res.windowHeight)
console.log(res.language)
console.log(res.version)
} catch (e) {
}
wx.makePhoneCall(OBJECT)OBJECT参数说明: | 参数 | 类型 | 必填 | 说明 |
|---|
| phoneNumber | String | 是 | 需要拨打的电话号码 | | success | Function | 是 | 接口调用成功的回调 | | fail | Function | 否 | 接口调用失败的回调函数 | | complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码: wx.makePhoneCall({
phoneNumber: '1340000'
})
wx.canvasToTempFilePath(OBJECT)把当前画布的内容导出生成图片,并返回文件路径 OBJECT参数说明: | 参数 | 类型 | 必填 | 说明 |
|---|
| canvasId | String | 是 | 画布标识,传入 <canvas/> 的 cavas-id |
wx.login(OBJECT)调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key)。用户数据的加解密通讯需要依赖会话密钥完成。 OBJECT参数说明: | 参数名 | 类型 | 必填 | 说明 |
|---|
| success | Function | 否 | 接口调用成功的回调函数 | | fail | Function | 否 | 接口调用失败的回调函数 | | complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数说明: | 参数名 | 类型 | 说明 |
|---|
| errMsg | String | 调用结果 | | code | String | 用户允许登录后,回调内容会带上 code(有效期五分钟),开发者需要将 code 发送到开发者服务器后台,使用code 换取 session_key api,将 code 换成 openid 和 session_key |
示例代码:
App({
onLaunch: function() {
wx.login({
success: function(res) {
if (res.code) {
wx.request({
url: ',
data: {
code: res.code
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
});
}
})
code 换取 session_key 这是一个 HTTP 接口,开发者服务器使用登录凭证 code 获取 session_key 和 openid。其中 session_key 是对用户数据进行加密签名的密钥。为了自身应用安全,session_key 不应该在网络上传输。 接口地址:
请求参数: | 参数 | 必填 | 说明 |
|---|
| appid | 是 | 小程序唯一标识 | | secret | 是 | 小程序的 app secret | | js_code | 是 | 登录时获取的 code | | grant_type | 是 | 填写为 authorization_code |
返回参数: | 参数 | 说明 |
|---|
| openid | 用户唯一标识 | | session_key | 会话密钥 | | expires_in | 会话有效期, 以秒为单位, 例如2592000代表会话有效期为30天 |
返回说明:
{
"openid": "OPENID",
"session_key": "SESSIONKEY"
"expires_in": 2592000
}
{
"errcode": 40029,
"errmsg": "invalid code"
}
|