我正在升级基于谷歌的登录系统,这需要我解码谷歌提供的id_token
字符串。字符串是有效的,我可以通过以下方式对其进行解码:https://developers.google.com/wallet/digital/docs/jwtdecoder
但我希望我的服务器能在PHP中快速完成这项工作。
我发现了两个:https://github.com/firebase/php-jwt/tree/master和https://github.com/luciferous/jwt
但是我不知道如何使用PEAR包。我可以用简单的PHP脚本复制到我的服务器上,但我发现这两个包提供的文档非常有限。有人有关于如何解码这样一个字符串的示例代码吗?
任何帮助都将不胜感激。
如果我理解正确,您是在尝试用PHP脚本解码JWT吗?如果是这样的话,下面的PHP代码(取自https://developers.google.com/wallet/instant-buy/about-jwts#jwt_decoding)可以帮助您使用来自lucisious的脚本。
$mwr = array(
'iat' => $now,
'exp' => $now + 3600,
'typ' => 'google/wallet/online/masked/v2/request',
'aud' => 'Google',
'iss' => MERCHANT_ID,
'request'=> array(
'clientId' => CLIENT_ID,
'merchantName'=> MERCHANT_NAME,
'origin'=> ORIGIN,
'pay'=> array (
'estimatedTotalPrice'=> $estimated_total_price,
'currencyCode'=> $input['currencyCode'],
),
'ship'=> new stdClass(),
),
);
if (isset($input['googleTransactionId'])) {
$mwr['request']['googleTransactionId'] = $input['googleTransactionId'];
}
WalletUtil::encode_send_jwt($mwr);