[Android] Google IAP unmaneged Items Server Checksum

Source: Internet
Author: User
Tags oauth

Android IAP unmaneged Items Server Checksum

When the IAP is successful, the status of this purchase is recorded on Google server. You can request this status via the Google Play Android Developer API to complete the checksum and send the player the appropriate props.

1> client String, ORDERID (Order ID), productId (purchase item name), PackageName (app package name), Purchasetoken (token, unique value), this 4 string is required for verification, and passed to the server.

2> calls the Google Play Android Developer API (https://developers.google.com/android-publisher/api_usage) requires the use of OAuth2.0, Can be used in Java, Python,. Net, Ruby, PHP, etc. (https://developers.google.com/identity/protocols/OAuth2WebServer)

This article uses Python implementations.

3> setting up the environment

Enable Google Play Android Developer API interface in console.developers.google.com

Set API permissions in play.google.com, OAuth client project Settings

4> Script Implementation

    

Import httplib2import pprintimport sysimport timeimport osimport mysqldblist_bill=[]from apiclient.discovery Import Buildfrom oauth2client.client Import signedjwtassertioncredentialsdef Main (argv): # Connect the db to get billdb= MySQLdb.connect ("localhost", "root", "pass", Sys.argv[1]) cursor=db.cursor () try:# Query the string Cursor.callproc from the client (' Getbill ', (' 2 ')) Results=cursor.fetchall () while (Cursor.nextset ()):p rint "111111111111" for result in results:# Load the Key in PKCS \ Downloaded from the Google api# Console when you created your Service account.f = file (' Con The path of P12 key in Sole ', ' 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,# are the Email address created for the service account. The It must is the email# address associated with the key is created.credentials = Signedjwtassertioncredentials (' PLAY.G Oogle.com OAuth Authorized Account ', key,scope= ' Https://www.googleApis.com/auth/androidpublisher ') http = httplib2. HTTP () http = credentials.authorize (http) #service Buildservice = Build ("Androidpublisher", "V2", Http=http) #get Billlist_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 BILLCURSOR.CALLPROC (# SQL processing code while (Cursor.nextset ()):p rint "111111111111" Db.commit () continuepprint.pprint (lists) # to determine if it is legal and not consumed if (lists[' Purchasestate ']==0 and lists[' consumptionstate ']==0):d iff=time.time ()-float (lists[' Purchasetimemillis '][0:10]) if (diff>2592000): #over time Bill, the record the Logcursor.callproc (# SQL processing code) while (Cursor.nextset ()):p rint " 111111111111 "Db.commit () Continueelse: #good receiptnum=product_id.split ('. ') [3]cursor.callproc (' Check_bill ', (Result[0],1,num,time.time (), ", transaction_id)) while (Cursor.nextset ())):p rint "111111111111" Db.commit () continue# has consumed elif (lists[' purchasestate ']==0 and lists[' Consumptionstate ']==1): Cursor.callproc (# SQL processing code) while (Cursor.nextset ()):p rint "111111111111" Db.commit () print "already consumed" continueexcept:# SQL Get is wrongprint "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")):p rint "Stop" Breakelse:main (SYS.ARGV) time.sleep (2)

  

      

[Android] Google IAP unmaneged Items Server Checksum

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.