function
verify_market_in_app($signed_data, $signature, $public_key_base64)
{
$key =
"-----BEGIN PUBLIC KEY-----\n"
.
chunk_split($public_key_base64, 64,
"\n"
).
'-----END PUBLIC KEY-----'
;
//using PHP to create an RSA key
$key = openssl_get_publickey($key);
//$signature should be in binary format, but it comes as BASE64.
//So, I'll convert it.
$signature = base64_decode($signature);
//using PHP's native support to verify the signature
$result = openssl_verify(
$signed_data,
$signature,
$key,
OPENSSL_ALGO_SHA1);
if
(0 === $result)
{
return
false
;
}
else
if
(1 !== $result)
{
return
false
;
}
else
{
return
true
;
}
}
$signed_data는 구글이 결제시 내려주는 결제정보, 즉 영수증
$signature 는 위에 $signed_data 영수증을 RSA방식으로 암호화한 영수증
$public_key_base64는 구글에서 앱마다 제공해주는 라이센스 키
ex))
$public_key_base64 = "G9w0BAQEFAAOCAQ8AMIIBCgKCAQEAonHQLAJmy6sycCiy7ftSKioyW/GYzXS4N2SMxvB0xZ2q1utGuX2lqYfcAJaQdzCM8rlYxlkPfx8DNXL7BBjWpaN+yYyJ1j5ZSAwCEJw5TTA/MqWAAxzaIcIvx3t5ysJMmGdwC+cQZinTopNttdQfUWyk+1enkx5UQjozQtRPDBQtNY+sfomfxJCQRkiuHfWxKe3zw7B624E02yFe/2m3y6KxjhJY5LtVEo302bdMqbaSaYVcBly0toVyhIAbM3V9b6S0KvaMFbGT/h8J01471Hs5U0oIfgvawWBk3kQdrgHsnx7M4cH5II8JI+ao++xiKOhp6iLnxm9dZT0MxqkqYwIDAQAB";
$signature = "Yq+NuzvaXb+ZFdk9Dwnrpch7DUtLQ1+1vnQPdaSEFCis9Zy14iu/C0QEApKvf8UV96o2Ih7nNQ8Cm0kMCY1RRs8mlHYiGJhTKtzvIxsG2B3lVhuCK1jPsTSwm2hvS7TH0/VIv9vaVDycTmteXiPIwg4mtjn5xKfPCgswvly7GFRMOGYBZh2/5NfBYV1xJbEdKonu9W8zi90UfBlPvSgHV6HlmXK2sd87ctVQjoL3NANXjC3YIYDrIxmw6s140icBDOZyPmm/9TosG2U6QgWgwNfAxhC0swQB4RgaPjX77Dy1S9TGBiiBHYVrMny5gsRg==";
$signed_data = '{"orderId":"129997631705758.138922","packageName":"kr.co.test","productId":"test_1","purchaseTime":1383572649564,
"purchaseState":0,"purchaseToken":"ghdbrltdfqgjiecsvpxslgew.AO-zlqko8XNIyCtgUk5SVFiNgP-vbNvcPv1SyTNSQdvCx1b7RQZvi3M6es3ZzpNSA-_LcBJK3SxONU7vL29juFQ6782BX9DrckuY-oLVjTpA7T7"}';
미리 정리는 하지만 맞는건지 모르겠음;
출처 : http://bbung224.blogspot.kr/2013/08/android-in-app-billing-server-side.html
본글과 댓글로 조합해봄 또 찾아야겠음
참조 : http://ideaargo.phps.kr/tc/182
'공부' 카테고리의 다른 글
mysql replication (0) | 2015.02.25 |
---|---|
curl 잠시 주의 (0) | 2015.02.09 |
linux 계정 비밀번호 변경 (0) | 2014.12.24 |
mysql rand (0) | 2014.12.18 |
오랜만에찾은 mysql query case 문 (0) | 2014.10.31 |