This commit is contained in:
aozhiwei 2020-10-16 16:25:12 +08:00
parent 5202915550
commit 77366f1e23
2 changed files with 0 additions and 283 deletions

View File

@ -4,13 +4,6 @@ require 'phpcommon/tglog.php';
class PayController {
const SCAN_PAY_API_URL = 'https://gwapi.yemadai.com/pay/aggregatePay';
const PRI_KEY = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALaDZP3ysvKxkBLWlW/aAT/YM5/34uQcj2gQVV4q9Vkoscw3MSlmRcr4hckwenGUw0tK2LC4vEume8JBCm0ZsWiGoOwcAJp16Zzr+35hUXYVfgXoYiAG5o8N0nBIYCWO1Tk/e+wJsmkY9eHpA3Iq94EAkogttd6bqk+X4nTUIxfJAgMBAAECgYB3pECC3CMERvOr9bC2RtGE2aRV2/iHElXLoNFlToHQ9YU/2npGqj1cJXgF/9p0NFGlPKY5ipAcg0EjgOFlzW7me9C/wC7x704+WMsqZu7POvOXTlFDRVHYpd6iQqLubjToSMPeIEreSBQYjU8giiVxEZ+7mcFpBShFcXSTJWInBQJBANw5/euICWKnqtmN/PXzdKVC+Y4A2TsYgxWCQaCrjO7YytqCCoaZSJn0+rnTchI0VB2YP0nBxlz+8Jp7DkPjpMsCQQDUKR2Olmh7VB9OQ49KhsgGoNMZvZB69borAPtY8I3eSkyS3t6xTa5S9AEXV4hW1553/KewBAYvnAwS0Gkevbc7AkAzlaXjoLbKFAoR8Y9aMQ+WkkyQNaSskf5KcHtc3jIh1EgXzLQYeRknbtm3405p8zXsxLe2WBxVtiW3mbFqt4znAkEAoeLJmd5s1QYoaRimAtD7WgtnaPG7iAduSZgTMhdDuUVqTnte412J0eQ73Oq+rr0SPy37ahR3/+YLVGPQglNytwJAAcbSZ0EhcRaJUMcrrs2HQoMmQ53Gs5qJsVE5VWUh25Ryqjjo6y7kVYVVaYU1xhguMs7309Y4F4VFiPLZeLIpcw==';
const MER_NO = '49118';
const SUB_APPID = 'wx7d6509053659d9ed';
const COMPANY_NO = 'sweep-f4fea613fec043f8bd81e9b70375e364';
protected function getMysql($accountid)
{
$mysql_conf = getMysqlConfig(crc32($accountid));
@ -24,185 +17,4 @@ class PayController {
return $conn;
}
//ksome201908191405_xxxxx
private function getOrderId()
{
$conn = $this->getMysql($_REQUEST['account_id']);
$orderid_pre = 'ksome' . strftime('%y%m%d%H%M%S');
$ret = $conn->execScript("INSERT INTO orderidx(createtime) VALUES(:createtime);",
array(
'createtime' => time()
));
if (!$ret) {
die();
}
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID();', array());
if (empty($row)) {
die();
}
$orderid = $orderid_pre . '_' . $row[0];
return $orderid;
}
private function _reaEncode($str) {
$prikey = phpcommon\readPriKey(self::PRI_KEY);
return openssl_sign($str, $sign, $prikey, OPENSSL_ALGO_SHA1) ? base64_encode($sign) : false;
}
public function aggregatePay()
{
if (!phpcommon\isValidSessionId(
$_REQUEST['account_id'],
$_REQUEST['session_id']
)) {
echo json_encode(array(
'errcode' => 100,
'errmsg' => 'session无效',
));
die();
}
$nowtime = time();
$openid = phpcommon\extractOpenId($_REQUEST['account_id']);
$minigame_appid = self::SUB_APPID;
$minigame_accountid = $_REQUEST['account_id'];
{
$ipos = strpos($_REQUEST['data'], '_');
$gameid = substr($_REQUEST['data'], 0, $ipos);
$rawdata = substr($_REQUEST['data'], $ipos + 1, strlen($_REQUEST['data']) - $ipos);
$rawdata = base64_decode($rawdata);
$iv = '1dd2f605f4f8496b';
$key = 'c868a478c81ff3c168b35d703f787d3c';
$data = phpcommon\aesDecrypt($rawdata, $iv, $key);
if (empty($data)) {
die();
}
$jsonobj = json_decode($data, true);
if (!isset($jsonobj)) {
die();
}
$game_account_id = $jsonobj['account_id'];
$game_channel = phpcommon\extractChannel($jsonobj['account_id']);
$game_openid = phpcommon\extractOpenId($jsonobj['account_id']);
$real_amount = $jsonobj['price'];
$amount = $jsonobj['price'];
$itemid = $jsonobj['itemid'];
$itemnum = $jsonobj['itemnum'];
if (SERVER_ENV != _ONLINE) {
$amount = 0.01;
}
}
$orderid = $this->getOrderId();
if (empty($orderid)) {
die();
}
$advice_url = '';
if (SERVER_ENV != _ONLINE) {
$advice_url = "https://gamepay-test.kingsome.cn/webapp/index.php?c=PayNotify&a=payNotify";
} else {
$advice_url = "https://gamepay.kingsome.cn/webapp/index.php?c=PayNotify&a=payNotify";
}
$params = array(
'MerchantNo' => self::MER_NO,
'MerchantOrderNo' => $orderid,
'PayType' => 'WxJsapi_OnLine',
'Amount' => $amount,
'Subject' => '1',
'Desc' => '1',
'CompanyNo' => self::COMPANY_NO,
'RandomStr' => $orderid,
'SignInfo' => '',
'AdviceUrl' => htmlentities($advice_url),
'SubAppid' => self::SUB_APPID,
'UserId' => $openid
);
$params['SignInfo'] = $this->_reaEncode(
'AdviceUrl=' . $advice_url . '&' .
'Amount=' . $params['Amount'] . '&' .
'MerchantNo=' . $params['MerchantNo'] . '&' .
'MerchantOrderNo=' . $params['MerchantOrderNo'] . '&' .
'PayType=' . $params['PayType'] . '&' .
'RandomStr=' . $params['RandomStr'] .
''
);
$xml_txt = phpcommon\objectToXml($params, '<AggregatePayRequest/>');
$xml_txt = str_replace('<?xml version="1.0"?>', '<?xml version="1.0" encoding="utf-8"?>', $xml_txt);
# echo $xml_txt;
$requestDomain = base64_encode($xml_txt);
$response = '';
if (!phpcommon\HttpClient::post(self::SCAN_PAY_API_URL,
'requestDomain='. urlencode($requestDomain),
$response)
) {
echo json_encode(array(
'errcode' => 101,
'errmsg' => '交易失败:' . $response,
));
die();
}
$xmlobj = new \SimpleXMLElement(base64_decode($response));
if ($xmlobj->RespCode == '0000') {
$conn = $this->getMysql($_REQUEST['account_id']);
$ret = $conn->execScript('INSERT INTO orderinfo(orderid, accountid, channel, gameid, openid, ' .
' itemid, price, ipv4, createtime, sp_orderid, ' .
' minigame_appid, minigame_accountid)' .
'VALUES(:orderid, :accountid, :channel, :gameid, :openid, :itemid, ' .
' :price, :ipv4, :createtime, :sp_orderid, :minigame_appid, :minigame_accountid);',
array(
':orderid' => $orderid,
':accountid' => $game_account_id,
':openid' => $game_openid,
':channel' => $game_channel,
':gameid' => $gameid,
':itemid' => $itemid,
':price' => $real_amount,
':ipv4' => phpcommon\getIPv4(),
':createtime' => time(),
':sp_orderid' => (string)$xmlobj->OrderNo,
':minigame_appid' => $minigame_appid,
':minigame_accountid' => $minigame_accountid,
));
{
$log_params = array(
'#account_id' => $game_account_id,
'#distinct_id' => '',
'#type' => 'track',
'#time' => date("Y-m-d H:i:s"),
'#ip' => phpcommon\getIPv4(),
'#event_name' => 'event_' . 11 . '_' . 40,
'properties' => array(
'channel' => $game_channel,
'gameid' => $gameid,
'orderid' => $orderid,
'itemid' => $itemid,
'itemnum' => 1,
'amount' => $real_amount,
'sp_orderid' => (string)$xmlobj->OrderNo,
'minigame_appid' => $minigame_appid,
'minigame_account_id' => $minigame_accountid,
)
);
phpcommon\TGLog::writeToLog('gamepay', $gameid, $log_params);
}
if (!$ret) {
echo json_encode(array(
'errcode' => 2,
'errmsg' => '服务器内部错误',
));
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'orderid' => $orderid,
'pay_str' => (string)$xmlobj->PayStr
));
} else {
echo json_encode(array(
'errcode' => 1,
'errmsg' => '平台错误:' . $xmlobj->RespCode,
));
}
}
}

