【问题标题】:How Confirm in-app Billing Info with Google Play Market如何通过 Google Play Market 确认应用内结算信息
【发布时间】:2012-04-26 11:39:23
【问题描述】:

我正在制作一个包含计费的应用程序。我有采购工作。

应用程序链接到 PHP 服务器。我想将应用内购买信息保存在我的服务器上并使用 Google Play Market 确认。

我已设法将应用内购买信息保存在我的服务器上,但我无法通过 Google Play Market 确认。

我曾尝试使用this 库,但我看到的只是:

“此库(尚)不支持验证通过 Google Play 的应用内结算进行的购买。”

我想做的事可能吗?如果有,怎么做?

这是我的 PHP:

$signedData = $request['signedData'];
$signature = $request['signature'];

$signedData = str_replace('\\', '', $signedData);
$signature = str_replace('\\', '', $signature);

define('PUBLIC_KEY', 'MY GOOGLE MARKET PUBLIC KEY');
define('PACKAGE_NAME', 'MY APP PACKAGE NAME');

$validator = new AndroidMarket_Licensing_ResponseValidator(PUBLIC_KEY, PACKAGE_NAME);
$valid = $validator->verify($signedData, $signature);

if($valid){
    $result['respon'] = 'sucessed';
} else {
    $result['respon'] = 'fail';
}

SendData($result);

$db -> close();

【问题讨论】:

标签: php android in-app-purchase in-app-billing


【解决方案1】:

是的,这完全有可能。谷歌还建议您在他们的安全设置中这样做,以便在最佳实践中做到这一点。以下代码块是我在生产中使用的代码之一,这要归功于 https://gist.github.com/menny

Google 最佳做法:https://developer.android.com/google/play/billing/billing_best_practices.html

以下代码返回真或假。您可以使用 packageName 和 orderId 的唯一性,这样任何人都无法进行重放攻击。

问题的答案:

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;
    }
} 

【讨论】:

    猜你喜欢
    • 2019-01-16
    • 1970-01-01
    • 2014-11-01
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    相关资源
    最近更新 更多