您的位置:首页 > 其它

请支付谷歌支付服务器上检查

2015-01-28 17:52 85 查看
http://translate.google.com.tw/translate?hl=zh-CN&sl=ru&u=http://habrahabr.ru/post/240447/&prev=search

我想分享与支付从谷歌播放服务器应用程序检查连接的体验。

所以. 我们有一个应用程序准备出版( 链接 )。 同一组的付款项目(的链路 ),并与该应用程序相关联。



接下来,逐点。

1.有必要去标签凭证;

2.创建客户端ID作为网络应用程序,并指定redirect_uri到我们的服务器(例如, server.ru和回调server.ru/callback );

3.创建密钥类型ServerKey(可以是空的和数据)。



在服务器上,做传入变量处理程序代码server.ru/callback

它会作为一个GET请求。

下面是处理语言的例子Python的存储数据的萝卜

import requests, redis Redis = redis.Redis() data = requests.post('https://accounts.google.com/o/oauth2/token',{'code':code,'grant_type':'authorization_code','client_id':client_id,'client_secret':client_secret,'redirect_uri':'http://server.ru/callback/'}) jdata = data.json() if 'access_token' in jdata and 'token_type' in jdata and 'expires_in' in jdata: Redis.setex('GooglePayAccess',jdata['access_token'],jdata['expires_in']) Redis.setex('GooglePayType',jdata['token_type'],jdata['expires_in']) if "refresh_token" in jdata: Redis.set('GooglePayRefresh',jdata['refresh_token'])
[/code]

接下来,你需要填写页面«同意屏»,以及激活API«谷歌的Andr​​oid游戏开发者API»。

现在,您需要在我们的服务器上的授权服务。

可以肯定,这必须从该帐户,这是与支付项目创建完成。

那么这个帐户下去的链接 ,取代....... 我们的ClientID。

[code]https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=http://server.ru/callback/&client_id=……………………………………
[/code]

此链接只发送给我们的回调变量的代码。

一旦您的帐户能够与支付操作。

收到付款Peredaёm服务器数据由客户端从谷歌,并与他的手检查。

[code]import requests, redis Redis = redis.Redis() access_token = Redis.get('GooglePayAccess') token_type = Redis.get('GooglePayType') if not access_token or not token_type: refresh_token = Redis.get('GooglePayRefresh') data = requests.post('https://accounts.google.com/o/oauth2/token',{'grant_type':'refresh_token','client_id':client_id,'client_secret':client_secret,'refresh_token':refresh_token}) jdata = data.json() if 'access_token' in jdata and 'token_type' in jdata and 'expires_in' in jdata: access_token = jdata['access_token'] token_type = jdata['token_type'] Redis.setex('GooglePayAccess',access_token,jdata['expires_in']) Redis.set('GooglePayType',token_type,jdata['expires_in']) url = 'https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/products/%s/tokens/%s?key=%s' % (packageName,productId,purchaseToken,api_key) response = requests.get(url,headers={"Authorization":"%s %s" % (token_type,access_token)}) jdata2 = response.json()
[/code]

如果从客户端数据与谷歌的数据一致拍摄,你可以放心地收取用户的虚拟货币。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: