我想验证我的应用内购买。
我正在使用this receipt validator通过查看源代码正在调用 https://www.googleapis.com/androidpublisher/v3/applications/<appId>/purchases/products/<productId>/tokens/<token>
,这是我的代码基本上是从自述文件中复制的
$googleClient = new Google_Client();
$googleClient->setScopes([Google_Service_AndroidPublisher::ANDROIDPUBLISHER]);
$googleClient->setApplicationName('my project name');
$googleClient->setAuthConfig('files/googleauthconfig.json');
$validator = new Validator(new Google_Service_AndroidPublisher($googleClient));
try {
$response = $validator->setPackageName('my.app.id')
->setProductId('my.product.id')
->setPurchaseToken('token i got from my app when purchasing')
->validatePurchase();
} catch (Exception $e) {
var_dump($e->getMessage());
exit;
}
var_dump($response);
exit;
我已经硬编码了很多东西,因为我现在只是想让它发挥作用。 googleauthconfig.json
是开发控制台为我的服务帐户提供的 JSON 文件,其中包含该帐户的一堆 ID 以及私钥。我进入我的游戏控制台并将我的服务帐户设置为管理员,然后按照其他问题中针对同一问题的建议等待大约 24 小时。我已经配置了我的产品,这些产品是消耗品且处于事件状态,并且我使用测试信用卡通过我的签名发布应用程序成功购买了它们。
我不断收到的错误是
The current user has insufficient permissions to perform the requested operation.
最佳答案
The current user has insufficient permissions to perform the requested operation.
这意味着您正在验证的用户没有权限执行您尝试执行的操作。您正在使用服务帐户。服务帐户不是您。服务帐户已预先授权。
转到 google pay(可能是管理部分)获取服务帐户电子邮件地址并授予其访问数据的权限。您可能会像对待任何其他用户一样这样做。
正如评论中提到的,服务帐户通常需要不到一个小时的时间才能启动。在您授予其访问权限后。
可能的代码错误。
我认为你应该尝试纯代码而不是使用验证器来确保这不是问题所在。
$client = new Google_Client();
$client->setScopes([Google_Service_AndroidPublisher::ANDROIDPUBLISHER]);
$client->setApplicationName('my project name');
$client->setAuthConfig('files/googleauthconfig.json');
$service = new Google_Service_AndroidPublisher($client);
try {
$response = $service->purchases_products->get(package_name, product_id, purchase_token);
} catch (Exception $e) {
var_dump($e->getMessage());
exit;
}
var_dump($response);
exit;
关于php - 支付 API 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55843314/