googleplay的h5/web端支付
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://accounts.google.com/gsi/client" async defer></script> <title>Document</title> </head> <body> <div id="g_id_onload" data-client_id="xxxxxx" data-context="signin" data-ux_mode="popup" data-callback="callback" data-auto_prompt="false"> </div> <div class="g_id_signin" data-type="standard" data-shape="rectangular" data-theme="outline" data-text="signin_with" data-size="large" data-logo_alignment="left"> </div> </body> <script> function callback(e){ console.log("123213213213",e.credential) decodeJwt(e.credential) } function decodeJwt(jwt) { // 将JWT拆分为头部、有效载荷和签名 const [headerB64, payloadB64] = jwt.split('.'); // 对有效载荷进行Base64解码 const payload = JSON.parse(atob(payloadB64)); console.log(38,payload); return payload; } </script> </html>
// 解码JWT并解析用户信息
function decodeJwt(jwt) {
// 将JWT拆分为头部、有效载荷和签名
const [headerB64, payloadB64] = jwt.split('.');
// 对有效载荷进行Base64解码
const payload = JSON.parse(atob(payloadB64));
return payload;
}
// 使用GSI API获取身份凭证
google.accounts.id.initialize({
client_id: 'YOUR_CLIENT_ID',
callback: handleCredentialResponse,
});
function handleCredentialResponse(response) {
const credential = response.credential;
const idToken = credential.id_token;
// 解码JWT并解析用户信息
const userInfo = decodeJwt(idToken);
console.log(userInfo);
}
https://developers.google.com/identity/gsi/web/reference/js-reference?hl=zh-cn#credential

浙公网安备 33010602011771号