hid*_*s02 8 google-api google-cloud-console google-play-integrity-api
我正在尝试在我的 Android 应用程序中实现 PlayIntegrity API,但我不知道如何使用 Google 的服务器解密和验证令牌。
到目前为止我一直遵循文档:
现在我坚持向 发出解码请求googleapis。我不明白这个指令是如何工作的。
我创建了一个服务帐户,下载了 JSON 凭证文件并将其放入我的 Laravel 项目中,然后我尝试了这段代码:
$client = new Client();
$client->setAuthConfig(storage_path('app/integrity_check_account.json'));
$client->addScope(PlayIntegrity::class);
$httpClient = $client->authorize();
$result = $httpClient->request('POST', 'https://playintegrity.googleapis.com/v1/my.package.name', [
'headers' => ['Content-Type' => 'application/json'],
'body' => "{ 'integrity_token': 'token' }"
]);
dd($result);
Run Code Online (Sandbox Code Playgroud)
所以我对这段代码有两个问题:
我花了几个小时让它与 Node js 一起工作。有时谷歌在记录/解释和检查自己的代码方面非常糟糕。
因此,我将这篇文章发布给任何正在寻找使用 Node js 服务器进行完整性解密的人。我能找到的唯一示例直接位于 googleapis 的节点 playintegrity 模块内。基于这里的示例,我的工作代码:
async function getAppToken() {
const auth = new google.auth.GoogleAuth({
keyFile: 'secret.json',
scopes: ['https://www.googleapis.com/auth/playintegrity'],
});
const authClient = await auth.getClient();
google.options({auth: authClient});
const res = await playintegrity.decodeIntegrityToken (
{
packageName: 'com.example.myapp',
requestBody:
{
"integrityToken": "myToken"
}
}
);
console.log(res.data);
return res.data;
}
Run Code Online (Sandbox Code Playgroud)
你可以像这样调用该函数
getAppToken()
.then(data => {
console.log(data);
})
.catch(e => {
console.error(e);
throw e;
});
Run Code Online (Sandbox Code Playgroud)
现在我们开始!嗯……不,等等。您还必须修复完整性 api。转到您的节点项目并在 playintegrity 模块中找到v1.js文件
它应该在这里:\node_modules\googleapis\build\src\apis\playintegrity
现在打开它并在 Playintegrity 构造函数中添加这一行
this.decodeIntegrityToken = this.v1.decodeIntegrityToken;
Run Code Online (Sandbox Code Playgroud)
为了得到那个
class Playintegrity {
constructor(options, google) {
this.context = {
_options: options || {},
google,
};
this.v1 = new Resource$V1(this.context);
this.decodeIntegrityToken = this.v1.decodeIntegrityToken;
}
}
Run Code Online (Sandbox Code Playgroud)
现在应该可以了
在查看 Google APIs Client Library for PHP 的源代码时,我终于找到了问题的PlayIntegrity API解决方案。
导入所需的依赖项后:
composer require google/apiclient:^2.12.1
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
composer require google/apiclient:^2.12.1
Run Code Online (Sandbox Code Playgroud)
此处解释了可能的返回判决。
| 归档时间: |
|
| 查看次数: |
11325 次 |
| 最近记录: |