티스토리 뷰

 

/* recept
	{
    	"Store":"AppleAppStore",
        "TransactionID":"1000000629303951",
        "Payload":"MIIT+QYJKoZIhvBFja19....BkpGkqEZQbQ8l8fNdoKPFRDc="
    }
*/
function IOSInappPurchaseVerify($recept_from_appstore)
{
	$json = array();
	$json["error_code"] = 0;
	$json["error_message"] = "success";
	$json["order_id"] = "";
	$json["product_id"] = "";
	$json["purchase_date"] = 0;
	$json["user_seq"] = 0;
	$json["char_num"] = 0;
	$json["currency_code"] = "";
	$json["price_amount"] = 0;

	$url = "https://sandbox.itunes.apple.com/verifyReceipt"
	$post_data = json_encode(array("receipt-data" => $recept_from_appstore));

	$curl = curl_init($url); 
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
	curl_setopt($curl, CURLOPT_POST, true); 
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);

	$response = curl_exec($curl);
	$errno    = curl_errno($curl);
	$errmsg   = curl_error($curl);

	curl_close($curl);

	$result = (object)json_decode($response);

	$json["order_id"] = $result->receipt->in_app[0]->transaction_id;
	$json["product_id"] = $result->receipt->in_app[0]->product_id;
	$json["purchase_date"] = $result->receipt->in_app[0]->purchase_date;
	
	return $json;
}
function GoogleInappPurchaseVerify($receipt, $signature)
{
	$json = array();
	$json["error_code"] = 0;
	$json["error_message"] = "success";
	$json["order_id"] = "";
	$json["product_id"] = "";
	$json["purchase_date"] = 0;
	
	$google_play_key = "MIIBIjANBgkqhkiG9....pA/mCVpBPr7QIDAQAB";
	$public_key = 
	"-----BEGIN PUBLIC KEY-----\n". 
	chunk_split($google_play_key, 64, "\n"). 
	'-----END PUBLIC KEY-----';

	$key = openssl_get_publickey($public_key);
	$decoded_signature = base64_decode($signature);
	$result = json_decode($receipt);

	if(1 != openssl_verify($receipt, $decoded_signature, $key, OPENSSL_ALGO_SHA1 ))
	{
		throw new Exception("fail to verification", 1);
	}
    
	$json["order_id"] = $result->orderId;
	$json["product_id"] = $result->productId;
	$json["purchase_date"] = $result->purchaseTime;

	return $json;
}
댓글
댓글쓰기 폼