147 lines
4.8 KiB
PHP
147 lines
4.8 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
require 'classes/AddReward.php';
|
|
|
|
class RechargeController{
|
|
|
|
protected function getMysql($account_id)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($account_id));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
public function prePay() {
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
$goods_id = $_REQUEST['goods_id'];
|
|
|
|
$url = '';
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$url = 'https://payservice.kingsome.cn/api/ingame/spreorder';
|
|
} else {
|
|
$url = 'https://payservice-test.kingsome.cn/api/ingame/spreorder';
|
|
}
|
|
$sign = md5($_REQUEST['account_id'].$_REQUEST['goods_id'].'f3a6a9a5-217a-4079-ab99-b5d69b8212be'.$_REQUEST['session_id']);
|
|
$params = array(
|
|
'account_id' => $_REQUEST['account_id'],
|
|
'goods_id' => $goods_id,
|
|
'session_id' => $_REQUEST['session_id'],
|
|
'user_ip' => phpcommon\getIPv4(),
|
|
'sign' => $sign
|
|
);
|
|
if (!phpcommon\HttpClient::get($url, $params, $rsp)) {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
|
return;
|
|
}
|
|
|
|
if ($rsp == null || $rsp == '') {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙2');
|
|
return;
|
|
}
|
|
|
|
$response = json_decode($rsp, true);
|
|
echo json_encode(array(
|
|
'errcode' => $response['errcode'],
|
|
'errmsg'=> $response['errmsg'],
|
|
'order_id' => $response['order_id']
|
|
));
|
|
}
|
|
|
|
public function payDone() {
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
$order_id = $_REQUEST['order_id'];
|
|
|
|
$url = '';
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$url = 'https://payservice.kingsome.cn/api/ingame/paid';
|
|
} else {
|
|
$url = 'https://payservice-test.kingsome.cn/api/ingame/paid';
|
|
}
|
|
$sign = md5($_REQUEST['account_id'].$_REQUEST['order_id'].'f3a6a9a5-217a-4079-ab99-b5d69b8212be'.$_REQUEST['session_id']);
|
|
$params = array(
|
|
'account_id' => $_REQUEST['account_id'],
|
|
'order_id' => $order_id,
|
|
'session_id' => $_REQUEST['session_id'],
|
|
'user_ip' => phpcommon\getIPv4(),
|
|
'sign' => $sign
|
|
);
|
|
if (!phpcommon\HttpClient::get($url, $params, $rsp)) {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
|
return;
|
|
}
|
|
|
|
if ($rsp == null || $rsp == '') {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙 2');
|
|
return;
|
|
}
|
|
|
|
$response = json_decode($rsp, true);
|
|
$diamonds = $response['diamond'];
|
|
$diamond_num = -1;
|
|
if ($diamonds > 0) {
|
|
$userrow = $conn->execQueryOne(
|
|
'SELECT diamond_num, free_diamond FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
)
|
|
);
|
|
if (!$userrow) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
$diamond_num = $userrow['diamond_num'] + $diamonds;
|
|
|
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':diamond_num' => $diamond_num
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => $response['errcode'],
|
|
'errmsg'=> $response['errmsg'],
|
|
'order_id' => $response['order_id'],
|
|
'diamond_nums' => $diamond_num
|
|
));
|
|
}
|
|
}
|
|
?>
|