game2006api/webapp/controller/BaseAuthedController.class.php
2024-10-11 12:05:19 +08:00

944 lines
33 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once('services/AddItemsService.php');
require_once('services/LogService.php');
require_once('services/TimingPropService.php');
require_once('mt/Item.php');
require_once('models/Bag.php');
require_once('models/DynData.php');
require_once('models/Gun.php');
require_once('models/Hero.php');
require_once('models/HeroSkin.php');
require_once('models/GunSkin.php');
require_once('models/User.php');
require_once('models/Nft.php');
require_once('models/UserSeasonRing.php');
require_once('models/Parachute.php');
require_once('models/Chip.php');
require_once('models/Pass.php');
require_once('models/Avatar.php');
require_once('mt/Parameter.php');
require_once('mt/RankSeason.php');
require_once('mt/LevelUp.php');
require_once('mt/Task.php');
require_once('mt/Drop.php');
require_once('mt/StarLevel.php');
require_once('mt/BattlePass.php');
require_once('mt/AchievementsCycle.php');
require_once('mt/RookieTask.php');
use phpcommon\SqlHelper;
use models\Bag;
use models\DynData;
use models\Hero;
use models\Gun;
use models\HeroSkin;
use models\GunSkin;
use models\User;
use models\Nft;
use models\Parachute;
use models\UserSeasonRing;
use models\Chip;
use models\Pass;
use models\Avatar;
use services\LogService;
class BaseAuthedController extends BaseController {
protected $accountId = '';
private $sessionId = '';
private $mysqlConn = null;
private $redisConn = null;
private $address = null;
private $addressActived = false;
private function isWhiteList()
{
$whiteList = array(
'0x875835829e95fe87e53a2dfcfd9860a735b70754',
'0x11299400d87f24e79af8cb8cc5661792bea45300',
'0x898a887fa574dd0297f202d66d5a65787acc1316',
'0x9b703a5a094df5b1ba4f3dec15810f7c708e31fa',
'0xad2dea1977055db01c66e6e53309c4604ab869b8',
'0xef59f6cc4d190a0ae576c46d4583e92b61174340'
);
return in_array(myself()->_getOpenId(), $whiteList);
}
public function switchAccount($accountId){
$this->accountId = $accountId;
$this->address = null;
$this->addressActived = false;
$this->mysqlConn = null;
$this->redisConn = null;
}
public function switchOnlineAccount($accountId){
$this->accountId = $accountId;
$this->address = null;
$this->addressActived = false;
$this->mysqlConn = null;
$this->redisConn = null;
$r = $this->_getRedis($this->_getAccountId());
$this->sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId());
return !empty($this->sessionId);
}
public function _handlePre()
{
// if (SERVER_ENV == _ONLINE) {
// if (getReqVal('client_uuid', '') != '499af8a0-a1bc-0b0e-dc79-a42cb3f103dc') {
// if ((getReqVal('c', '') != 'Battle')) {
// phpcommon\sendError(1001, 'session expiration');
// die();
// }
// }
// }
$this->accountId = getReqVal('account_id', '');
$this->sessionId = getReqVal('session_id', '');
/*
if ($this->_getAccountId() == '1_2006_google-oauth2|102579762412391374191') {
phpcommon\sendError(1001, 'session expiration');
die();
return;
}*/
if (SERVER_ENV == _ONLINE) {
$sessionTime = $this->_getSessionTime();
if ($sessionTime < 1724049880) {
phpcommon\sendError(1001, 'session expiration');
die();
return;
}
}
if (SERVER_ENV != _DEBUG) {
if (SERVER_ENV == _TEST) {
if ($this->sessionId == "CzRXrGHxwQZJNCeXkTRA") {
return;
} else {
if (!phpcommon\isValidSessionId($this->accountId,
$this->sessionId)) {
phpcommon\sendError(500, 'invalid session_id');
die();
}
}
} else {
if (!phpcommon\isValidSessionId($this->accountId,
$this->sessionId)) {
phpcommon\sendError(500, 'invalid session_id');
die();
}
}
}
if (!(myself()->_getChannel() == IMTBL_CHANNEL ||
myself()->_getChannel() == GUEST_CHANNEL ||
myself()->_getChannel() == POLY_CHANNEL)) {
phpcommon\sendError(1001, 'session expiration');
die();
}
$this->safeApiVerify();
$r = $this->_getRedis($this->_getAccountId());
if (!(getReqVal('c', '') == 'User' && getReqVal('a', '') == 'login')) {
if ((getReqVal('c', '') == 'Battle')) {
return;
}
$sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId());
if (SERVER_ENV != _DEBUG)
{
if (empty($sessionId)) {
$this->updateSession(myself()->_getAccountId(),
myself()->_getSessionId());
} else if ($sessionId != $this->_getSessionId()) {
error_log('session expiration' . json_encode(
$_REQUEST
));
phpcommon\sendError(1001, 'session expiration');
die();
}
}
}
$this->updateActive($r);
}
protected function updateActive($r)
{
$lastActiveTime = $r->get(LAST_ACTIVE_TIME . $this->_getAccountId());
//第一次登录或者跨天更新最后活跃时间
if (empty($lastActiveTime) ||
$lastActiveTime < $this->_getNowDaySeconds()) {
$r->setPx(LAST_ACTIVE_TIME . $this->_getAccountId(), $this->_getNowTime(), 1000 * 3600 * 24);
}
}
protected function updateSession($accountId, $sessionId)
{
$r = $this->_getRedis($this->_getAccountId());
$r->set(LAST_SESSION_KEY . $this->_getAccountId(), $sessionId);
$r->pexpire(LAST_SESSION_KEY . $this->_getAccountId(), 1000 * 3600 * 24);
}
public function _getAccountId()
{
return $this->accountId;
}
public function _getGameId()
{
return phpcommon\extractGameId($this->_getAccountId());
}
public function _getOpenId()
{
return phpcommon\extractOpenId($this->_getAccountId());
}
public function _getChannel()
{
return phpcommon\extractChannel($this->_getAccountId());
}
public function _getAddress()
{
if (!$this->addressActived) {
$userDb = $this->_getOrmUserInfo();
$this->address = $userDb['address'];
$this->addressActived = true;
/*
if (SERVER_ENV != _ONLINE && empty($this->address)) {
$this->address = strtolower('0xa9ecB9F3A0b54d31ce4a035C89EC7Da4110beB59');
if (myself()->_getAccountId() == '6513_2006_3WOWIsmpcihK1KTnNP1Ky5MBOh7rt6Rl') {
///$this->address = strtolower('0x0bb52209756e8d157f2e551a9adb8d9019b688b1');
$this->address = strtolower('0xbd2d6de4b70d370954b187c95dddfbd00f4129ff');
}
}*/
}
return $this->address;
}
public function _isValidAddress()
{
$address = $this->_getAddress();
return !empty($address);
}
public function _getSessionId()
{
return $this->sessionId;
}
public function _getRegisterTime()
{
$registertime = phpcommon\extractRegisterTimeFromSessionId($this->sessionId);
return $registertime;
}
public function _getSessionTime()
{
$sessionTime = phpcommon\extractSessionTimeFromSessionId($this->sessionId);
return $sessionTime;
}
public function _getSelfMysql()
{
if (!$this->mysqlConn) {
$this->mysqlConn = $this->_getMysql($this->_getAccountId());
}
return $this->mysqlConn;
}
public function _getSelfRedis()
{
if (!$this->redisConn) {
$this->redisConn = $this->_getRedis($this->_getAccountId());
}
return $this->redisConn;
}
public function _getUserInfo($fields)
{
$row = SqlHelper::selectOne
($this->_getSelfMysql(),
't_user',
$fields,
array(
'account_id' => $this->_getAccountId()
)
);
if (empty($row)) {
phpcommon\sendError(500, 'server internal error');
error_log('getUserInfo error '. $this->_getAccountId());
die();
}
return $row;
}
public function _getOrmUserInfo()
{
$row = SqlHelper::ormSelectOne
($this->_getSelfMysql(),
't_user',
array(
'account_id' => $this->_getAccountId()
)
);
if (empty($row)) {
phpcommon\sendError(500, 'server internal error');
error_log('getUserInfo error '. $this->_getAccountId());
die();
}
return $row;
}
public function _safeGetOrmUserInfo()
{
$row = SqlHelper::ormSelectOne
($this->_getSelfMysql(),
't_user',
array(
'account_id' => $this->_getAccountId()
)
);
return $row ? $row : null;
}
public function _updateUserInfo($fieldsKv)
{
SqlHelper::update
($this->_getSelfMysql(),
't_user',
array(
'account_id' => $this->_getAccountId()
),
$fieldsKv
);
}
public function _getItemCount($itemId, $userInfo)
{
switch ($itemId) {
case V_ITEM_GOLD:
{
return $userInfo['gold'];
}
break;
case V_ITEM_DIAMOND:
{
return $userInfo['diamond'];
}
break;
case V_ITEM_EXP:
{
return $userInfo['exp'];
}
break;
case V_ITEM_ACTIVE:
{
return $this->_getV(TN_ACTIVE, 0);
}
break;
default:
{
return Bag::getItemCount($itemId);
}
break;
}
return 0;
}
public function _isVirtualItem($itemId)
{
return in_array($itemId, array(
V_ITEM_BIND_GOLD,
V_ITEM_GOLD,
V_ITEM_DIAMOND,
V_ITEM_EXP,
V_ITEM_ACTIVE,
V_ITEM_BCEG,
V_ITEM_STAR,
V_ITEM_ROOKIE_TASK_POINT,
));
}
public function _addVirtualItem($itemId, $itemNum)
{
if ($itemNum <= 0){
return;
}
switch ($itemId) {
case V_ITEM_GOLD:
{
$this->_updateUserInfo(array(
'gold' => function () use($itemNum) {
return "gold + ${itemNum}";
}
));
myself()->_addTgLog("addGold",array(
'item_id'=>$itemId,
'item_num'=>$itemNum,
));
}
break;
case V_ITEM_DIAMOND:
{
$this->_updateUserInfo(array(
'diamond' => function () use($itemNum) {
return "diamond + ${itemNum}";
}
));
myself()->_addTgLog("addDiamond",array(
'item_id'=>$itemId,
'item_num'=>$itemNum,
));
}
break;
case V_ITEM_BCEG:
{
$this->_updateUserInfo(array(
'bceg' => function () use($itemNum) {
return "bceg + ${itemNum}";
}
));
}
break;
case V_ITEM_EXP:
{
// $this->_updateUserInfo(array(
// 'exp' => function () use($itemNum) {
// return "exp + ${itemNum}";
// }
// ));
$userDb = $this->_safeGetOrmUserInfo();
$newlV = $userDb['level'];
$newExp = $userDb['exp']+$itemNum;
\mt\BattlePass::getExpByLv($newlV,$newExp);
$this->_updateUserInfo(array(
'level' => $newlV,
'exp' => $newExp
));
if ($newlV != $userDb['level']){
$currSeasonMeta = \mt\BattlePass::getCurrentSeason();
$passDb = Pass::find($currSeasonMeta['id']);
$rewards = emptyReplace(json_decode($passDb['data'], true), array());
foreach ($rewards['basic'] as &$reward){
if ($newlV >= $reward['level'] && $reward['state']==-1){
$reward['state'] = 0;
}
}
if ($userDb['activated']){
foreach ($rewards['platinum'] as &$reward){
if ($newlV >= $reward['level'] && $reward['state']==-1){
$reward['state'] = 0;
}
}
}
Pass::upsert($currSeasonMeta['id'],json_encode($rewards));
}
}
break;
case V_ITEM_ACTIVE:
{
$addItem = max(0, mt\Parameter::getVal('activeness_limit', 0) - $this->_getDailyV(TN_DAILY_ACTIVE, 0));
$addItem = min($addItem, $itemNum);
if ($addItem > 0) {
$this->_incV(TN_ACTIVE, 0, $itemNum);
$this->_incDailyV(TN_DAILY_ACTIVE, 0, $itemNum);
$this->_incWeeklyV(TN_WEEKLY_ACTIVE, 0, $itemNum);
}
}
break;
case V_ITEM_STAR:
{
$this->_updateUserInfo(array(
'star_num' => function () use($itemNum) {
return "star_num + ${itemNum}";
}
));
$this->_incDailyV(TN_DAILY_GET_STAR_NUM, 0,$itemNum);
}
break;
case V_ITEM_BIND_GOLD:
{
$this->_incDailyV(TN_DAILY_BIND_GOLD, 0,$itemNum);
myself()->_callModelStatic('RookieTask','incTaskVal',mt\RookieTask::PIGGY_BANK_GOLD_COND,$itemNum);
}
break;
case V_ITEM_ROOKIE_TASK_POINT:
{
myself()->_callModelStatic('RookieTask','incTaskVal',\mt\RookieTask::TOTAL_COMMIT_TASK_TIMES_COND,$itemNum);
}
break;
default:
{
}
break;
}
}
public function _decVirtualItem($itemId, $itemNum)
{
if ($itemNum <= 0){
return;
}
switch ($itemId) {
case V_ITEM_GOLD:
{
$fieldsKv = array(
'gold' => function () use($itemNum) {
return "gold - ${itemNum}";
},
'consume_gold' => function () use ($itemNum){
return "consume_gold + ${itemNum}";
});
array_push($fieldsKv);
$this->_updateUserInfo($fieldsKv);
$this->_incDailyV(TN_DAILY_USED_GOLD_NUM, 0, $itemNum);
// $this->_incPeriodV(TN_HASH_RATE_GOLD_CONSUME, 0, $itemNum);
myself()->_fireEvent('ConsumeProduct','onGoldConsume',$itemNum);
myself()->_addTgLog("decGold",array(
'item_id'=>$itemId,
'item_num'=>$itemNum,
));
}
break;
case V_ITEM_DIAMOND:
{
$this->_updateUserInfo(array(
'diamond' => function () use($itemNum) {
return "GREATEST(0, diamond - ${itemNum})";
}
));
myself()->_fireEvent('ConsumeProduct','onDiamondConsume',$itemNum);
myself()->_addTgLog("decDiamond",array(
'item_id'=>$itemId,
'item_num'=>$itemNum,
));
}
break;
case V_ITEM_BIND_GOLD:
{
$this->_decDailyV(TN_DAILY_BIND_GOLD, 0,$itemNum);
}
break;
default:
{
}
break;
}
}
public function _addItems($items, $awardService, $propertyService){
$obj = new services\AddItemsService();
$obj->addItems($items, $awardService, $propertyService);
}
// public function _addItems($items, $awardService, $propertyService)
// {
// myself()->_checkS();
// $heads = array();
// $headFrames = array();
// foreach ($items as $item) {
// //道具产出埋点
// LogService::productItem($item);
// if ($awardService){
// $awardService->addItem($item['item_id'], $item['item_num']);
// }
// if ($this->_isVirtualItem($item['item_id'])) {
// $this->_addVirtualItem($item['item_id'], $item['item_num'],$awardService,$propertyService);
// $propertyService->addUserChg();
// } else {
// $itemMeta = mt\Item::get($item['item_id']);
// if ($itemMeta) {
// if (mt\Item::isBagItem($itemMeta['type'], $itemMeta['sub_type'])) {
// Bag::addItem($item['item_id'], $item['item_num']);
// $propertyService->addBagChg();
// } else {
// for ($i=0; $i<$item['item_num']; $i++){
// switch ($itemMeta['type']) {
// case mt\Item::HERO_TYPE:
// {
// $heroMeta = \mt\Hero::get($itemMeta['id']);
// $res = Hero::addHero($heroMeta);
// if ($res){
// $lastIdx = SqlHelper::getLastInsertId( myself()->_getSelfMysql());
// $awardService->addHero($item['item_id'],$lastIdx);
// }
// $propertyService->addHeroChg();
// $propertyService->addUserChg();
// }
// break;
// case mt\Item::HERO_SKIN_TYPE:
// {
// HeroSkin::addSkin($itemMeta);
// $propertyService->addHeroSkinChg();
// }
// break;
// case mt\Item::HEAD_TYPE:
// {
// array_push($heads, $itemMeta['id']);
// $propertyService->addUserChg();
// }
// break;
// case mt\Item::HEAD_FRAME_TYPE:
// {
// array_push($headFrames, $itemMeta['id']);
// $propertyService->addUserChg();
// }
// break;
// case mt\Item::GUN_TYPE:
// {
// Gun::addGun($itemMeta);
// $propertyService->addGunChg();
// }
// break;
// case mt\Item::GUN_SKIN_TYPE:
// {
// GunSkin::addSkin($itemMeta['id']);
// $propertyService->addGunSkinChg();
// }
// break;
// case mt\Item::FRAGMENT_BOX_TYPE:
// {
// Bag::addItem($item['item_id'], $item['item_num']);
// $propertyService->addBagChg();
// }
// break;
// case mt\Item::RING_TYPE:
// {
// UserSeasonRing::addRing($itemMeta);
// $propertyService->addUserChg();
// }
// break;
// case mt\Item::PARACHUTE_TYPE:
// {
// Parachute::addParachute($itemMeta);
// $propertyService->addUserChg();
// }
// break;
// case mt\Item::CHIP_TYPE:
// {
// Chip::addChip($itemMeta);
// $propertyService->addChip();
// }
// break;
// case mt\Item::RANDOM_BOX_TYPE:
// {
// $this->_openRandomBox($itemMeta,$awardService,$propertyService);
// }
// break;
// case mt\Item::AVATAR_TYPE:
// {
// Avatar::addAvatar($itemMeta);
// }
// break;
// case mt\Item::TIMING_PROP_TYPE:
// {
// $timingObj = new \services\TimingPropService();
// $timingObj->handleProp($itemMeta);
// }
// break;
// case mt\Item::APPOINT_PROP_TYPE:
// {
//
// }
// break;
// default:
// {
// $this->_addLogEx($this->_getAccountId(),
// 'additems', 'invalid_item',
// array(
// 'param1' => $item['item_id'],
// 'param2' => $item['item_num'],
// ));
// }
// break;
// }
// }
//
// }
// }
// }
// }//end foreach
// if (!empty($heads) || !empty($headFrames)) {
// $userInfo = $this->_getOrmUserInfo();
// $headsDb = emptyReplace(json_decode($userInfo['head_list'], true), array());
// $headFramesDb = emptyReplace(json_decode($userInfo['head_frame_list'], true), array());
// $heads = array_unique(array_merge($heads, $headsDb));
// $headFrames = array_values(array_unique(array_merge($headFrames, $headFramesDb)));
// $this->_updateUserInfo(array(
// 'head_list' => json_encode($heads),
// 'head_frame_list' => json_encode($headFrames),
// ));
// }
// }
public function _openRandomBox($itemMeta,$awardService,$propertyService){
if ($itemMeta['include_item_id']) {
$includeItemIds = explode('|', $itemMeta['include_item_id']);
$key = array_rand($includeItemIds,1);
$items = array(
array(
'item_id' => $includeItemIds[$key] ,
'item_num' => 1
)
);
$this->_addItems($items,$awardService,$propertyService);
}
}
public function _addTryUsingItems($items)
{
foreach ($items as $item) {
Bag::addTryUsingItem($item['item_id'], $item['item_num'], $item['try_using_time']);
}
}
public function _decItems($items)
{
myself()->_checkS();
foreach ($items as $item) {
//道具消耗埋点
LogService::consumeItem($item);
if ($this->_isVirtualItem($item['item_id'])) {
$this->_decVirtualItem($item['item_id'], $item['item_num']);
} else {
Bag::decItem($item['item_id'], $item['item_num']);
}
}
}
public function _hasEnoughItems($items, &$lackItem)
{
$userInfo = $this->_getUserInfo(array(
'gold',
'diamond',
));
foreach ($items as $item) {
$inventory = $this->_getItemCount($item['item_id'], $userInfo);
if ($inventory < $item['item_num']) {
$lackItem = array(
'item_id' => $item['item_id'],
'item_num' => $item['item_num'],
'inventory' => $inventory
);
return false;
}
}
return true;
}
public function _getLackItemErrMsg($lackItem)
{
if (!$lackItem) {
return 'Not enough item';
}
$itemMeta = mt\Item::get($lackItem['item_id']);
if (!$itemMeta) {
return 'Not enough item';
}
if (SERVER_ENV != _ONLINE) {
return "${itemMeta['name']} Not enough stock:${lackItem['inventory']} need:${lackItem['item_num']}";
} else {
// return "${itemMeta['name']} Not enough";
return "item Not enough";
}
}
public function _scatterDrop($dropSource, $dropMeta, $awardService, $propertyService)
{
$itemIds = explode('|', $dropMeta['item_id']);
$nums = explode('|', $dropMeta['num']);
$weights = explode('|', $dropMeta['weight']);
if (count($itemIds) != count($nums) ||
count($itemIds) != count($weights)) {
return;
}
$totalWeight = 0;
foreach ($weights as $weight) {
$totalWeight += $weight;
}
$addItems = array();
if ($dropMeta['type'] == 1) {
//N out of n
for ($i = 0; $i < count($itemIds); ++$i) {
$itemId = $itemIds[$i];
$num = $nums[$i];
$weight = $weights[$i];
if ((rand() % 10000) < $weight) {
array_push($addItems, array(
'item_id' => $itemId,
'item_num' => $num
));
}
}
}else if ($dropMeta['type'] == 2 && $totalWeight > 0) {
//1 out of n
$currWeight = 0;
$rnd = rand() % $totalWeight;
for ($i = 0; $i < count($itemIds); ++$i) {
$itemId = $itemIds[$i];
$num = $nums[$i];
$currWeight += $weights[$i];
if ($currWeight > $rnd) {
array_push($addItems, array(
'item_id' => $itemId,
'item_num' => $num
));
break;
}
}
}
if (count($addItems) > 0) {
$this->_addItems($addItems, $awardService, $propertyService);
}
SqlHelper::insert(
myself()->_getSelfMysql(),
't_drop_log',
array(
'account_id' => myself()->_getAccountId(),
'drop_source' => $dropSource,
'drop_id' => $dropMeta['drop_id'],
'drop_items' => json_encode($addItems),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public function _getV($x, $y, $defVal = 0)
{
return DynData::getV($x, $y, $defVal);
}
public function _setV($x, $y, $val)
{
DynData::setV($x, $y, $val);
}
public function _incV($x, $y, $incVal)
{
DynData::incV($x, $y, $incVal);
}
public function _decV($x, $y, $decVal)
{
DynData::decV($x, $y, $decVal);
}
public function _getDailyV($x, $y, $defVal = 0)
{
return DynData::getDailyV($x, $y, $defVal);
}
public function _setDailyV($x, $y, $val)
{
DynData::setDailyV($x, $y, $val);
}
public function _incDailyV($x, $y, $incVal)
{
DynData::incDailyV($x, $y, $incVal);
}
public function _decDailyV($x, $y, $decVal)
{
DynData::decDailyV($x, $y, $decVal);
}
public function _getWeeklyV($x, $y, $defVal = 0)
{
return DynData::getWeeklyV($x, $y, $defVal);
}
public function _setWeeklyV($x, $y, $val)
{
DynData::setWeeklyV($x, $y, $val);
}
public function _incWeeklyV($x, $y, $incVal)
{
DynData::incWeeklyV($x, $y, $incVal);
}
public function _decWeeklyV($x, $y, $decVal)
{
DynData::decWeeklyV($x, $y, $decVal);
}
public function _incPeriodV($x, $y, $incVal){
$currentPeriod= \mt\AchievementsCycle::getCurrentPeriod();
if ($currentPeriod && strtotime($currentPeriod['obtain_end_time']) > myself()->_getNowTime()){
DynData::incPeriodV($x, $y,strtotime($currentPeriod['obtain_start_time']), $incVal);
}
}
public function _getPeriodV($x, $y, $decVal = 0){
$currentPeriod= \mt\AchievementsCycle::getCurrentPeriod();
if ($currentPeriod){
return DynData::getPeriodV($x, $y,strtotime($currentPeriod['obtain_start_time']), $decVal);
}
return $decVal;
}
private function safeApiVerify() {
$aLastChar = substr(getReqVal('a', ''), -1);
if ($aLastChar != 'S') {
return;
}
$params = $_REQUEST;
ksort($params);
$signData = '';
$ignoreKeys = array(
'__nonce',
'__timestamp',
'__sign'
);
foreach($params as $key => $val){
if (!in_array($key, $ignoreKeys)) {
$signData .= $key . '=' . $val . '&';
}
}
$nonce = getReqVal('__nonce', '');
$timeStamp = getReqVal('__timestamp', '');
$sign = getReqVal('__sign', '');
$postData = file_get_contents('php://input');
if (intval($timeStamp) < myself()->_getNowTime() - 20 ||
intval($timeStamp) > myself()->_getNowTime() + 10) {
error_log('safeApiVerify timestamp error:' . $timeStamp . ' nowTime:' . myself()->_getNowTime());
myself()->_rspErr(1007, "sign error1");
die();
}
$signData .= $nonce . $timeStamp . $postData;
foreach (SAPI_SECRET_KEYS as $val) {
if (md5($signData . $val) == $sign) {
return;
}
}
myself()->_rspErr(1007, "sign error2");
die();
}
public function _fireEvent($moduleName, $eventName, ...$args)
{
return myself()->_internalCallModuleStatic('events', $moduleName, $eventName, ...$args);
}
/*
添加通用日志埋点
$prop必须是array对象不是数组{}
!!!注意eventName多人之间开发不要用重复了
*/
public function _addTgLog($eventName, $prop)
{
myself()->_callServiceStatic('LogService', 'addTgLog', $eventName, $prop);
}
public function _getVipRightsVal($type)
{
$vip = User::getVipLv(myself()->_getAddress());
return myself()->_callMtStatic('StakingVip', 'getValByLv', $vip, $type);
}
}