# API 支持列表

API 的支持情况在原子接口环境与原子组件环境下有所不同,以下从新增 API 和原有 API 两个维度分别列出所有支持的 API。

# 新增 API

小程序 AI 开发模式下新增的 API 都在 wx.modelContext 命名空间下。

原子接口支持的如下:

  1. 创建 Skill:wx.modelContext.createSkill(skillPath: string)
    • 注册原子接口:skill.registerAPI('name', handler)
    • 注册中间件:skill.use(Middleware)
  2. 获取会话 ID:wx.modelContext.getSessionId()
  3. 设置所有组件过期:wx.modelContext.expireAllCards({ componentPaths, match })

原子组件支持的如下:

  1. 半联小程序页面:wx.modelContext.getViewContext(this).setRelatedPage({ path, query })
  2. 上行消息:wx.modelContext.getContext().sendFollowUpMessage()
  3. 半屏页面:
    • 打开半屏页面:wx.modelContext.getViewContext(this).openDetailPage({ url })
    • 预加载半屏页面:wx.modelContext.getViewContext(this).preloadDetailPage({ url })
  4. 原子组件过期态:
    • 设置所有组件过期:wx.modelContext.expireAllCards({ componentPaths, match })
    • 设置之前的组件过期:wx.modelContext.getViewContext(this).expirePreviousCards({ componentPaths, match })
  5. 原子组件接收事件:wx.modelContext.getViewContext(this).on(NotificationType, calback)
    • 原子接口入参:wx.modelContext.NotificationType.Input
    • 原子接口出参:wx.modelContext.NotificationType.Result
    • 内容溢出事件:wx.modelContext.NotificationType.Overflow
    • 过期事件:wx.modelContext.NotificationType.Expire

# 原有 API

小程序原有部分 API 支持在小程序 AI 开发模式下调用,但原子接口与原子组件可调用的接口有所不同,支持情况如下表:

原则上,不会再提供原有的已标为废弃版本的 API

