How to implement fingerprint login for WeChat mini program in PHP

PHPz
Release: 2023-05-31 22:42:01
Original
1415 people have browsed it

With the continuous development of WeChat mini programs, more and more users are beginning to choose WeChat mini programs to log in. In order to improve users’ login experience, WeChat mini programs began to support fingerprint login. In this article, we will introduce how to use PHP to implement fingerprint login for WeChat mini programs.

1. Understand the fingerprint login of WeChat mini programs

On the basis of WeChat mini programs, developers can use WeChat’s fingerprint recognition function to allow users to log in to WeChat mini programs through fingerprints, thereby improving The security and convenience of the login experience.

2. Preparations

Before using PHP to implement fingerprint login for WeChat mini programs, the following preparations are required:

1. Have a WeChat developer account and mini program ID .
2. Obtain the developer key in the mini program background.
3. Install PHP and fingerprint recognition library. Here we take fingerprintjs2 as an example, which can be downloaded on Github.

3. Implementation process

1. Implement fingerprint login in the mini program
Mini program side code implementation:

Call the WeChat mini program API

wx.checkIsSupportSoterAuthentication({

  success: function(e) {
    console.log(e.supportMode)
  }
Copy after login

})

2. Create fingerprint login in the background
According to the regulations of the WeChat mini program, in the background of the mini program, you need to enable fingerprint login, and Upload the fingerprint certificate. The specific operations are as follows:

In the mini program management background, select "Development-Development Settings-Fingerprint Registration" and adjust the switch to "On".

Download the certificate and decrypt it with the corresponding certificate key.

Fill in the decrypted content in the "Fingerprint Encryption Certificate" and "Fingerprint Verification Certificate" and click Save.

3. Fingerprint identification in PHP
Use the fingerprintjs2 library for fingerprint identification to achieve login verification. The specific operations are as follows:

Introduce the fingerprintjs2 library into the PHP file.

$fingerprint = file_get_contents('/path/to/fingerprint2.min.js');

$time = time();
$time = $time - ($time % 86400);

$fingerprintKey = hash_hmac('sha256', $time.'/path/to/fingerprint2.min.js', 'your_key');
file_put_contents('/path/to /fingerprint2.min.js.'.$time.'.key', $fingerprintKey);

Use fingerprintjs2 for fingerprint identification and verify the results with the background.

var fingerprint = new Fingerprint2();
fingerprint.get(function(result, components){

  var xhr = new XMLHttpRequest();
  xhr.open('POST', '/login.php', true);
  xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  xhr.onreadystatechange = function() {
      if (xhr.readyState == 4 && xhr.status == 200) {
          console.log(xhr.responseText);
      }
  };
  xhr.send('fingerprint=' + encodeURIComponent(result));
Copy after login

});

4. Summary

This article introduces the fingerprint login process of the WeChat applet and explains in detail the method of implementing the fingerprint login of the WeChat applet in PHP. Regarding the fingerprint login problem of the WeChat applet, PHP's implementation is more convenient and also improves the security of the user's login experience. If readers have other questions about fingerprint login of WeChat Mini Program, they can refer to the official documentation of WeChat Mini Program or the corresponding development forum to learn more about related technologies and applications.

The above is the detailed content of How to implement fingerprint login for WeChat mini program in PHP. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!