背景
因为最近要引入新项目,需要介入一个新app的Google支付。所以需要配置一些信息,我看了我们之前java的代码,发现目前校验GooglePay支付参数得时候,java只需要4个信息:
1、ServiceAccountId
2、ServiceAccountPrivateKeyFromP12File
3、ApplicationName
4、GoogleAppPackageName
第3、4个信息比较好找就是app的包名和app名字。这里就略过了。
ServiceAccountId
进入谷歌云平台,https://console.cloud.google.com/ 创建项目,这里就不详细说了,略过。
选择左边的菜单-API和服务-凭据
到服务账号栏-管理服务账号,进入下图。创建服务账号,我这里创建过了,就不演示了。ServiceAccountId即为电子邮箱地址
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210618175345567.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,t
ServiceAccountPrivateKeyFromP12File
创建好服务账号以后,进入服务账号,选择密钥-创建新密钥-选择p12。创建好了以后,将p12的文件保存到服务器,然后代码里面直接获取就可以了。
踩坑
1、403:projectNotLinked。The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.
{
"error": {
"errors": [
{
"domain": "androidpublisher",
"reason": "projectNotLinked",
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
}
],
"code": 403,
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
}
}
出现403的原因是因为服务账号和app没有绑定关系导致。
解决办法:
登录https://play.google.com/console/developers谷歌的开发者平台,登录,选择设置,然后选择服务账号这一栏,看是否有自己配置的服务账号。
如果没有,检查关联的项目是否为自己刚刚创建的项目。
如果有服务账号,则授权服务账号。如果是做支付,则一定要勾选财务的模块,同时邀请账号进来,设置账号权限。即可
2、401:permissionDenied。The current user has insufficient permissions to perform the requested operation.
{
"code" : 401,
"errors" : [ {
"domain" : "androidpublisher",
"message" : "The current user has insufficient permissions to perform the requested operation.",
"reason" : "permissionDenied"
} ],
"message" : "The current user has insufficient permissions to perform the requested operation."
}
401原因是因为我解决403问题的时候,重新配置了权限。google以后发现,需要重新保存应用内产品,即可解决此问题。
在google play控制台中,选择自己的app,进入应用内,下来菜单栏,找到应用内商品,进入应用内商品-修改商品说明或者商品名称,保存。即可