This commit is contained in:
aozhiwei 2020-10-20 12:15:44 +08:00
parent a12be7649a
commit b5c0c9dd6b
4 changed files with 28 additions and 16 deletions

View File

@ -53,13 +53,13 @@ class OrderCtrl {
return uniqid('201020') . $hex_str;
}
public function getOrderByCpOrderId($cp_orderid)
public function getOrder($cp_orderid)
{
$conn = $this->getMysql($this->getCpOrderIdDNA($cp_orderid));
$row = $conn->execQueryOne('SELECT * FROM orderinfo ' .
'WHERE orderid=:orderid;',
array(
':orderid' => $orderid
':orderid' => $cp_orderid
)
);
return $row;
@ -78,6 +78,7 @@ class OrderCtrl {
{
$gameid = phpcommon\extractGameId($order_info['account_id']);
$openid = phpcommon\extractOpenId($order_info['account_id']);
$channel = phpcommon\extractChannel($order_info['account_id']);
$conn = $this->getMysql($this->getStrDNA($order_info['account_id']));
$ret = $conn->execScript('INSERT INTO orderinfo(' .
' orderid, account_id, roleid, server_id, channel, ' .
@ -97,7 +98,7 @@ class OrderCtrl {
':account_id' => $order_info['account_id'],
':roleid' => $order_info['roleid'],
':server_id' => $order_info['server_id'],
':channel' => $order_info['channel'],
':channel' => $channel,
':poly_sdk_channel' => $order_info['poly_sdk_channel'],
':unified_channel' => $order_info['unified_channel'],
':gameid' => $gameid,

View File

@ -49,14 +49,19 @@ 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();
require 'classes/OrderCtrl.php';
$order_ctrl = new classes\OrderCtrl();
$order_info = $order_ctrl->getOrder($_REQUEST['cp_orderid']);
if (!$order_info || $order_info['account_id'] != $_REQUEST['account_id']) {
phpcommon\sendError(1, '订单不存在');
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'cp_orderid' => $order_info['orderid'],
'status' => $order_info['status'],
));
}
}

View File

@ -24,7 +24,7 @@ class BaseSdk
error_log('basesdk new');
}
protected function setChannel($channel)
public function setChannel($channel)
{
$this->channel = $channel;
}
@ -39,9 +39,10 @@ class BaseSdk
public function queryOrderInfo()
{
$order_info = $this->order_ctrl->getOrderByCpOrderId($_REQUEST['cp_orderid']);
$order_info = $this->order_ctrl->getOrder($_REQUEST['cp_orderid']);
if (!$order_info) {
phpcommon\sendError(1, '订单不存在');
return;
}
echo json_encode(array(
'errcode' => 0,

View File

@ -12,12 +12,17 @@ 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 = '';
}
public function setChannel($channel)
{
parent::setChannel($channel);
$this->unified_channel = $this->channel;
}
private function loadConfig()
{
$config_name = "../config/game{$this->gameid}/{$this->channel}/config.php";
@ -31,7 +36,7 @@ class UnifiedWeiXin extends BaseSdk {
public function preOrder()
{
$this->gameid = phpcommon\extractGameId($_REQUEST['account_id']);
$this->real_channel = phpcommon\extractChannelId($_REQUEST['account_id']);
$this->real_channel = phpcommon\extractChannel($_REQUEST['account_id']);
$this->loadConfig();
$cp_orderid = $this->order_ctrl->genOrderId($_REQUEST['account_id']);
@ -42,10 +47,10 @@ class UnifiedWeiXin extends BaseSdk {
'account_id' => $_REQUEST['account_id'],
'roleid' => '',
'server_id' => 0,
'itemid' => 1,
'price' => 101,
'poly_sdk_channel' => $this->poly_sdk_channel,
'unified_channel' => $this->unified_channel,
'itemid' => $itemid,
'ipv4' => phpcommon\getIPv4(),
)
);
@ -73,7 +78,7 @@ class UnifiedWeiXin extends BaseSdk {
error_log(json_encode($params));
error_log(phpcommon\objectToXml($params));
$response = '';
if (phpcommon\HttpClient::postContent(
if (!phpcommon\HttpClient::postContent(
'https://api.mch.weixin.qq.com/pay/unifiedorder',
phpcommon\objectToXml($params),
$response