添加base功能

This commit is contained in:
aozhiwei 2019-03-30 16:46:02 +08:00
parent 5aacc2e840
commit 7a2abd43a2
5 changed files with 139 additions and 31 deletions

View File

@ -2,5 +2,6 @@
ini_set('date.timezone','Asia/Shanghai');
require 'phpcommon/common.php';
require 'sdkwarpper/sdkwarpper.php';
require 'config_loader.php';

View File

@ -2,38 +2,25 @@
class PayController {
protected function getRedis($accountid)
{
$redis_conf = getRedisConfig(crc32($accountid));
$r = new phpcommon\Redis(array(
'host' => $redis_conf['host'],
'port' => $redis_conf['port'],
'passwd' => $redis_conf['passwd']
));
return $r;
}
protected function getMysql($accountid)
{
$mysql_conf = getMysqlConfig(crc32($accountid));
$conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => 'kefudb' . $mysql_conf['instance_id']
));
return $conn;
}
public function getOrderId()
{
echo 'sss';
$channel = phpcommon\extractChannel($_REQUEST['accountid']);
$sdk = sdkwarpper\createSdkByChannel($channel);
if (!$sdk) {
echo 'is null';
} else {
$gameid = isset($_REQUEST['gameid']) ? $_REQUEST['gameid'] : 1008;
switch ($channel)
{
case SELFSDK_CHANNEL:
break;
case WEIXIN_CHANNEL:
break;
default:
break;
}
$sdk->getOrderId();
}
}
public function notifyAllUser()
{
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace sdkwarpper;
use phpcommon;
class BaseSdk {
public function getOrderId()
{
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace sdkwarpper;
require 'basesdk.php';
require 'selfsdk.php';
function createSdkByChannel($channel)
{
$channel_sdk_hash = array(
SELFSDK_CHANNEL => 'SelfSdk',
WEIXIN_CHANNEL => 'Weixin'
);
if (array_key_exists($channel, $channel_sdk_hash)) {
$class_name = "sdkwarpper\\" . $channel_sdk_hash[$channel];
return new $class_name;
} else {
return null;
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace sdkwarpper;
use phpcommon;
class SelfSdk extends BaseSdk {
public function getOrderId()
{
if (SERVER_ENV != _ONLINE) {
$url = "http://127.0.0.1:7051/webapp/index.php?c=Pay&a=getOrderId";
} else {
$url = "https://center.kingsome.cn/api/games/click/$game_id";
}
$response = '';
$params = array(
'accountid' => $_REQUEST['accountid'],
'roleid' => $_REQUEST['roleid'],
'rolename' => $_REQUEST['rolename'],
'serverid' => $_REQUEST['serverid'],
'itemid' => $_REQUEST['itemid'],
'price' => $_REQUEST['price'],
'sp_orderid' => 'testtttttt'
);
if (!phpcommon\HttpClient::get($url, $params, $response)) {
phpcommon\sendError(100,'获取失败');
return;
}
error_log($response);
$ret_info = json_decode($response, true);
if ($ret_info['errcode'] == 0) {
echo json_encode(array(
'errcode' => 0,
'errmsg' => ''
));
$data = array(
'pay_type' => 1,
'orderid' => $ret_info['orderid'],
'payresult' => 1
);
$this->payNotify($data);
} else {
echo json_encode(array(
'errcode' => $ret_info['errcode'],
'errmsg' => $ret_info['errmsg'],
));
}
}
private function payNotify($data)
{
if (SERVER_ENV != _ONLINE) {
$url = "http://127.0.0.1:7051/webapp/index.php?c=Pay&a=payNotify";
} else {
$url = "https://center.kingsome.cn/api/games/click/$game_id";
}
$response = '';
$params = array(
'pay_type' => $data['pay_type'],
'orderid' => $data['orderid'],
'payresult' => $data['payresult']
);
if (!phpcommon\HttpClient::get($url, $params, $response)) {
phpcommon\sendError(100,'获取失败');
return;
}
error_log($response);
$ret_info = json_decode($response, true);
if ($ret_info['errcode'] == 0) {
} else {
}
}
}