View File

@ -4,8 +4,6 @@ require 'phpcommon/tglog.php';
class PayNotifyController {
const PUB_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2g2T98rLysZAS1pVv2gE/2DOf9+LkHI9oEFVeKvVZKLHMNzEpZkXK+IXJMHpxlMNLStiwuLxLpnvCQQptGbFohqDsHACademc6/t+YVF2FX4F6GIgBuaPDdJwSGAljtU5P3vsCbJpGPXh6QNyKveBAJKILbXem6pPl+J01CMXyQIDAQAB';
protected function getMysql($accountid)
{
$mysql_conf = getMysqlConfig(crc32($accountid));
@ -19,97 +17,4 @@ class PayNotifyController {
return $conn;
}
private function _reaEncode($str) {
$prikey = self::_redPrikey();
return openssl_sign($str, $sign, $prikey, OPENSSL_ALGO_SHA1) ? base64_encode($sign) : false;
}
public function payNotify()
{
error_log('payNotify:' . json_encode($_REQUEST));
/*
$sign_info = $this->_reaEncode(
'MerNo=' . $_REQUEST['MerNo'] . '&' .
'BillNo=' . $_REQUEST['BillNo'] . '&' .
'OrderNo=' . $_REQUEST['OrderNo'] . '&' .
'Amount=' . $_REQUEST['Amount'] . '&' .
'Succeed=' . $_REQUEST['Succeed']
);
if ($sign_info != $_REQUEST['SignInfo']) {
die('sign error');
}*/
$nowtime = time();
$conn = $this->getMysql($_REQUEST['BillNo']);
$conn->execScript("INSERT INTO notify_his(orderid, request_data, ipv4, createtime)" .
"VALUES(:orderid, :request_data, :ipv4, :createtime);",
array(
':orderid' => $_REQUEST['BillNo'],
':request_data' => json_encode($_REQUEST),
':ipv4' => phpcommon\getIPv4(),
':createtime' => time()
));
if ($_REQUEST['Succeed'] == '88') {
$row = $conn->execQueryOne('SELECT orderid, accountid, sp_pay_result, status, channel, '.
' gameid, itemid, price '.
'FROM orderinfo ' .
'WHERE orderid=:orderid;',
array(
'orderid' => $_REQUEST['BillNo']
)
);
if ($row) {
{
$log_params = array(
'#account_id' => $row['accountid'],
'#distinct_id' => '',
'#type' => 'track',
'#time' => date("Y-m-d H:i:s"),
'#ip' => phpcommon\getIPv4(),
'#event_name' => 'event_' . 11 . '_' . 41,
'properties' => array(
'channel' => $row['channel'],
'gameid' => $row['gameid'],
'orderid' => $row['orderid'],
'itemid' => $row['itemid'],
'itemnum' => 1,
'amount' => $row['price'],
'sp_orderid' => $_REQUEST['OrderNo'],
'sp_amount' => $_REQUEST['Amount'],
)
);
phpcommon\TGLog::writeToLog('gamepay', $row['gameid'], $log_params);
}
if ($row['status'] == 0 && $row['sp_pay_result'] == 0) {
$ret = $conn->execScript('INSERT INTO confirmed_order(orderid, status, createtime)' .
'VALUES(:orderid, :status, :createtime);',
array(
':orderid' => $_REQUEST['BillNo'],
':status' => 0,
':createtime' => $nowtime,
));
if (!$ret) {
die('dberror');
}
$ret = $conn->execScript('UPDATE orderinfo SET ' .
' sp_pay_result = 1, ' .
' sp_confirm_time = :sp_confirm_time, ' .
' sp_amount = :sp_amount, ' .
' sp_orderid = :sp_orderid ' .
'WHERE orderid=:orderid;',
array(
':orderid' => $_REQUEST['BillNo'],
':sp_orderid' => $_REQUEST['OrderNo'],
':sp_amount' => $_REQUEST['Amount'],
':sp_confirm_time' => $nowtime
));
if ($ret) {
die('ok');
}
}
}
}
die('sign error');
}
}