SoFunction
Updated on 2025-04-10

Detailed explanation of the official face nucleicity certification of WeChat mini program

The mini program collected the user's personal information and uploaded it and said:

Hello, the functions of the mini program page involve: collecting user biometrics (face photos or videos) and other sensitive information for identity recognition or recognition.

In order to ensure users' sensitive privacy and identity information, the platform does not support this function for the time being. Please remove the relevant functions and submit again.

Then I searched for the Du Niang and needed to apply

({})

/cgi-bin/token?appid=appid&secret=secret&grant_type=client_credential

/cityservice/face/identify/getinfo?access_token=access_token

/cityservice/face/identify/getimage?access_token=access_token

First, you need to send two parameters to the applied interface: name, ID number

data: {
    openid: '',
    custName: 'Name',
    custIdCard: 'ID number',
    verifyImg: ''
  },
  /**
    * Lifecycle function-listen to page load
    */
  onLoad: function (options) {
    ({
      custName: ,
      custIdCard: 
    });
    var _this = this;
    ({
      checkAliveType: 2,
      success: function (res) {
        if ( === 0 ||  === "checkIsSupportFacialRecognition:ok") {
          //Call face recognition          _this.startface(_this.(/(^\s*)|(\s*)$/g, ""), _this.); //Identity card name, ID number          return;
        }
        ('The WeChat version is too low, and this function cannot be used for the time being. Please upgrade the latest version of WeChat')
      },
      fail: function(res){
        ('The WeChat version is too low, and this function cannot be used for the time being. Please upgrade the latest version of WeChat')
      }

    })
  },
  startface(name, idcard) {
    ('I'm in!  !  !  ');
    var _this = this;
    ({
      name: _this., //Identity card name      idCardNumber: _this., //Identity card number      success: function (res) {
        var verifyResult = ; //Certification results        //Calling the interface

        ({
          url: '/cgi-bin/token?appid=wx2cafec51ec4c2153&secret=8d3e68a5a2c702673340d72d1c7db4cc&grant_type=client_credential',
          data: {

          },
          method: 'POST',
          header: {
            'content-type': 'application/json;charset=utf-8'
          },
          success: function (res) {
            ();
            (.access_token)
            var token = .access_token;
            ({
              url: '/cityservice/face/identify/getinfo?access_token=' + .access_token,
              data: {
                verify_result: verifyResult
              },
              method: 'POST',
              header: {
                'content-type': 'application/json;charset=utf-8'
              },
              success: function (res) {
                ()
                ('I finally succeeded.  .  .  .  ')
                ({
                  url: '/cityservice/face/identify/getimage?access_token=' + token,
                  data: {
                    verify_result: verifyResult
                  },
                  method: 'POST',
                  responseType: 'arraybuffer',
                  header: {
                    'content-type': 'application/json;charset=utf-8',
                  },
                  success: (res) => {
                    // ('data:image/png;base64,'+wx.arrayBufferToBases64(res))

                    ();
                    var base64 = wx.arrayBufferToBase64();
                    _this.setData({ verifyImg:'data:image/png;base64,'+ base64})
                    ({
                      url: '../msg/msg?msg=Congratulations on your successful verification of information&verifyImg=' + _this.
                    });
                  },
                  fail: function (res) {
                    ('fail', )
                  }
                })

              },
              fail: function (res) {

              }
            })
          },
          fail: function (res) {

          }
        })



        (verifyResult)
        // ({
        // url: '../msg/msg?msg=Face nucleic authentication is successful'        // });
      },
      checkAliveType: 2, //Screen flashes (the interaction method of face verification, default 0, read number)      fail: err => {
        ('Please keep the light in full, your face is facing the phone, and there is no obstruction')
        ({
          url: '../msg/msg?msg=Please keep the light in place,Face facing the cell phone,And no obstruction,Please exit and re-operate'
        });
      }
    })
  }

The main trick is that you have to apply for the interface several times and the business needs unionid in the end, so you have to go to the WeChat open platform to apply for certification.

Then when you want to pull the image of the nucleus result, you need /cityservice/face/identify/getimage?access_token=access_token

The returned data needs to be converted into base64 code and then displayed on the image tag. I passed it directly to the background.

Here is my msg js code

const app = getApp();
Page({

  /**
    * Initial data of the page
    */
  data: {
    msg:'',
    verifyImg:'',
    url:
  },

  /**
    * Lifecycle function-listen to page load
    */
  onLoad: function (options) {
    var timestamp = (new Date());
    timestamp = timestamp/1000
    (options)
    var that = this;
    ({
      msg:,
      verifyImg:
    });
    ()
    ()
    
      ({
        url: +'fileUpload!', //For example only, non-real interface address        data: {
          file:,
          filename:timestamp,
          filedata:
        },
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
        },
        success:function (res){
          const data = 
          ('success',data);
          //do something
        },
       fail:function(res){
         ('fail',res)
       }
        
      })
  }

Upload the code for base64 conversion in the background

public void upBase64() {
         ("======Start uploading pictures====");
         (file);
        Json j = new Json();
        String FilePath = ().getRealPath(+"/"+);  
        File PathFile = new File(FilePath);
        try {
            // If it is IE, it needs to be set to text/html, otherwise the box will be downloaded            // ("text/html;charset=UTF-8");
            ("application/json;charset=UTF-8");

            String FileName = ("filename");
            String FileData = ("filedata");
            (FileName+"**************"+FileData);
            if (null == FileData || () < 50) {
                ("Upload failed, data is too short or not");
                (false);
            } else {
                // Remove unreasonable data at the beginning                FileData = (30);
                FileData = (FileData, "UTF-8");
                ("FileData="+FileData);
                byte[] data = (FileData);
                /*if (null == FileName || () < 1) {
                    FileName = () + ".jpg";
                }*/
                // Write to file                FileOutputStream outputStream = new FileOutputStream(new File(PathFile,FileName)); 
                (data); 
                (); 
                (); 
                (FileName+"**************"+FileData);
                ("Uploaded successfully");
                (true);
            }
        } catch (Exception err) {
            ("Upload failed");
            (false);
            ();
        }
        writeJson(j);
    }

The above is a detailed explanation of the detailed content of the official face nucleicity certification of WeChat mini program. For more information about the official face nucleicity certification of WeChat mini program, please follow my other related articles!