Best Practices | Use Tencent Cloud Smart Eyes Face Core to Escort Integrity Examinations

Click to participate: Tencent Cloud AI user practice prize-winning submission activity!

After the outbreak of the COVID-19 epidemic in 2020, exams under the epidemic have been affected to varying degrees in various countries. "Postponement", "cancellation" and "make-up exam" have become the keywords for candidates from various countries to "rush to take the exam". In the traditional sense, offline exam work Facing a greater risk of crowd gathering, and relying heavily on the manual proctoring model, the cost of human and material resources is increasing.

What followed was the advent of a wave of online exams. From campus to workplace, especially academic exams, training and certification exams, etc. were all moved online due to the epidemic, and the demand for online exams in various industries exploded. One of the primary problems with online exams is that users require real-name identity verification from platform registration to exam login. Relying on manual verification will inevitably take up too much manpower and financial resources. So, is there a smarter way?

As a developer, I have also participated in many online training and certification exams. After some research, from the perspective of product ease of use and cost-effectiveness, I found that Tencent Cloud Smart Eye Face Kernel has mature applications in the examination field, not only It can meet the identity verification of exam users. During the exam, if you need to randomly select to check whether there are violations, it can also be combined with facial recognition and other capabilities to achieve anti-cheating management.

Next, I will describe in detail how I used Tencent Cloud Eyes’ face verification capabilities to complete user identity verification during the online exam.

1. Preparation work

The preparation work includes: activating the face verification service, business application, understanding the Tencent Cloud Huiyan face verification configuration, and obtaining the cloud API key of the account. The five steps are described in detail below:

Step one: Activate the face verification service

Let’s first enter the Tencent Cloud Huiyan face-matching console . Users who use the face-matching service for the first time need to activate the face-matching service first. Click Submit Application directly, fill in the information according to the actual situation, and submit the application.

special reminder:

1. The Internet industry and financial industry must upload business-related business qualifications.

2. Because Tencent Cloud E-Pass service not only supports authoritative database comparison, but also supports customers’ self-portraits of ID card photos, the required function combination is: live face verification (compare photos with authoritative database after completing live body detection) and identity Information real-name verification (two elements).

Step Two: Business Application

After successfully activating the face verification service, enter the self-service access page . The E-Certificate service is currently only developed for Tencent Cloud users who have completed corporate real-name authentication. Before using the service, you need to pass the corporate qualification review.

Click the Authentication Guide button to enter the Enterprise Account Authentication Guide page, and follow the guidelines to complete the real-name authentication of the enterprise account.

After the enterprise certification is completed, you can apply for a merchant ID and start the E-Certificate service.

Step 3: Understand Tencent Cloud E-Certificate Service

First, you can learn about the functions and advantages of the E-Certificate service on the product introduction page of the official website .

Step 4: Obtain the cloud API key of the account

We need a personal key. On the API key management page of Tencent Cloud Access Management , we created a new personal key. Note: The applied API key needs to be kept properly.

2. Access the E-Certificate face verification service

Step 1: View the access document and select the access method

First, check the E-Certificate access document . In the left directory column, you can see that there are three access methods for E-Certificate: E-Certificate applet access, E-Certificate applet access (uni-app) and E-Certificate applet access. Zhengtong H5 access. Among them, E-Certificate Mini Program access and E-Certificate Mini Program access (uni-app) require the support of WeChat Mini Program to realize the interaction logic between the access party’s Mini Program and eID Mini Program, while the H5 access method only requires When the access party calls the E-Certificate service interface in the background, it can get an H5 page accessible to users.

Combined with the online examination identity verification application scenario, we chose the H5-based E-Certificate service for access.

Step 2: Determine the interaction process

Looking at the E-Certificate H5 access guide , we can know that the E-Certificate H5 access method requires two interactions with the E-Certificate back-end interface, namely: obtaining the EidToken and verification URL initially, and obtaining it after the candidate completes the verification process. Verify the results. There are two ways to obtain verification results: polling and redirection. In this scenario, we choose the redirection method. The sequence diagram is as follows.

Among them, the front end of the access party is the candidate's personal WeChat, and the server end of the access party is the access logic we implemented. The entire implementation process is:

1. Issue a QR code to the candidate, which points to the interface through which the access party calls GetEidToken;

2. Candidates use WeChat to scan the QR code and jump to the H5 page specified by the Kernel Url to perform ID card OCR recognition and face recognition identity verification. After the verification is completed, the access specified by the RedirectUrl is automatically called to obtain the verification results. Square backend interface;

3. Since the redirection method of E-Certificate will automatically pass the token as a parameter to the interface specified by RedirectUrl, the accessing party's interface for obtaining the result can obtain the token and call the GetEidResult interface provided by the E-Certificate backend to obtain the verification result. .

