AI technology practice|Using Tencent Cloud Smart Eye WeChat floating layer H5 to solve the problem of scalpers grabbing tickets

Let me ask you a question first, what bad things have you encountered while traveling? Most people have experienced forgetting their ID cards, flight delays, lost luggage, car breakdowns, sudden changes in weather, or even sudden physical discomfort, etc. However, what is even worse is to find out when you arrive at your destination that you are in trouble. When it comes to "ticket scalpers", the journey is so bumpy and frustrating.

As a gray area between tourists and scenic spots, scalpers in the early days often collected large quantities of tickets in scenic spots and then resold them to tourists at higher prices. Most scenic spots now use identity verification to purchase tickets, which has alleviated the problem of ticket scalpers to a certain extent. However, it is often difficult to get tickets for some scenic spots during the peak tourist season. Scalpers will obtain the tourist ID number and name in advance, use software scripts to grab tickets from tourists who want to grab tickets, and then ask for high handling fees. On the one hand, this chaos causes tourists to spend far more than the ticket price to visit scenic spots, causing economic losses to tourists; on the other hand, whether the software to grab tickets successfully is a matter of probability, but tourists need to inform scalpers in advance of their ID number and name. Visitors' private information is exposed, posing a major security risk. From the perspective of the scenic spot, tourists spend more money to buy tickets with low ticket prices, which will also affect the image of the scenic spot in the long run and is not conducive to the long-term development of the scenic spot.

After paying attention to this issue, I discovered "WeChat Overlay H5", a face-core SaaS product, on Tencent Cloud's official website. Through the official website, I learned that it passed the three elements of liveness detection + ID card (face, ID number, name) for user authentication. It is initially assumed that this technology can solve the problem of ticket scalpers in scenic spots: if a live face verification is required when purchasing tickets, then the scalpers will not be able to successfully purchase tickets even if they obtain their ID number and name.

So I experienced its various functions through an access demo. During the access process, I also found that this technology implements a series of security measures to ensure user information security. Let’s talk about my access process. Provide reference for those who need this information.

1. Access preparation

The preparation work includes: activating the face verification service, business application, understanding the Tencent Cloud Smart Eye face verification configuration, and obtaining the cloud API key of the account. The four 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.

 

Because the Tencent Cloud WeChat floating layer H5 service not only supports authoritative database comparison, but also supports customers’ self-portraits of ID card photos, the required function combinations are: live face verification (compare the photo with the authoritative database after completing the live body detection), living person Face comparison (comparison of the photo after completing the liveness detection and the uploaded photo) and real-name verification of identity information (two elements).

 

Step Two: Business Application

After successfully activating the face verification service, enter the self-service access page . , click Create Business Process here to create a usage scenario for the business.

 

Step 3: Understand WeChat floating layer H5

WeChat Overlay H5 serves as the access channel for Tencent Cloud’s Face Core team’s “Enhanced Face Core” product. You can learn about its features in the product introduction on the official website . It is worth mentioning that in this application scenario, scalpers are equivalent to system attackers. Tencent Cloud's enhanced version of the face core body provides enhanced device security, enhanced in-vivo security, and enhanced intelligent hierarchical authentication, which can comprehensively upgrade the core body. Security capabilities, according to the official website, this product can intercept attacks such as camera hijacking and malicious injection with an accuracy of up to 99.9%.

 

Step 4: Obtain the cloud API key of the account

A personal key is required to use it, which is used to identify the accesser. On the API key management page of Tencent Cloud Access Management , you can create a new set of your own keys.
Note: The applied API key needs to be kept properly.

 

2. Access the face core body

Step 1: View the access document to understand the access process

First, check the WeChat floating layer H5 configuration process . Before accessing WeChat floating layer H5, you need to complete: 1. Register a Tencent Cloud account and authenticate your real name, 2. Successfully apply for Tencent Cloud Face ID. According to the following access sequence diagram, the entire access process only needs to call two interfaces: 1. DetectAuth obtains the core entrance URL (face core front-end entrance) and authentication identification BizToken, 2. GetDetectInfo obtains the core result.

The steps to create the core business process are explained in detail in the WeChat floating layer H5 configuration process .

According to the demo requirements, the process submitted by Izui Zhou is shown in the figure below. After passing the review, the created business process can be used through the RuleID of the authentication process in the personal account.

After passing the review, the RuleID can be obtained on the business process interface .

 

Step 2: Access the demo process

The demo process is as follows:

1. Issue a QR code to the visitor. This QR code points to the interface for calling DetectAuth by the access party.

2. The visitor uses WeChat to scan the QR code and jumps to the Core H5 page specified by the Core Url for OCR identification of the ID card. and face recognition identity verification. After the verification is completed, the access party backend interface specified by RedirectUrl to obtain the verification result is automatically called.

3. Since the Tencent Cloud WeChat floating layer H5 backend will automatically pass BizToken as a parameter into the interface specified by RedirectUrl, Therefore, the access party's interface for obtaining results can obtain the BizToken and call the GetDetectInfo interface to obtain the verification results.

 

Step 3: Quick access to the background

