From 7a2abd43a2dea68b4824006e8ac0adc823af8326 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 30 Mar 2019 16:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0base=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/bootstrap/init.php | 1 + webapp/controller/PayController.class.php | 49 +++++-------- webapp/sdkwarpper/basesdk.php | 13 ++++ webapp/sdkwarpper/sdkwarpper.php | 21 ++++++ webapp/sdkwarpper/selfsdk.php | 86 +++++++++++++++++++++++ 5 files changed, 139 insertions(+), 31 deletions(-) create mode 100644 webapp/sdkwarpper/basesdk.php create mode 100644 webapp/sdkwarpper/sdkwarpper.php create mode 100644 webapp/sdkwarpper/selfsdk.php diff --git a/webapp/bootstrap/init.php b/webapp/bootstrap/init.php index b2355bd..f945630 100644 --- a/webapp/bootstrap/init.php +++ b/webapp/bootstrap/init.php @@ -2,5 +2,6 @@ ini_set('date.timezone','Asia/Shanghai'); require 'phpcommon/common.php'; +require 'sdkwarpper/sdkwarpper.php'; require 'config_loader.php'; diff --git a/webapp/controller/PayController.class.php b/webapp/controller/PayController.class.php index ae2e322..5f8ab9d 100644 --- a/webapp/controller/PayController.class.php +++ b/webapp/controller/PayController.class.php @@ -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() - { - - } - } diff --git a/webapp/sdkwarpper/basesdk.php b/webapp/sdkwarpper/basesdk.php new file mode 100644 index 0000000..ae0b034 --- /dev/null +++ b/webapp/sdkwarpper/basesdk.php @@ -0,0 +1,13 @@ + '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; + } +} diff --git a/webapp/sdkwarpper/selfsdk.php b/webapp/sdkwarpper/selfsdk.php new file mode 100644 index 0000000..4bb3c8f --- /dev/null +++ b/webapp/sdkwarpper/selfsdk.php @@ -0,0 +1,86 @@ + $_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 { + + } + + } + +}