如何测试我的RESTAPI IAP认证?

时间:2017-04-27 20:51:54

标签: java php android

我正在进行应用内购买,并进行了设置。我创建了一个脚本,应该用谷歌验证购买(在我的服务器上)。然而,我无法测试它。

这是我的服务器代码:

<?PHP

$username = $_GET["username"];
$public_key_base64 = $_GET["base64key"];
$signed_data = $_GET["signeddata"];
$signature = $_GET["signature"];

if(!is_string($username)){
    echo "Username is not a string!";
    return;
}

$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){
    echo "purchase denied";
    return;
}
elseif(1 !== $result){
    echo "purchase denied";
    return;
}
else{
    echo "purchase accepted";
    return;
}

?>

这是我的java代码:

String result = RestAPI.getResponse("http://hg1.flarehubpe.com/purchasemanager.php?username=" + this.playername + "&" + "base64key=" + FlareHubVIPProperties.BASE_64_KEY + "&signeddata=" + base64encodedJson + "&signature=" + this.info.getSignature());

每次我使用SKU android.test.purchased测试时,我都会收到失败的购买拒绝回复。我能做错什么?是否有可能android.test.purchased不支持RESTAPI顶点化?

0 个答案:

没有答案