Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement the login signature of Mini Program game developers

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to achieve Mini Program game development user login state signature, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe that after reading this Mini Program game development user login state signature article will have something to gain, let's take a look.

User login signature

Part of Mini Program's background (HTTP) interface requires verification of the user's login status. The developer needs to provide the signature generated with session_key as the key when calling. Where session_key refers to the login state obtained through wx.login.

Signature algorithm

At present, the signature algorithm supported is hmac_sha256. For POST requests, the developer generates a signature using the following algorithm:

Signature = hmac_sha256 (post_data, session_key)

Where post_data is the packet of this POST request. In particular, for GET requests, post_data equals a string of length 0.

Signature = hmac_sha256 ("", session_key)

Signature example

For example, the developer needs the requested HTTP (POST) interface, where the request package is a json string.

Curl-d'{"foo": "bar"}''https://api.weixin.qq.com/some_api?access_token=xxx&openid=xxx&signature=???&sig_method=hmac_sha256'

Developers need to calculate the signature parameters. Assume that the user's current valid session_key is:

'o0q0otL8aEzpcZLTFT9WsQothers

Then the developer generated signature should be

Hmac_sha256 ('{"foo": "bar"}', 'o0q0otL8aEzpcZL') = 654571f79995b2ce1e149e53c0a33dc39c0a74090db514261454e8dbe432aa0b

HTTP requests initiated by the developer server

Curl-d'{"foo": "bar"}''https://api.weixin.qq.com/some_api?access_token=xxx&openid=xxx&signature=654571f79995b2ce1e149e53c0a33dc39c0a74090db514261454e8dbe432aa0b&sig_method=hmac_sha256'

Session_key validity check

We provide an API for developers to verify whether the login state session_key saved by the server is legal. In order to maintain the privacy of session_key, the verification API provided by us does not directly explicitly text session _ key, but is done by verifying the login status signature.

Interface address

Request method: GET

Https://api.weixin.qq.com/wxa/checksession?access\_token=ACCESS\_TOKEN&signature=SIGNATURE&openid=OPENID&sig\_method=SIG\_METHOD

Invocation example

Curl-G 'https://api.weixin.qq.com/wxa/checksession?access_token=OsAoOMw4niuuVbfSxxxxxxxxxxxxxxxxxxx&signature=fefce01bfba4670c85b228e6ca2b493c90971e7c442f54fc448662eb7cd72509&openid=oGZUI0egBJY1zhBYw2KhdUfwVJJE&sig_method=hmac_sha256'

Parameter description

Parameter description is required

Access_token is the API call credential

Openid is the user's unique identifier

Signature is the login signature of the user

Sig_method is a hash method of user login signature.

Buffer is managed data with a type of string and a length of no more than 1000 bytes

Return the result

When correct, the returned JSON packet is as follows:

{"errcode": 0, "errmsg": "ok"}

The JSON packet returned in case of error is as follows (example, signature error):

{"errcode": 87009, "errmsg": "invalid signature"}

This is the end of the article on "how to achieve user login signature in Mini Program game development". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "Mini Program game development user login signature" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report