应用内购买php验证openssl验证,openssl_get_publickey

时间:2018-10-10 15:22:57

标签: php openssl in-app-purchase

从前端获得响应后,我一直在尝试从服务器端验证inapp购买 Android方面。前端开发人员向我发送以下信息。我正在使用openssl_get_publickey()作为公共密钥(从Google控制台获取)和openssl_verify()函数,但是每次都得到false / 0响应。请帮我解决问题。 预先感谢。

        $signedData =  array(
            "orderId"           => 'GPA.3333-5628-5675-XXXX',
            "packageName"       => 'com.xxxxxxxx',
            "productId"         => 'sample_test_purchase',
            "purchaseTime"      => 1539165004552,
            "purchaseState"     => 0,
            "purchaseToken"     => $purchase_token
        );
    $signedData = json_encode($signedData); 


    $base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlrVLmLsjKbT+D96evuqmVrMq5FnTVtYOJY5AF2R/sadfasfasdfasdfasdfasdf+DQ3kCxGj+dfgdsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXx/NZyXxxxxxxxx";


    $key = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($base64EncodedPublicKey, 64, "\n") . '-----END PUBLIC KEY-----';
    $key = openssl_get_publickey($key);
    $sign=base64_decode($input_fields->signature);
    $result   = openssl_verify($signedData,$sign,$key,OPENSSL_ALGO_SHA1);

输出:0或false 结果为0错误:0906D06C:PEM例程:PEM_read_bio

0 个答案:

没有答案