Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat program API NFC sends NFC messages


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.sendHCEMessage(Object object)

Base library 1.7.0 starts to support, and low versions need to be compatible.

Send an NFC message. Valid only under Android.

Parameters

Object object

Property Type The default Required Description
data ArrayBuffer Is Binary data
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

Error

Error code The error message Description
0 Ok Normal
13000 NFC is not supported by the current device
13001 The current device supports NFC, but the system NFC switch is not on
13002 The current device supports NFC, but not HCE
13003 The AID list parameters are in the wrong format
13004 WeChat is not set as the default NFC payment app
13005 The instructions returned are not legal
13006 Registration of the AID failed

The sample code

const buffer = new ArrayBuffer(1)
const dataView = new DataView(buffer)
dataView.setUint8(0, 0)

wx.startHCE({
  success (res) {
    wx.onHCEMessage(function(res) {
      if (res.messageType === 1) {
        wx.sendHCEMessage({data: buffer})
      }
    })
  }
})