1. 程式人生 > >GooglePlay Console 後臺配置以及支付訂單驗證流程

GooglePlay Console 後臺配置以及支付訂單驗證流程


第一步 獲取code(離線code)

組合URL,如下:

https://accounts.google.com/o/oauth2/auth?
scope=https://www.googleapis.com/auth/androidpublisher&
state=123456&
redirect_uri=developers console中設定的重新導向 URI&
response_type=code&
client_id=developers console中的ClientID&
approval_prompt=force
&access_type=offline

訪問上面的URL,在彈出確認框中點選確定,跳轉到新的網頁後,複製瀏覽器的url

例如:
http://www.thisisgame.com.cn/google.php?state=123456&code=code

code= "code"

取出code:
例如:4/8qzGqVXPAHwD5CspOMoQiS6rPzTzNxJpny11q123OpQ994bs.AtydTx4yH0g234QgrKXntQA11a123x3U85XMkwI

--------------------------------------------------------------------------------------------------------------------

第二步  獲取refreshtoken(用於離線重新整理)

這裡需要執行Post操作:

URL: https://accounts.google.com/o/oauth2/token

Content Type:application/x-www-form-urlencoded

內容:
grant_type=authorization_code
code=上面獲取的code
client_id=developers console中的ClientID
client_secret=developers console中的client_secret
redirect_uri=developers console中設定的重新導向 URI

例如:
code=4/hUzPN2YhJUQtdsbbAu2wXtbQ234212334rN1560gSAiWGF7o_4mk8.8mG4R3gvGvIXEnp6123U23434APFm0G8PsbDkwI&client_id=7771985123023459487.apps.googleusercontent.com&client_secret=s9-nF4sgWJ123UM2q412323Sg-hhOXfE&redirect_uri=http://www.thisisgame.com.cn/google.php&grant_type=authorization_code


POST返回資料:
{
  "access_token" : "access_token",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "access_token"
}


檢視獲取的許可權
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29.yABr0qXqbnZqweqwerSxXu3Hh-7WR2SAtCXQi7kH5Bmu2p8Ny5Dbjw_nzaO7JV6heYKU1iDzAj4TiEmUfKRg

https://developers.google.com/oauthplayground/?code=4/08pnki23e1-n1SBwerweraNmjEWC-KjaaS9kJxCEK2bC3HBUU.4qp2DVaBI50REnp6UAPFm0E8w2DEkwI

https://security.google.com/settings/security/permissions


access Token過期後重新獲取Token
https://accounts.google.com/o/oauth2/token

application/x-www-form-urlencoded

grant_type=refresh_token&client_id=777985059487.apps.googleusercontent.com&client_secret=s9-nF4sgWJUM2q4Sg-hhOXfE&refresh_token=1/EjTL8LKlhj4UUtlafg9eWOpklG4XIwSDKUokhG0NUMA

ya29.ygA9icexU3fFqdyvPY5yoh7o_K533VsT9XmdAD4lMbepXFZ9IaoTiKOYxkk2ynGJ5HMfsBlcBVYj-g
----------------------------------------------------------------------------------------

第三步 驗證google訂單
https://www.googleapis.com/androidpublisher/v1.1/applications/packagename/inapp/商品ID/purchases/支付成功返回的purchase?access_token=access_Token

https://www.googleapis.com/androidpublisher/v1.1/applications/tw.com.joybomb.tan/inapp/tan_diamond_60/purchases/hceipdfgccjjjajbjmfanfbb.AO-J1OzYNGV09inOGzUU4gUW1QUcVAgzF2R1ETclYaC6uwSbEi90Bh4aqLCbDpUoYwu879U-g3RFeRvI7Ln5DUriT-A8M-cV6-Dp8INB39fvjbkht-8_dUbYQy8sdvm4H4PrVXJB1ZN2?access_token=ya29.ygA9icexU3fFqdyvPY5yoh7o_K533VsT9XmdAD4lMbepXFZ9IaoTiKOYxkk2ynGJ5HMfsBlcBVYj-g

驗證返回:https://developers.google.com/android-publisher/api-ref/purchases/products#resource

總結:
1、獲取AccessToken
https://developers.google.com/android-publisher/authorization

2、請求訂單狀態
https://developers.google.com/android-publisher/api-ref/purchases/products/get

3、訂單狀態返回
https://developers.google.com/android-publisher/api-ref/purchases/products#resource