google⽀付服务端订单验证PHP代码
之前有转发⼀则关于google⽀付服务端验证的⽂章,今天把之前研究出得服务端订单⽀付验证代码(PHP版本)贴出来⼤家分享
下载google的php版本的官⽅sdk程序包,然后代码如下:
每次付费成功后,客户端调⽤计费回调⽅法可以获取交易的状态:其中会有purchase token和productId(就是在google应⽤app后台配
置的⽀付商品⾃定义标⽰)
请求订单交易状态代码如下:
<?php
google官方下载apprequire_once 'Google/Client.php';
require_once 'Google/Service/AndroidPublisher.php';
//include 'Google/Auth/AssertionCredentials.php';
try{
$client = new Google_Client();
$key_file_location = 'prikey.p12';
$key = file_get_contents($key_file_location);
$service_account_name = 'xxxxxxxxxxxx-t1280g9vsd7465aprh0xxxxxxxxxxx@developer.gserviceaccount';
$cred = new Google_Auth_AssertionCredentials(
// Replace this with the email address from the client.
$service_account_name,
// Replace this with the scopes you are requesting.
array('leapis/auth/androidpublisher'),
$key
);
$client->setAssertionCredentials($cred);
$service = new Google_Service_AndroidPublisher( $client );
$packageName='';
$productId='9419';
$token = 'omoaokhfkmiipfffmemjaclh.AO-J1OyFcurjPmcY4J5MFMYvW5z6jq-X9SrpZCo93etscPe0SzDItMnAY50RLWLwOEYl71HQEBXG8fREgJp-EVZTOwkG8uH $optps=array();
$resp = $service->purchases_products->get( $packageName, $productId, $token, $optps );
$resp = (array)$resp;
var_dump($resp);
}catch(Exception $e){
echo $e->getCode(),'|',$e->getMessage();
}
>
consumptionState:商品消费状态,0表还未消费,1表消费了(因为google的同⼀个商品未消费的话是不允许重复购买的)
developerPayload:这个⽐较重要,是我们开发者⾃定义透传的,⼀般为⾃⾝系统订单号之类的交易唯⼀标⽰,可以⽤来⽐对
purchaseState:购买状态,1代表购买了,0代表取消
备注:貌似这个api调⽤google平台有20w/⽇的次数限制

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。