一、前言
集成google支付,需要后臺確認訂單等操作,會用到Google Play Developer API中的接口。這些接口不能直接調用,需要做配置
二、具體配置
1.開發(fā)者帳號與 Google Cloud 項目相關聯(lián)

- 關聯(lián)的 Google Cloud 項目啟用 Google Play Developer API。
3.在 Google Cloud開啟OAuth同意屏幕,創(chuàng)建一個web憑據(jù),創(chuàng)建完成后獲得client_id,client_secrert,redirect_uri

image.png

image.png
4.獲取調用Developer API接口的token (官方文檔)
- 生成Authorization Code
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri={創(chuàng)建web憑據(jù)中的重定向地址}&client_id={創(chuàng)建的憑據(jù)的clientId} - 把上面地址放入瀏覽器,授權獲取code,下面返回的code后面之就是需要的,將此參數(shù)進行urldecode
https://developers.google.com/?code=4%FSOFAGDB323_4324l_777777&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fandroidpublisher - 獲取refresh_token和access_token
post請求:https://accounts.google.com/o/oauth2/token
參數(shù)
grant_type=authorization_code
code=上一步獲取的code,記得進行urldecode
client_id=Google Cloud 創(chuàng)建的憑據(jù)Id Client ID
client_secret=Google Cloud 創(chuàng)建的憑據(jù)密鑰Client secret
redirect_uri=創(chuàng)建web憑據(jù)中的重定向地址
access_type=offline
執(zhí)行完成,會返回一下數(shù)據(jù)

- 刷新token,上面返回的access_token,會過期,expires_in字段就是過期時間,后臺需要自己處理刷新token邏輯,刷新token如下

-
到這里獲得access_token就可以請求Google Play Developer API中的接口了
如確認訂閱商品

