微信api

微信api

界面

Object wx.getSystemInfoSync()

获取系统信息

screenWidth	number	屏幕宽度,单位px	
screenHeight	number	屏幕高度,单位px	
windowWidth	number	可使用窗口宽度,单位px	
windowHeight	number	可使用窗口高度,单位px	
statusBarHeight	number	状态栏的高度,单位px
safeArea	Object	在竖屏正方向下的安全区域

网络

wx.request(Object object)

发起 HTTPS 网络请求

属性	类型	默认值	必填	说明	最低版本
url	string	是	开发者服务器接口地址	
data	string/object/ArrayBuffer	否	请求的参数	
header	Object	否	设置请求的 header,header 中不能设置 Referer。
content-type 默认为 application/json	
method	string	GETHTTP 请求方法	
 wx.request({
      url:url,
      method:option.method||"GET",
      data:option.data,
      header,
      success(res){ //请求成功
        resolve(res.data)
      },fail(err){ //请求失败
        wx.showToast({title:"加载失败",icon:"none"})
        reject(err);
      },
      complate(){//接口调用结束的回调函数(调用成功、失败都会执行)	
        wx.hideToast()
      }
    })

wx.downloadFile(Object object)

下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径 (本地路径),单次下载允许的最大文件为 200MB。

 wx.downloadFile({
      url: this.data.pic,//下载资源的 url
      success(res) {
        console.log(res);
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success() {
            wx.showToast({
              title: '下载图片成功',
              icon: "none"
            })
          }
        })
      }
    })

wx.uploadFile(Object object)

将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-typemultipart/form-data

  wx.uploadFile({
          filePath: tempFile,
          name: 'file',
          url: 'http://dida100.com/ajax/file.php',
          success: res => {
            console.log(res);
            var data = JSON.parse(res.data);
            that.setData({
              pic: "http://dida100.com" + data.pic
            })
          }
        })

wx.chooseMedia(Object object)

拍摄或从手机相册中选择图片或视频。

wx.chooseMedia({
  count: 9,
  mediaType: ['image','video'],
  sourceType: ['album', 'camera'],
  maxDuration: 30,
  camera: 'back',
  success(res) {
    console.log(res.tempFiles.tempFilePath)
    console.log(res.tempFiles.size)
  }
})

wx.saveImageToPhotosAlbum(Object object)

保存图片到系统相册。

wx.saveImageToPhotosAlbum({
  success(res) { }
})

界面

wx.showToast(Object object)

显示消息提示框

wx.showToast({
  title: '成功',
  icon: 'success',
  duration: 2000
})

wx.showModal(Object object)

显示模态对话框

wx.showModal({
       title:"需要观看广告才能解锁",
       content:"每天使用2次"
     })

wx.showLoading(Object object)

显示 loading 提示框

wx.showLoading({
     title:"加载中。。。"
     })

wx.setBackgroundTextStyle(Object object)

动态设置下拉背景字体、loading 图的样式

wx.setBackgroundTextStyle({
  textStyle: 'dark' // 下拉背景字体、loading 图的样式为dark
})

wx.setBackgroundColor(Object object)

动态设置窗口的背景色

wx.setBackgroundColor({
  backgroundColor: '#ffffff', // 窗口的背景色为白色
})

wx.setBackgroundColor({
  backgroundColorTop: '#ffffff', // 顶部窗口的背景色为白色
  backgroundColorBottom: '#ffffff', // 底部窗口的背景色为白色
})

wx. getUserProfile(Object object)

获取用户信息。页面产生点击事件(例如 button 上 bindtap 的回调中)后才可调用,每次请求都会弹出授权窗口,用户同意后返回 userInfo。该接口用于替换 wx.getUserInfo

getUser(){
    var that = this;
    wx.getUserProfile({
      desc: '需要获取您的昵称',
      success:res=>{
        console.log(res);
        that.setData({"userInfo":res.userInfo})
        wx.setStorageSync('userInfo',res.userInfo)
      }
    })
  },

posted @   aureazjl  阅读(93)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示