Based on the analysis in the second step, we only need to implement two access party back-end interfaces to complete the H5 access to Tencent Cloud WeChat floating layer. At the same time, in order to start the identity verification by scanning the QR code, we need to implement an acquisition pointer. The QR code interface of the getToken interface.

1. Quick access method

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. First, click "Online Debugging" on the WeChat floating layer H5 configuration process page, enter the API online debugging interface , fill in the necessary parameters, select the corresponding language, you can obtain the core access code, copy it directly to the local, and add the business process code appropriately. Can be used directly.

 

2.demo code

Three http interfaces are opened in the main function and are implemented as follows:

func main() {
	 http请求路径和接口名
	http.HandleFunc("/gettoken", getBizToken)
	http.HandleFunc("/redirect", getResult)
	http.HandleFunc("/getqrcode", getQRCode)
	 在IP:Port开启服务
	err := http.ListenAndServe("0.0.0.0:8881", nil)
	if err != nil {
		fmt.Println("ListenAndServe Error:", err.Error())
	}
}

The implementation of the three http interfaces is as follows:

getToken interface: Triggered by tourists scanning the QR code, the WeChat floating layer H5 backend interface DetectAuth is called to obtain the core Url for tourists to perform face authentication. The incoming parameters include the RuleID used to specify the verification process, and the RedirectUrl of the front-end interface of the ticket purchasing platform that jumps to after the verification process (the demo is another interface for obtaining verification results, outputting the tourist name and whether the verification is successful), The implementation based on Go is as follows:

func getBizToken(w http.ResponseWriter, req *http.Request) {
	cpf.HttpProfile.Endpoint = "faceid.tencentcloudapi.com"
	client, _ := faceid.NewClient(credential, "", cpf)
	//实例化一个请求对象,每个接口都会对应一个request对象
	request := faceid.NewDetectAuthRequest()

	request.RuleId = common.StringPtr("16")
	request.RedirectUrl = common.StringPtr("http://192.168.43.82:8881/redirect")

	// 返回的resp是一个DetectAuthResponse的实例,与请求对象对应
	response, err := client.DetectAuth(request)
	if _, ok := err.(*errors.TencentCloudSDKError); ok {
		fmt.Printf("An API error has returned: %s", err)
		return
	}
	if err != nil {
		panic(err)
	}
	// 输出json格式的字符串回包
	fmt.Printf("%s", response.ToJsonString())

	token := *response.Response.BizToken
	url := *response.Response.Url
	url = url + "&token=" + token
    // 直接跳转到微信浮层h5前端进行身份认证
	http.Redirect(w, req, url, 302)
}

getResult interface: Specified by RedirectUrl, visitors will automatically jump after completing the verification on the H5 page, and pass in the token and RuleID of this verification to obtain the verification results. The implementation given in Go is as follows:

func getResult(w http.ResponseWriter, req *http.Request) {
	fmt.Println(req)
	cpf.HttpProfile.Endpoint = "faceid.tencentcloudapi.com"
	client, _ := faceid.NewClient(credential, "", cpf)
	// 实例化一个请求对象,每个接口都会对应一个request对象
	request := faceid.NewGetDetectInfoEnhancedRequest()

	err := req.ParseForm()
	if err != nil {
		fmt.Println(err.Error())
	}

	token, found := req.Form["BizToken"]
	if !found {
		fmt.Println("参数解析出错")
	}

	request.BizToken = &token[0]
	request.RuleId = common.StringPtr("16")

	// 返回的resp是一个GetDetectInfoEnhancedResponse的实例,与请求对象对应
	response, err1 := client.GetDetectInfoEnhanced(request)
	if _, ok := err1.(*errors.TencentCloudSDKError); ok {
		fmt.Printf("An API error has returned: %s", err1)
		return
	}
	if err1 != nil {
		panic(err1)
	}
	// 输出json格式的字符串回包
	fmt.Printf("%s", *response.Response.Text)
}

getQRCode interface: The interface implementation code for obtaining QR code is as follows:

func getQRCode(w http.ResponseWriter, req *http.Request) {
	err1 := req.ParseForm()
	if err1 != nil {
		fmt.Println(err1.Error())
	}
	getTokenUrl, found1 := req.Form["token_url"]
	if !found1 {
		fmt.Println("token_url参数解析错误")
	}
	url := getTokenUrl[0]

	w.Header().Set("content-type", "image/png")
	w.Write(stringToQR(url))
	// 二维码内容示例:http://192.168.43.82:8881/gettoken
}

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

3. Effect display

Finally, a test environment is built 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 complete test results are finally obtained as shown in the video below.

Go to Zhihu to view the effect video: zhuanlan.zhihu.com/p/587932111

4. Access experience

After carefully reading the official website documentation, with the help of online API debugging tools, you can directly copy the core calling logic and connect it to the logic code quite smoothly. The entire demo is implemented and the experience is very good. At the same time, after many tests, it can be accurately identified with high accuracy. Coupled with a series of security solutions mentioned in the official website documents, it can be said that Tencent Cloud WeChat floating layer H5 face core can achieve the goal of purchasing scenic spot tickets. Face verification is required when voting.

おすすめ

転載: blog.csdn.net/tencentAI/article/details/128110303