我需要通过 php 服务器验证 android 购买数据,但验证总是返回 false。这是我的android代码以防购买成功:
if (result.isSuccess()) {
//TODO send purchase info to web server, should verify bill info
String postData = "purchase_data=" + purchase.getOriginalJson() + "&"
+ "signature=" + purchase.getSignature();
webView.postUrl(url, EncodingUtils.getBytes(postData, "BASE64"));
}
这是我的php代码:
$receipt = $_POST['purchase_data'];
$billInfo = json_decode($receipt,true);
$signature = $_POST['signature'];
$public_key_base64 = "my base64 public key";
$key = "-----BEGIN PUBLIC KEY-----\n".
chunk_split($public_key_base64, 64,"\n").
'-----END PUBLIC KEY-----';
$key = openssl_get_publickey($key);
$signature = base64_decode($signature);
$result = openssl_verify($billInfo, $signature, $key);
if (0 === $result) {
return false;
} else if (1 !== $result) {
return false;
} else {
return true;
}
返回的值总是假的。谁能告诉我我哪里错了?提前致谢