分类 API 原子接口 原子组件
登录 wx.login 支持 不支持(需声明 scope.dynamic)
wx.checkSession 支持 不支持(需声明 scope.dynamic)
网络 wx.request 支持 不支持(需声明 scope.dynamic)
wx.onNetworkWeakChange 支持 不支持
wx.onNetworkStatusChange 支持 不支持
wx.offNetworkWeakChange 支持 不支持
wx.offNetworkStatusChange 支持 不支持
wx.getNetworkType 支持 不支持
wx.getLocalIPAddress 支持 不支持
云开发 wx.cloud.init 支持 不支持
wx.cloud.callFunction 支持 不支持
wx.cloud.database 支持 不支持
位置 wx.getLocation 支持 不支持
wx.getFuzzyLocation 支持 不支持
wx.openLocation 支持 支持
wx.chooseLocation 支持 不支持
加密 wx.getUserCryptoManager 支持 不支持
系统 wx.getDeviceInfo 支持 支持
wx.getAppBaseInfo 支持 支持
数据缓存 wx.getStorage 支持 支持
wx.setStorage 支持 支持
wx.batchGetStorage 支持 支持
wx.batchSetStorage 支持 支持
wx.getStorageInfo 支持 支持
wx.removeStorage 支持 支持
wx.clearStorage 支持 支持
wx.getStorage 支持 支持
wx.setStorageSync 支持 支持
wx.getStorageSync 支持 支持
分享 wx.shareAppMessage 支持 支持(需在 tap 事件回调中调用)
手机号 wx.getPhoneNumber 支持 不支持
wx.getRealtimePhoneNumber 支持 不支持
图片视频 wx.chooseMedia 支持 不支持
wx.chooseMessageFile 支持 不支持
wx.previewMedia 不支持 支持
人脸核身 wx.startFacialRecognitionVerify 支持 不支持
wx.startFacialRecognitionVerifyAndUploadVideo 支持 不支持
微信支付 wx.requestPayment 支持 不支持
wx.requestVirtualPayment 支持 不支持
wx.verifyPaymentPassword 支持 不支持
wx.requestJointPayment 支持 不支持
wx.openPublicServicePayment 支持 不支持
wx.openBusinessView businessType=openPublicServicePayment 支持 不支持
wx.openBusinessView businessType=trafficInvestList 支持 不支持
wx.openBusinessView businessType=wxpayPapayIndex 支持 不支持
微信支付分 wx.openBusinessView businessType=wxpayScoreUse 支持 不支持
wx.openBusinessView businessType=wxpayScoreEnable 支持 不支持
订阅消息 wx.requestSubscribeMessage 支持 不支持
授权 wx.authorize 支持 不支持
设备 wx.makePhoneCall 支持 支持
wx.scanCode 支持 不支持
界面 wx.showToast 不支持 支持
wx.hideToast 不支持 支持
城市服务 wx.openBusinessView businessType=wxCityWxpayAuth 支持 不支持
地址 wx.chooseAddress 支持 不支持
设置 wx.openSetting 支持 不支持
wx.getSetting 支持 不支持
WiFi wx.stopWifi 支持 不支持
wx.startWifi 支持 不支持
wx.setWifiList 支持 不支持
wx.onWifiConnectedWithPartialInfo 支持 不支持
wx.onWifiConnected 支持 不支持
wx.onGetWifiList 支持 不支持
wx.offWifiConnectedWithPartialInfo 支持 不支持
wx.offWifiConnected 支持 不支持
wx.offGetWifiList 支持 不支持
wx.getWifiList 支持 不支持
wx.getConnectedWifi 支持 不支持
wx.connectWifi 支持 不支持
蓝牙-通用 wx.stopBluetoothDevicesDiscovery 支持 不支持
wx.startBluetoothDevicesDiscovery 支持 不支持
wx.openBluetoothAdapter 支持 不支持
wx.onBluetoothDeviceFound 支持 不支持
wx.onBluetoothAdapterStateChange 支持 不支持
wx.offBluetoothDeviceFound 支持 不支持
wx.offBluetoothAdapterStateChange 支持 不支持
wx.makeBluetoothPair 支持 不支持
wx.isBluetoothDevicePaired 支持 不支持
wx.getConnectedBluetoothDevices 支持 不支持
wx.getBluetoothDevices 支持 不支持
wx.getBluetoothAdapterState 支持 不支持
wx.closeBluetoothAdapter 支持 不支持
低功耗蓝牙
-中心
wx.writeBLECharacteristicValue 支持 不支持
wx.setBLEMTU 支持 不支持
wx.readBLECharacteristicValue 支持 不支持
wx.onBLEMTUChange 支持 不支持
wx.onBLEConnectionStateChange 支持 不支持
wx.onBLECharacteristicValueChange 支持 不支持
wx.offBLEMTUChange 支持 不支持
wx.offBLEConnectionStateChange 支持 不支持
wx.offBLECharacteristicValueChange 支持 不支持
wx.notifyBLECharacteristicValueChange 支持 不支持
低功耗蓝牙
-外围
wx.onPeripheralConnectionStateChanged 支持 不支持
wx.offPeripheralConnectionStateChanged 支持 不支持
wx.createBLEPeripheralServer 支持 不支持
BLEPeripheralServer.writeCharacteristicValue 支持 不支持
BLEPeripheralServer.stopAdvertising 支持 不支持
BLEPeripheralServer.startAdvertising 支持 不支持
BLEPeripheralServer.removeService 支持 不支持
蓝牙-低功耗
外围设备
wx.onBLEPeripheralConnectionStateChanged 支持 不支持
wx.offBLEPeripheralConnectionStateChanged支持不支持
wx.createBLEPeripheralServer支持不支持
BLEPeripheralServer.addService支持不支持
BLEPeripheralServer.close支持不支持
BLEPeripheralServer.offCharacteristicReadRequest支持不支持
BLEPeripheralServer.offCharacteristicSubscribed支持不支持
BLEPeripheralServer.offCharacteristicUnsubscribed支持不支持
BLEPeripheralServer.offCharacteristicWriteRequest支持不支持
BLEPeripheralServer.onCharacteristicReadRequest支持不支持
BLEPeripheralServer.onCharacteristicSubscribed支持不支持
BLEPeripheralServer.onCharacteristicUnsubscribed支持不支持
BLEPeripheralServer.onCharacteristicWriteRequest支持不支持
BLEPeripheralServer.removeService支持不支持
BLEPeripheralServer.startAdvertising支持不支持
BLEPeripheralServer.stopAdvertising支持不支持
BLEPeripheralServer.writeCharacteristicValue支持不支持
WebSocket wx.sendSocketMessage 支持 不支持
wx.onSocketOpen支持不支持
wx.onSocketMessage支持不支持
wx.onSocketError支持不支持
wx.onSocketClose支持不支持
wx.connectSocket支持不支持
wx.closeSocket支持不支持
SocketTask.send支持不支持
SocketTask.onOpen支持不支持
SocketTask.onMessage支持不支持
SocketTask.onError支持不支持
SocketTask.onClose支持不支持
SocketTask.close支持不支持
mDNS wx.stopLocalServiceDiscovery 支持 不支持
wx.startLocalServiceDiscovery支持不支持
wx.onLocalServiceResolveFail支持不支持
wx.onLocalServiceLost支持不支持
wx.onLocalServiceFound支持不支持
wx.onLocalServiceDiscoveryStop支持不支持
wx.offLocalServiceResolveFail支持不支持
wx.offLocalServiceLost支持不支持
wx.offLocalServiceFound支持不支持
wx.offLocalServiceDiscoveryStop支持不支持
加速计 wx.stopAccelerometer 支持 不支持
wx.startAccelerometer支持不支持
wx.onAccelerometerChange支持不支持
wx.offAccelerometerChange支持不支持
罗盘 wx.stopCompass 支持 不支持
wx.startCompass支持不支持
wx.onCompassChange支持不支持
wx.offCompassChange支持不支持
设备方向 wx.stopDeviceMotionListening 支持 不支持
wx.startDeviceMotionListening支持不支持
wx.onDeviceMotionChange支持不支持
wx.offDeviceMotionChange支持不支持
陀螺仪 wx.stopGyroscope 支持 不支持
wx.startGyroscope支持不支持
wx.onGyroscopeChange支持不支持
wx.offGyroscopeChange支持不支持
TCP wx.createTCPSocket 支持 不支持
TCPSocket.write支持不支持
TCPSocket.onMessage支持不支持
TCPSocket.onError支持不支持
TCPSocket.onConnect支持不支持
TCPSocket.onClose支持不支持
TCPSocket.offMessage支持不支持
TCPSocket.offError支持不支持
TCPSocket.offConnect支持不支持
TCPSocket.offClose支持不支持
TCPSocket.connect支持不支持
TCPSocket.close支持不支持
TCPSocket.bindWifi支持不支持
TCPSocket.setTimeout支持不支持
TCPSocket.setNoDelay支持不支持
UDP wx.createUDPSocket 支持 不支持
UDPSocket.write支持不支持
UDPSocket.setTTL支持不支持
UDPSocket.onMessage支持不支持
UDPSocket.onListening支持不支持
UDPSocket.onError支持不支持
UDPSocket.onClose支持不支持
UDPSocket.offMessage支持不支持
UDPSocket.offListening支持不支持
UDPSocket.offError支持不支持
UDPSocket.offClose支持不支持
UDPSocket.close支持不支持
UDPSocket.bind支持不支持
UDPSocket.addMembership支持不支持
UDPSocket.dropMembership支持不支持
上传 wx.uploadFile 支持 不支持
下载 wx.downloadFile 支持 支持
文件 wx.openDocument 支持 支持
图片 wx.saveImageToPhotosAlbum 支持 不支持
wx.previewImage支持支持
地图 MapContext.fromScreenLocation 不支持 支持
MapContext.getMapProperties 不支持 支持
MapContext.initMarkerCluster 不支持 支持
MapContext.moveAlong 不支持 支持
MapContext.moveToLocation 不支持 支持
MapContext.openMapApp 不支持 支持
MapContext.removeMarkers 不支持 支持
MapContext.setLocMarkerIcon 不支持 支持
MapContext.addMarkers 不支持 支持
MapContext.addVisualLayer 不支持 支持
MapContext.executeVisualLayerCommand 不支持 支持
MapContext.getRegion 不支持 支持
MapContext.getScale 不支持 支持
MapContext.includePoints 不支持 支持
MapContext.removeVisualLayer 不支持 支持
MapContext.setBoundary 不支持 支持
MapContext.setCenterOffset 不支持 支持
MapContext.setLocMarkerIcon 不支持 支持
MapContext.toScreenLocation 不支持 支持
MapContext.translateMarker 不支持 支持
MapContext.updateGroundOverlay 不支持 支持
微信运动 wx.getWeRunData 支持 不支持
发票 wx.chooseInvoiceTitle 支持 不支持
wx.chooseInvoice 支持 不支持
账号信息 wx.getAccountInfoSync 支持 支持