From 6cb9a7ec6de57268e657e991102b7fbf09428534 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 19 Oct 2020 16:48:19 +0800 Subject: [PATCH] 1 --- webapp/controller/PayController.class.php | 2 ++ webapp/sdkwarpper/BaseSdk.php | 7 ++++++ webapp/sdkwarpper/UnifiedWeiXin.php | 27 ++++++++++++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/webapp/controller/PayController.class.php b/webapp/controller/PayController.class.php index 52d06f5..8c3893c 100644 --- a/webapp/controller/PayController.class.php +++ b/webapp/controller/PayController.class.php @@ -21,6 +21,7 @@ class PayController { if (!$sdk) { echo 'is null'; } else { + $sdk->setChannel($channel); $sdk->preOrder(); } } @@ -38,6 +39,7 @@ class PayController { if (!$sdk) { echo 'is null'; } else { + $sdk->setChannel($channel); $sdk->payNotify(); } } diff --git a/webapp/sdkwarpper/BaseSdk.php b/webapp/sdkwarpper/BaseSdk.php index 27691a1..bf079b5 100644 --- a/webapp/sdkwarpper/BaseSdk.php +++ b/webapp/sdkwarpper/BaseSdk.php @@ -14,10 +14,17 @@ class BaseSdk protected $gameid = 0; protected $order_ctrl = null; + protected $config = null; function __construct() { $this->order_ctrl = new classes\OrderCtrl(); + error_log('basesdk new'); + } + + protected function setChannel($channel) + { + $this->channel = $channel; } public function preOrder() diff --git a/webapp/sdkwarpper/UnifiedWeiXin.php b/webapp/sdkwarpper/UnifiedWeiXin.php index 2a6f7e6..ae64ed2 100644 --- a/webapp/sdkwarpper/UnifiedWeiXin.php +++ b/webapp/sdkwarpper/UnifiedWeiXin.php @@ -11,16 +11,31 @@ class UnifiedWeiXin extends BaseSdk { function __construct() { - $this->channel = UNIFIED_WEIXIN_CHANNEL; - $this->gameid = phpcommon\extractGameId($_REQUEST['account_id']); - $this->real_channel = phpcommon\extractGameId($_REQUEST['account_id']); + parent::__construct(); + $this->conf_appid = ''; + $this->conf_mch_id = ''; + $this->conf_pay_secret_key = ''; + } + + private function loadConfig() + { + $config_name = "../config/game{$this->gameid}/{$this->channel}/config.php"; + $this->config = require($config_name); + $this->conf_appid = $this->config['appid']; + $tmp_str = explode('|', $this->config['pay_secret_key']); + $this->conf_mch_id = $tmp_str[0]; + $this->conf_pay_secret_key = $tmp_str[1]; } public function preOrder() { + $this->gameid = phpcommon\extractGameId($_REQUEST['account_id']); + $this->real_channel = phpcommon\extractGameId($_REQUEST['account_id']); + $this->loadConfig(); + $params = array( - 'appid' => 'wx9b006ee01033cec7', - 'mch_id' => '1509252791', + 'appid' => $this->conf_appid, + 'mch_id' => $this->conf_mch_id, 'nonce_str' => uniqid('201019'), 'body' => '测试产品', 'out_trade_no' => uniqid('201019'), @@ -34,7 +49,7 @@ class UnifiedWeiXin extends BaseSdk { $params['notify_url'] = 'https://gamepay-test.kingsome.cn/webapp/paynotify/unified_weixin.php'; } $sign = phpcommon\wxPaySign($params, - 'ZTlMqTh5lRNefcH2KHroQqxdShEiedD0' + $this->conf_pay_secret_key ); $params['sign'] = strtoupper($sign); error_log(json_encode($params));