diff --git a/webapp/controller/PayController.class.php b/webapp/controller/PayController.class.php index 8c3893c..5dde97b 100644 --- a/webapp/controller/PayController.class.php +++ b/webapp/controller/PayController.class.php @@ -35,6 +35,9 @@ class PayController { } else { $channel = $_REQUEST['_channel']; } + if (!empty($_REQUEST['_unified_channel'])) { + $channel = $_REQUEST['_unified_channel']; + } $sdk = sdkwarpper\createSdkByChannel($channel); if (!$sdk) { echo 'is null'; @@ -46,6 +49,14 @@ class PayController { public function queryOrderInfo() { + $channel = phpcommon\extractChannel($_REQUEST['account_id']); + $sdk = sdkwarpper\createSdkByChannel($channel); + if (!$sdk) { + echo 'is null'; + } else { + $sdk->setChannel($channel); + $sdk->queryOrderInfo(); + } } } diff --git a/webapp/sdkwarpper/BaseSdk.php b/webapp/sdkwarpper/BaseSdk.php index bf079b5..6b44bdb 100644 --- a/webapp/sdkwarpper/BaseSdk.php +++ b/webapp/sdkwarpper/BaseSdk.php @@ -11,6 +11,8 @@ class BaseSdk { protected $real_channel = '0'; protected $channel = '0'; + protected $unified_channel = '0'; + protected $poly_sdk_channel = '0'; protected $gameid = 0; protected $order_ctrl = null; diff --git a/webapp/sdkwarpper/UnifiedWeiXin.php b/webapp/sdkwarpper/UnifiedWeiXin.php index ae64ed2..063eb65 100644 --- a/webapp/sdkwarpper/UnifiedWeiXin.php +++ b/webapp/sdkwarpper/UnifiedWeiXin.php @@ -12,6 +12,7 @@ class UnifiedWeiXin extends BaseSdk { function __construct() { parent::__construct(); + $this->unified_channel = $this->channel; $this->conf_appid = ''; $this->conf_mch_id = ''; $this->conf_pay_secret_key = ''; @@ -30,15 +31,31 @@ class UnifiedWeiXin extends BaseSdk { public function preOrder() { $this->gameid = phpcommon\extractGameId($_REQUEST['account_id']); - $this->real_channel = phpcommon\extractGameId($_REQUEST['account_id']); + $this->real_channel = phpcommon\extractChannelId($_REQUEST['account_id']); $this->loadConfig(); + $cp_orderid = $this->order_ctrl->genOrderId(); + { + $this->order_ctrl->addPreOrder( + array( + 'orderid' => $cp_orderid, + 'account_id' => $_REQUEST['account_id'], + 'roleid' => '', + 'server_id' => 0, + 'poly_sdk_channel' => $this->poly_sdk_channel, + 'unified_channel' => $this->unified_channel, + 'itemid' => $itemid, + 'ipv4' => phpcommon\getIPv4(), + ) + ); + } + $params = array( 'appid' => $this->conf_appid, 'mch_id' => $this->conf_mch_id, - 'nonce_str' => uniqid('201019'), + 'nonce_str' => md5($cp_orderid . time()), 'body' => '测试产品', - 'out_trade_no' => uniqid('201019'), + 'out_trade_no' => $cp_orderid, 'total_fee' => '101', 'spbill_create_ip' => phpcommon\getIPv4(), 'notify_url' => 'https://gamepay.kingsome.cn/webapp/paynotify/unified_weixin.php', @@ -60,9 +77,26 @@ class UnifiedWeiXin extends BaseSdk { phpcommon\objectToXml($params), $response )) { - + phpcommon\sendError(1, '服务器内部错误'); + return; } echo $response; + $xml = new \SimpleXMLElement($response); + if ($xml->return_code != 'SUCCESS') { + phpcommon\sendError(2, $xml->return_msg); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'cp_orderid' => $cp_orderid, + 'prepayid' => $xml->prepay_id + )); + } + + public function payNotify() + { + } }