1、控制台地址:
https://play.google.com/console/u/0/developers/https://play.google.com/console/u/0/developers/
2、API与服务地址:
https://console.cloud.google.com/apis/dashboard?project=xxxxx
一、Google PlayConsole绑定项目和API权限
前提:已创建项目
1、创建API控制台项目
2、转到API控制台并使用您的Google Play控制台帐户登录。
3、选择创建项目。
4、转到服务在左侧导航面板。
5、打开Google Play Android Developer API。
6、接受服务条款。
7、转到左侧导航面板中的API Access。
8、选择“ 创建OAuth 2.0客户端ID”。
绑定有可能找不到项目,解决如下:
地址:https://developers.google.com/android-publisher/getting_started#using_an_existing_api_project
使用现有 API 项目
如果您已是 Google Play Developer API 的用户,则可以执行以下这些步骤来关联到您现有的 API 项目。如果您想关联的 API 项目未列出,请确认您的 Google Play 管理中心帐号已指定为“所有者”,且 Google Play Developer API 已启用。
转到 Google Play 管理中心的 API 权限页面。接受《API 服务条款》。选择您想关联的项目。点击关联。红色字体开启地址如下:
绑定完的页面:
二、获取token步骤(最终目的是拿到访问令牌)
授权文档参考:https://developers.google.com/android-publisher/authorization#generating_a_refresh_token
屏幕要改成正式版(重要)(不然令牌一个星期会过期)
开始:获取client_id和client_secret登录开发账号,在API权限里面创建相应的Oauth客户端获取(OAuth 2.0 客户端 ID ->Web client -> 客户端 ID | 客户端密钥)
令牌文档说明:
第一步:获取Authorization code
1、使用您的 Google Play 管理中心帐号登录,然后浏览器直接访问以下 URI:
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=...&client_id=...
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=https://xxxx-aad8a.firebaseapp.com/__/auth/handler&client_id=77777558944-s9q7tr9jucc8g4p2rcrtnns1vhklsu5b.apps.googleusercontent.com
注意:
redirect_uri 参数必须与使用客户端 ID 注册的值完全匹配,包括末尾的反斜杠(如果有)
client_id 是开始中拿到的客户端ID
redirect_uri :“Web 应用”的客户端 ID中的已获授权的重定向 URI
2、看到系统提示时,请选择允许访问。
3、浏览器将使用 code 参数重定向到您的重定向 URI,该参数类似于 4/eWdxD7b
第二步:生成刷新令牌 refresh token
1、refresh token 很关键,是用于后端生成 access_token 的唯一凭证,生成之后必须妥善保管。这个token是一个长久有效的token,可以保存起来
2、请求:https://accounts.google.com/o/oauth2/token
设置字段:
grant_type=authorization_code
code=<the code from the previous step> 第一步获取到的code
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
redirect_uri=<the URI registered with the client ID>
成功响应:
{
"access_token" : "ya29.ZStBkRnGyZ2mUYOLgls7QVBxOg82XhBCFo8UIT5gM",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/zaaHNytlC3SEBX7F2cfrHcqJEa3KoAHYeXES6nmho"
}
第三步:根据刷新令牌获取到 访问令牌 access_token
使用上一步获取到的 refresh_token ,通过 HTTP POST 获取 access_token
HTTP POST
URL:
https:
POST BODY:
grant_type:refresh_token
client_id:OAuth 凭证中的 client_id
client_secret:OAuth 凭证中的 client_secret
refresh_token:上一步拿到的 refresh_token
第四步:获取用户支付 订单信息
接口文档:
https:
当用户在 APP 中完成支付后,前端可以从谷歌手上拿到一个 token ,该 token 上报给后端服务可以用来查询订单状态,并进行订单消费处理。
1、Checks the purchase and consumption status of an inapp item.
检查inapp项目的购买和消费状态。
2、调用接口地址:GET https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/products/{productId}/tokens/{token}
3、主要判断:
purchaseState 0. 已购买 1. 已取消 2. 待定
orderId : 谷歌订单号
其他:
1、第一步骤获取code有可能页面报错如下:
错误 403: access_denied
The developer hasn’t given you access to this app. It’s currently being tested and it hasn’t been verified by Google. If you think you should have access, contact the developer (oneisallmy@gmail.com).
翻译:错误 403:访问被拒绝
开发人员尚未授予您访问此应用程序的权限。它目前正在测试中,还没有得到谷歌的验证。如果您认为您应该有访问权限,请与开发人员联系(oneisallmy@gmail.com).
参考如下:
原因:没有增加测试用户
解决此问题视频地址:https://www.youtube.com/watch?v=x_NPvk0pk8g
2、第一步骤(获取刷新token)可能会报错如下:
{“error”: “invalid_grant”, “error_description”: “Bad Request”}
原因是因为:前一步获取code的地址没有加上access_type=offline
参考地址:invalid_grant试图从Google获取oAuth令牌
{"error_description":"Token has been expired or revoked.",
"error":"invalid_grant"}
原因:同意屏幕没有改成正式版(重要)
参考地址:
'Token has been expired or revoked' - Google OAuth2 Refresh token gets expired in a few days - Stack Overflow
3、第四步骤(获取用户支付订单信息)问题:
① 报错如下:
The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.
原因:关联项目和创建商品ID的顺序不对,先创建了商品才去关联了项目
解决:去商品列表任意创建一个商品然后删掉,从新使用postman访问。
② 确认订单问题
前端支付过程中,因为闪退等其他原因,从新打开app,只能获取到token,没有后台的order_sn,无法判断是哪一笔订单。
网上的大部分以前的博客都是使用developerPayload该字段来判断,文档意思为:包含有关订单的补充信息的开发人员指定的字符串。
但是结算库版本 3 开始,安卓apk弃用了该字段,无法设置订单号进去。
解决:安卓将后台订单号传入:需同时设值。BillingFlowParams.Builder.setObfuscatedAccountId() 和 BillingFlowParams.Builder.setObfuscatedProfileId()
Google结算库集成避坑指南博客:
Google结算库集成避坑指南_setobfuscatedaccountid-CSDN博客
为你的应用集成谷歌结算(客户端集成+服务端校验) - 代码先锋网
https://developers.google.com/api-client-library/java
https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/get
http://www.wangwenyong.com/?p=306
https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/get
谷歌Google Play内购支付后端指南 - Guozhang Wu's Blog - 吴国章的博客
谷歌支付验证 403错误 - 程序员大本营
第三方问题帮助:文档中心 | QuickSDK——专业的手游第三方SDK接入服务平台,渠道SDK聚合,广告跟踪,客服,登录充值SDK
api接口文档:https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/get
相关知识
探究华为支付,揭秘华为自研支付系统及其命名奥秘
盘点全球六大类型支付方式,你的业务适合哪一种?
花礼网鲜花APP的订单是否支持多种支付方式?
phpcms ?m=pay&c=deposit&a=pay
花礼网鲜花APP支持哪些支付方式?
快速便捷,盘点那些五花八门的手机移动支付方式
华为旗下支付公司更名花瓣支付,加速推进鸿蒙全场景支付服务建设
华为花瓣支付:鸿蒙生态的全场景支付服务,探索更多应用场景
华为支付更名花瓣支付,其发展历程及未来前景备受关注
Google的60款开源项目
网址: Google Pay 服务端配置和支付集成 https://m.huajiangbk.com/newsview849420.html
上一篇: 实现WAP调用支付宝支付功能的完 |
下一篇: SpringBoot 集成第三方 |