This process can be vividly illustrated through the flow chart on the actual usage page below.

Step Three: Access Implementation

Based on the analysis in the second step, we only need to implement two access party back-end interfaces to complete access to the E-Certificate H5 method. At the same time, in order to start identity verification by scanning the QR code, we need to implement a getToken pointer. The interface of the QR code of the interface. Three interfaces are opened in the main function and are implemented as follows:

func main() {
   // http请求路径和接口名
   http.HandleFunc("/gettoken", getToken)
   http.HandleFunc("/redirect", getResult)
   http.HandleFunc("/getqrcode", getQRCode)

   // 在IP:Port开启服务
   err := http.ListenAndServe("ServerIP:Port", nil)
   if err != nil {
      fmt.Println("ListenAndServe Error:", err.Error())
   }
}

The implementation of the three http interfaces is as follows:

1. getToken interface: Triggered by the candidate, the E-Certificate backend GetEidToken is called, the core URL is obtained, and the candidate performs face recognition authentication. The implementation based on Go is as follows:

func getToken(w http.ResponseWriter, req *http.Request) {
   credential := common.NewCredential(
      "SecretId",
      "SecretKey",
   )
   cpf := profile.NewClientProfile()
   cpf.HttpProfile.Endpoint = "faceid.tencentcloudapi.com"
   client, _ := faceid.NewClient(credential, "", cpf)

   request := faceid.NewGetEidTokenRequest()

   // 装填参数
   merchantId := "MerchantId"
   redirectUrl := "http://ServerIP:Port/redirect"
   request.MerchantId = &merchantId
   request.RedirectUrl = &redirectUrl

   // 发起调用
   response, err := client.GetEidToken(request)
   if _, ok := err.(*errors.TencentCloudSDKError); ok {
      fmt.Printf("An API error has returned: %s", err)
      return
   }
   if err != nil {
      panic(err)
   }
   // 控制前端H5页面跳转
   http.Redirect(w, req, *response.Response.Url, 302)
}

2.getResult interface: RedirectUrl specifies that after the candidate completes the verification on the H5 page, the E-Certificate front-end will automatically call it and pass in the verification token to obtain the verification results. The implementation given in Go is as follows:

func getResult(w http.ResponseWriter, req *http.Request) {
   credential := common.NewCredential(
      "SecretId",
      "SecretKey",
   )

   cpf := profile.NewClientProfile()
   cpf.HttpProfile.Endpoint = "faceid.tencentcloudapi.com"
   client, _ := faceid.NewClient(credential, "", cpf)

   request := faceid.NewGetEidResultRequest()
   // 装填参数
   err := req.ParseForm()
   if err != nil {
      fmt.Println(err.Error())
   }
   token, found := req.Form["token"]
   if !found {
      fmt.Println("参数解析出错")
   }
   request.EidToken = &token[0]
   // 发起结果查询
   response, err := client.GetEidResult(request)
   if _, ok := err.(*errors.TencentCloudSDKError); ok {
      fmt.Println("An API error has returned: %s", err)
      return
   }
   if err != nil {
      panic(err)
   }
   // 获取结果信息
   code := response.Response.Text.ErrCode
   name := response.Response.Text.Name
   if *code == 0 {
      res := "认证通过,该用户是" + *name
      fmt.Println(res)
      fmt.Fprint(w, res)
   } else {
      res := "!!!认证未通过,该用户不是" + *name
      fmt.Println(res)
      fmt.Fprint(w, res)
   }
}

3. The interface implementation code for obtaining the QR code is as follows:

func getQRCode(w http.ResponseWriter, req *http.Request) {
   err1 := req.ParseForm()
   if err1 != nil {
      fmt.Println(err1.Error())
   }
   url := "http://ServerIP:Port/gettoken"
   // 设置http响应头首部行
   w.Header().Set("content-type", "image/png")
   w.Write(stringToQR(url))
}

// 字符串转二维码
func stringToQR(url string) []byte {
   res, err := qrcode.Encode(url, qrcode.Medium, 256)
   if err != nil {
      fmt.Println(err.Error())
   }
   return res
}

During the access process, we can make full use of the API interface examples in the official documents to get the calling framework code for the interface. We only need to complete our own logic in it. Here we take obtaining the E-Certificate Token as an example to explain how to use the official API call example. First, click "Get E-Certificate Token" on the E-Certificate access page to enter the interface call description page .

Then select "Click to debug" on the interface description page to enter the interface debugging interface, select the language, and copy the code. 

3. Effect display

Finally, we set up a test environment on the same network segment so that the mobile phone can access the services provided by the PC (in actual scenarios, the service can be deployed on the public network). The final complete test results are as follows: View video

Guess you like

Origin blog.csdn.net/tencentAI/article/details/126969959