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 get member information on Alipay Mini Program

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

Share

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

This article introduces the relevant knowledge of "how to get member information on Alipay Mini Program". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Through the international standard OAuth3.0 authorization mechanism, developers can get tokens in exchange for user information in the case of user authorization. After getting the authorization token of the user, the public information of the user is obtained by calling the user information sharing interface.

1.1 access conditions

Mini Program can be used by developers.

1.2 Billing mode

There is no charge.

1.3 cases

Step 1: the user enters the home page of Mini Program for the first time. If there is no business interaction, there is no need to arouse member authorization.

Step 2: when you need to access the user, confirm the authorization in the form of a pop-up box (silent authorization does not pop up). Suggestion: user authorization should be placed in the link where the relevant information of the user needs to be displayed. Please do not guide the authorization at the beginning.

Step 3: after the user confirms the authorization, you can view the member information in the member center of the Mini Program, and the authorization is completed.

two。 Access guidelines

2.1 add the "get member Information" function

Add "get membership information" to the list of features on the Mini Program details page.

2.2 the client acquires authcode

My.getAuthCode ({

Scopes: 'auth_user', / / active authorization: auth_user, silent authorization: auth_base

Success: (res) = > {

If (res.authCode) {

/ / Certification succeeded

/ / call your own server-side interface to allow the server to perform back-end authorization and authentication, and use session to solve the cross-domain problem.

My.httpRequest ({

Url: 'http://isv.com/auth', / / the url is its own service address, and its function is to take the server to the authcode to the open platform for token verification

Data: {

Authcode: res.authcode

}

Success: () = > {

/ / authorization is successful and server login is successful

}

Fail: () = > {

/ / handle errors according to your business scenario

}

});

}

}

});

2.3 the server acquires access_token

The server calls the alipay.system.oauth.token API in exchange for an authorized access token, and developers can obtain access_token and user ID through the acquired auth_code. Auth_code is used as a ticket in exchange for access_token. Each time the user authorization is completed, the auth_code in the callback address will be different. Auth_code can only be used once, and it will automatically expire if it is not used for one day. For more information, please see the document alipay.system.oauth.token. An example of java call for SDK on open platform server is as follows:

AlipayClient alipayClient = new DefaultAlipayClient ("https://openapi.alipay.com/gateway.do","app_id","your private_key", "json", "GBK", "alipay_public_key", "RSA2")

AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest ()

Request.setGrantType ("authorization_code")

Request.setCode ("4b203fe6c11548bcabd8da5bb087a83b")

Request.setRefreshToken ("201208134b203fe6c11548bcabd8da5bb087a83b")

AlipaySystemOauthTokenResponse response = alipayClient.execute (request)

If (response.isSuccess ()) {

System.out.println ("call successful")

} else {

System.out.println ("call failed")

}

If the uid&token is successfully planted into the session, you do not need to go to the authorized platform for verification every time during the validity of the session.

If the authentication fails, the reason for the failure is returned, and the authorization process needs to be redone.

Note that if it is only for authorizing or obtaining the user ID, then the authorization ends.

2.4 the server obtains the member information

If the server wants to obtain user information, you need to complete not only the above steps-the client obtains authCode and authCode for token, but also token for user information. This step requires API: alipay.user.info.share.

Note: the user information obtained by the server is stored, and the user information obtained by jsapi is used for interface display. It is not recommended to transparently transmit the user information obtained from the front end to the server. The code is exemplified by java

AlipayClient alipayClient = new DefaultAlipayClient ("https://openapi.alipay.com/gateway.do","app_id","your private_key", "json", "GBK", "alipay_public_key", "RSA2")

AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest ()

AlipayUserInfoShareResponse response = alipayClient.execute (request,accessToken)

If (response.isSuccess ()) {

System.out.println ("call successful")

} else {

System.out.println ("call failed")

}

2.5 the client obtains the member information

The user information obtained by the front end through the my.getAuthUserInfo interface is mainly used for interface display. If you want to store it in the database, please use the above step, the server-side interface calls the process to obtain user information.

My.getAuthCode ({

Scopes: 'auth_user'

Success: (res) = > {

My.getAuthUserInfo ({

Success: ({nickName, avatar}) = > {

Console.log ({nickName, avatar})

}

});

}

});

Returned fields: nickName, avatar

3. API list

Interface name description

My.getAuthCode acquires user authorization code

Alipay.system.oauth.token in exchange for an authorized access token

The alipay.user.info.share server obtains the member information

My.getAuthUserInfo client gets member information

4. Supplementary explanation

The server cannot get the member information.

Reason 1: sensitive information, such as real name, mobile phone number, document number, etc., will not be returned.

Reason 2: the API called is incorrect. Please use the interface: alipay.user.info.share

Get the member information, and the server reports isv.invalid-token invalid token

Reason 1: auth_user is required to obtain the authorization code scope

Reason 2: the API called is incorrect. Please use the interface: alipay.user.info.share

This is the end of the introduction of "how to get member Information on Alipay Mini Program". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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