95 lines
2.7 KiB
PHP
95 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace sdkwarpper;
|
|
|
|
require 'BaseSdk.php';
|
|
|
|
use phpcommon;
|
|
use classes;
|
|
|
|
class GoogleAndroid extends BaseSdk {
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->conf_appid = '';
|
|
}
|
|
|
|
private function loadConfig()
|
|
{
|
|
$config_name = "../config/game{$this->gameid}/{$this->channel}/config.php";
|
|
$this->config = require($config_name);
|
|
$this->conf_appid = $this->config['appid'];
|
|
$this->conf_package_name = $this->config['package_name'];
|
|
}
|
|
|
|
public function payNotify()
|
|
{
|
|
if (!phpcommon\isValidSessionId($_REQUEST['_account_id'], $_REQUEST['_session_id'])) {
|
|
phpcommon\sendError(1, 'session无效');
|
|
return;
|
|
}
|
|
|
|
$this->gameid = phpcommon\extractGameId($_REQUEST['_account_id']);
|
|
$this->real_channel = phpcommon\extractChannel($_REQUEST['_account_id']);
|
|
$this->loadConfig();
|
|
|
|
$packageName = $this->conf_package_name;
|
|
$productId = $_REQUEST['_itemid'];
|
|
$token = $_REQUEST['_purchase_token'];
|
|
|
|
$response = '';
|
|
$proxy = null;
|
|
if (SERVER_ENV != _ONLINE) {
|
|
$proxy = array(
|
|
"host" => "127.0.0.1",
|
|
"port" => 8118,
|
|
"user_pwd" => ""
|
|
);
|
|
}
|
|
if (phpcommon\HttpClient::get(
|
|
"https://androidpublisher.googleapis.com/androidpublisher/v3/applications/" .
|
|
"{$packageName}/purchases/products/{$productId}/tokens/{$token}",
|
|
array(
|
|
'access_token' => '2134234'
|
|
),
|
|
$response,
|
|
$proxy)) {
|
|
phpcommon\sendError(2, '服务器内部错误');
|
|
return;
|
|
}
|
|
error_log($response);
|
|
echo $response;
|
|
|
|
$receipt_info = array();
|
|
$receipt_db = $this->order_ctrl->getReceipt($receipt_info['purchaseToken']);
|
|
$order_db = $this->order_ctrl->getOrderBySpOrderId(
|
|
$_REQUEST['account_id'],
|
|
$this->real_channel,
|
|
$receipt_info['purchaseToken']
|
|
);
|
|
if ($receipt_db) {
|
|
if ($receipt_db['account_id'] != $_REQUEST['account_id']) {
|
|
phpcommon\sendError(2, '账号id不匹配');
|
|
return;
|
|
}
|
|
if ($order_db) {
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
|
|
'cp_orderid' => $order_db['orderid'],
|
|
'status' => $order_db['status'],
|
|
));
|
|
return;
|
|
} else {
|
|
phpcommon\sendError(2, '订单不存在');
|
|
return;
|
|
}
|
|
} else {
|
|
$cp_orderid = $this->genOrderId($_REQUEST['account_id']);
|
|
}
|
|
}
|
|
|
|
}
|