$verifier_keys = '{"keys":[{"keyId":3335741209,"pem":"-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE+nzvoGqvDeB9+SzE6igTl7TyK4JB\nbglwir9oTcQta8NuG26ZpZFxt+F2NDk7asTE6/2Yc8i1ATcGIqtuS5hv0Q==\n-----END PUBLIC KEY-----","base64":"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE+nzvoGqvDeB9+SzE6igTl7TyK4JBbglwir9oTcQta8NuG26ZpZFxt+F2NDk7asTE6/2Yc8i1ATcGIqtuS5hv0Q=="}]}';
$query_string = '';
$verifier_keys_arr = json_decode($verifier_keys, true);
if(empty($verifier_keys_arr) || !is_array($verifier_keys_arr)){
throw new Exception("wrong google public keys!");
}
$publicKey_pem = $verifier_keys_arr['keys'][0]['pem'];
$publicKey_base64 = $verifier_keys_arr['keys'][0]['base64'];
$publicKeyString = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($publicKey_base64, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
$publicKey = openssl_pkey_get_public($publicKeyString);
parse_str($query_string, $query_arr);
$signature = trim($query_arr['signature']);
$signature = str_replace(['-', '_'], ['+', '/'], $signature);
$signature .= '===';
$message = substr($query_string, 0, strpos($query_string, 'signature')-1);
$return = [
'code' => 0,
'message' => 'error'
];
$success = openssl_verify($message, base64_decode($signature), $publicKey, OPENSSL_ALGO_SHA256);
if ($success === -1) {
$return['message'] = '111111'.openssl_error_string();
} elseif ($success === 1) {
$return['code'] = 1;
$return['message'] = 'success';
} else {
$return['message'] = '222222'.openssl_error_string();
}
var_dump($return);