Thứ Ba, 15 tháng 11, 2011

Verify transaction Receipt (Server, python)

#!/usr/bin/env python

import sys
import json
import base64
import urllib2

liveURL = 'https://buy.itunes.apple.com/verifyReceipt'
sandboxURL = 'https://sandbox.itunes.apple.com/verifyReceipt'
URL = sandboxURL

def main():
if len(sys.argv) < 2:
print 'USAGE: verifyReceipt RECEIPT'
sys.exit()

with open(sys.argv[1]) as f:
verifyReceipt(f.read())

def verifyReceipt(receipt):
receiptData = base64.b64encode(receipt)
jsonData = json.dumps({'receipt-data': receiptData})

s = urllib2.urlopen(URL, jsonData)
responseData = s.read()
s.close()

responseJSON = json.loads(responseData)
print json.dumps(responseJSON, sort_keys=True, indent=4)
stattus =
responseJSON.get_data("status","unknown")


if __name__ == '__main__':
main()

Không có nhận xét nào:

Đăng nhận xét