[Android] Google IAP unmaneged items服务器校验
android IAP unmaneged items 服务器校验
当成功IAP以后, 会在google服务器记录此次购买的状态. 可以通过Google Play Android Developer API去请求此状态, 从而完成校验和发给玩家相应的道具.
1> 客户端字串, orderId(订单ID), productId(购买道具名), packageName(APP包名), purchaseToken(token, 唯一值), 此4个串是校验需要用到的, 传给服务器.
2> 调用Google Play Android Developer API(https://developers.google.com/android-publisher/api_usage) 需要使用OAuth2.0, 可以采用Java, Python, .Net, Ruby, PHP等(https://developers.google.com/identity/protocols/OAuth2WebServer)
本文使用python实现.
3> 设置环境
在console.developers.google.com启用Google Play Android Developer API接口
在play.google.com中设置API权限, OAUTH客户端项目设置
4> 脚本实现
import httplib2
import pprint
import sys
import time
import os
import MySQLdb list_bill=[]
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials def main(argv):
# connect the db to get bill
db=MySQLdb.connect("localhost","root","pass",sys.argv[1])
cursor=db.cursor()
try:
# 查询客户端传来的字串
cursor.callproc('getbill',('2'))
results=cursor.fetchall()
while(cursor.nextset()):
print "111111111111"
for result in results:
# Load the key in PKCS 12 format that you downloaded from the Google API
# Console when you created your Service account.
f = file('console中的p12 key的路径', 'rb')
key = f.read()
f.close() # Create an httplib2.Http object to handle our HTTP requests and authorize it
# with the Credentials. Note that the first parameter, service_account_name,
# is the Email address created for the Service account. It must be the email
# address associated with the key that was created.
credentials = SignedJwtAssertionCredentials(
'play.google.com中OAUTH授权账号',
key,
scope='https://www.googleapis.com/auth/androidpublisher')
http = httplib2.Http()
http = credentials.authorize(http)
#service build
service = build("androidpublisher", "v2", http=http) #get bill
list_bill=result[4].split(' ')
transaction_id=list_bill[0]
product_id=list_bill[1]
packagename=list_bill[2]
token=list_bill[3]
try:
print "try to get"
lists = service.purchases().products().get(packageName=packagename,productId=product_id,token=token).execute(http=http)
except:
# bill is missing or invalid bill
cursor.callproc(# sql处理代码)
while(cursor.nextset()):
print "111111111111"
db.commit()
continue pprint.pprint(lists)
# 判断是否是合法且未消费
if(lists['purchaseState']==0 and lists['consumptionState']==0):
diff=time.time()-float(lists['purchaseTimeMillis'][0:10])
if(diff>2592000):
#over time bill, record the log
cursor.callproc(# sql处理代码)
while(cursor.nextset()):
print "111111111111"
db.commit()
continue
else:
#good receipt
num=product_id.split('.')[3]
cursor.callproc('check_bill',(result[0],1,num,time.time(),'',transaction_id))
while(cursor.nextset()):
print "111111111111"
db.commit()
continue
# 已消费
elif(lists['purchaseState']==0 and lists['consumptionState']==1):
cursor.callproc(# sql处理代码)
while(cursor.nextset()):
print "111111111111"
db.commit()
print "Already consumed"
continue
except:
# sql get is wrong
print "sql err"
finally:
cursor.close()
db.close() if __name__ == '__main__':
while(1):
if(os.path.exists("/tmp/stop_gp_iap_check-"+sys.argv[1]+".txt")):
print "stop"
break
else:
main(sys.argv)
time.sleep(2)
[Android] Google IAP unmaneged items服务器校验的更多相关文章
- SDK接入(2)之Android Google Play内支付(in-app Billing)接入
SDK接入(2)之Android Google Play内支付(in-app Billing)接入 继上篇SDK接入(1)之Android Facebook SDK接入整理完Facebook接入流程之 ...
- Android Webview SSL 自签名安全校验解决方案
服务器证书校验主要针对 WebView 的安全问题. 在 app 中需要通过 WebView 访问 url,因为服务器采用的自签名证书,而不是 ca 认证,使用 WebView 加载 url 的时候会 ...
- 转: android之虚拟机访问tomcat服务器资源
最近在研究Android虚拟机访问tomcat服务器资源,所以找了个时间写下这篇博客和大家分享一下心得. 其实Android虚拟机访问tomcat服务器非常的简单,只要不要弄错IP地址就可以访问tom ...
- Android Google 地图 API for Android
从健康类 app Runkeeper 到游戏 app 精灵宝可梦,位置服务对现代 app 来说越来越重要. 在本文中,我们将创建一个 app,名字就叫做 City Guide.这个 app 允许用户搜 ...
- Android操作HTTP实现与服务器通信(转)
Android操作HTTP实现与服务器通信 本示例以Servlet为例,演示Android与Servlet的通信. 众所周知,Android与服务器通信通常采用HTTP通信方式和Socket通信方 ...
- Android提交数据到JavaWeb服务器实现登录
之前学习Android提交数据到php服务器没有成功,在看了两三个星期的视频之后,现在终于实现了与服务器的交互.虽然完成的不是PHP端的,但是在这个过程还是学到了不少东西的.现在我先来展示一下我的成果 ...
- android文件上传到服务器
package uploadDemo; import java.io.DataOutputStream;import java.io.File;import java.io.FileInputStre ...
- android上传文件到服务器
package com.spring.sky.image.upload.network; import java.io.DataOutputStream; import java.io.File; i ...
- Android google map 两点之间的距离
在Android google map中,有时候会碰到计算两地的距离,下面的辅助类就可以帮助你计算距离: public class DistanceHelper { /** Names for the ...
随机推荐
- MWeb 1.3.7 发布!增加发布到 Wordpress 等支持 MetaWeblog API 的服务,如:Wordpress 博客、新浪博客、cnblogs、oschina。
MWeb 1.3.7 版的新功能 增加发布到 Wordpress 等支持 Metaweblog API 的服务,目前经测试过的有: Wordpress 博客.新浪博客.cnblogs.oschina. ...
- css3(border-radius)边框圆角详解
传统的圆角生成方案,必须使用多张图片作为背景图案.CSS3的出现,使得我们再也不必浪费时间去制作这些图片了,只需要border-radius属性,支持浏览器IE 9.Opera 10.5.Safari ...
- Linux操作系统备份之二:通过tar拷贝分区实现Linux操作数据的在线备份
http://www.tektea.com/archives/2163.html. 在<Linux操作系统备份之一:使用LVM快照实现Linux操作系统数据的在线备份>文章中,我们介绍了使 ...
- JAVA基本类库介绍
我们曾经讲过,Java已经为编程者编制了许多类,这些类已经经过测试,基本上不存在错误,这些类都是我们编程的基础.如果不利用这些已存在的类,我们的 编程工作将变得异常复杂,所以我们应尽可能多的掌握Jav ...
- STL—Vector简介
有关C++ STL 中的vector向量的用法(代码示例) 一. 简介 Vector是一个称为向量的顺序容器(不明白顺序容器与关联容器的可以Google). 二. 特点 1. 动态(相当于一个动态数组 ...
- CF 484E - Sign on Fence
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
- OC-01 编译链接的作用
编译:检测代码的语法合法性,随后生成.o文件. 链接:把项目中所有的.out合并,生成一个可执行文件. OC编译连接过程 .m---->.o---->.out . 检测源文件的语法合法性 ...
- mssql数据库添加,修改,删除字段
通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 增加字段: alter table [表名] add 字段名 smalli ...
- angularJS——ng-bind指令与插值的区别
在AngularJS中显示模型中的数据有两种方式: 一种是使用花括号插值的方式: <p>{{text}}</p> 另一种是使用基于属性的指令,叫做ng-bind: <p ...
- Thinkphp更改子集
//规格编辑 public function standard(){ //$id = $_GET['id'];//dump($id);die; $id = 388; //根据$id 到re_goods ...