代码格式重构

This commit is contained in:
aozhiwei 2019-01-25 15:13:39 +08:00
parent 61b12e3ec7
commit 76ca871aa3

View File

@ -6,7 +6,6 @@ class KefuController {
protected function getRedis($accountid) protected function getRedis($accountid)
{ {
$redis_conf = getRedisConfig(crc32($accountid)); $redis_conf = getRedisConfig(crc32($accountid));
$r = new phpcommon\Redis(array( $r = new phpcommon\Redis(array(
'host' => $redis_conf['host'], 'host' => $redis_conf['host'],
@ -46,7 +45,6 @@ class KefuController {
return require('../config/kefu.mysql.cluster.php'); return require('../config/kefu.mysql.cluster.php');
} }
#kefudb_info = array(accountid, channel, gameid, openid, awardtime) #kefudb_info = array(accountid, channel, gameid, openid, awardtime)
private function insertKefuInfoToDB($accountid, $kefu_info) private function insertKefuInfoToDB($accountid, $kefu_info)
{ {
@ -79,7 +77,7 @@ class KefuController {
#error_log('check_Exist:' . json_encode($row)); #error_log('check_Exist:' . json_encode($row));
if ($row) { if ($row) {
return $row; return $row;
}else{ } else {
return ''; return '';
} }
} }
@ -102,7 +100,6 @@ class KefuController {
private function getAwardtimeFromDB($accountid) private function getAwardtimeFromDB($accountid)
{ {
$conn = $this->getMysql($accountid); $conn = $this->getMysql($accountid);
$select_tbl_name = 'accounts_kefu'; $select_tbl_name = 'accounts_kefu';
$row = $conn->execQueryOne('SELECT awardtime ' . $row = $conn->execQueryOne('SELECT awardtime ' .
@ -117,7 +114,6 @@ class KefuController {
} else { } else {
return ''; return '';
} }
} }
private function getAwardDBMaxIdx($conn) private function getAwardDBMaxIdx($conn)
@ -131,12 +127,10 @@ class KefuController {
} else { } else {
return ''; return '';
} }
} }
private function getAccountsKefuInfo($min_idx, $max_idx, $conn) private function getAccountsKefuInfo($min_idx, $max_idx, $conn)
{ {
$select_tbl_name = 'accounts_kefu'; $select_tbl_name = 'accounts_kefu';
$row = $conn->execQuery("SELECT * FROM $select_tbl_name " . $row = $conn->execQuery("SELECT * FROM $select_tbl_name " .
"WHERE idx >= :min_idx AND idx < :max_idx;", "WHERE idx >= :min_idx AND idx < :max_idx;",
@ -150,13 +144,10 @@ class KefuController {
} else { } else {
return ''; return '';
} }
} }
private function getAwardConfig($gameid, $condition) private function getAwardConfig($gameid, $condition)
{ {
$url = ''; $url = '';
if (SERVER_ENV != _ONLINE) { if (SERVER_ENV != _ONLINE) {
$url = 'https://center-test.kingsome.cn/api/replays/'; $url = 'https://center-test.kingsome.cn/api/replays/';
@ -174,13 +165,12 @@ class KefuController {
} }
$ret = json_decode($response, true); $ret = json_decode($response, true);
#error_log('awardconfig:' . $response); #error_log('awardconfig:' . $response);
if($ret['errcode'] == 0) { if ($ret['errcode'] == 0) {
return $ret['items']; return $ret['items'];
} else { } else {
return; return;
die(); die();
} }
} }
private function translateAttachments($config) private function translateAttachments($config)
@ -194,8 +184,6 @@ class KefuController {
return $attachments; return $attachments;
} }
private function checkAward($accountid) private function checkAward($accountid)
{ {
$awardtime = $this->getAwardtimeFromDB($accountid); $awardtime = $this->getAwardtimeFromDB($accountid);
@ -206,10 +194,8 @@ class KefuController {
} }
} }
private function sendAward($accountid, $config) private function sendAward($accountid, $config)
{ {
if (SERVER_ENV != _ONLINE) { if (SERVER_ENV != _ONLINE) {
$url = 'https://gamemail-test.kingsome.cn/webapp/index.php?'; $url = 'https://gamemail-test.kingsome.cn/webapp/index.php?';
} else { } else {
@ -231,7 +217,6 @@ class KefuController {
$url .= "c=Mail&a=sendMail&to=$to&from=$from&mail_type=$mail_type" . $url .= "c=Mail&a=sendMail&to=$to&from=$from&mail_type=$mail_type" .
"&mail_subtype=$mail_subtype&subject=$subject&content=$content&sendtime=$sendtime" . "&mail_subtype=$mail_subtype&subject=$subject&content=$content&sendtime=$sendtime" .
"&ext=$ext&expire_time=$expire_time&attachments=$attachments&game_id=$game_id"; "&ext=$ext&expire_time=$expire_time&attachments=$attachments&game_id=$game_id";
#error_log('sendAward.url:' . $url); #error_log('sendAward.url:' . $url);
$response = ''; $response = '';
@ -241,33 +226,55 @@ class KefuController {
} }
$data = json_decode($response, true); $data = json_decode($response, true);
#error_log('邮件返回:' . $response); #error_log('邮件返回:' . $response);
if(isset($data) && $data['errcode'] == 0) { if (isset($data) && $data['errcode'] == 0) {
return true; return true;
} else{ } else {
return; return;
} }
} }
public function checkServer() // 校验服务器地址URL public function checkServer() // 校验服务器地址URL
{ {
$gameid = $_REQUEST['gameid']; $gameid = $_REQUEST['gameid'];
#error_log($gameid); #error_log($gameid);
$config_name = "../config/game$gameid/weixin/config.php"; $config_name = "../config/game$gameid/weixin/config.php";
require $config_name; require $config_name;
if ( isset($_REQUEST['echostr'])) { if (isset($_REQUEST['echostr'])) {
$this->valid(); $this->valid();
} else { } else {
$this->responseMsg(); $this->responseMsg();
} }
}
public function sendMsgAllUser()
{
error_log('sendMsgAllUser:');
error_log('request:' . json_encode($_REQUEST));
if (phpcommon\md5Sign(array
(
'exclude_accountids' => $_REQUEST['key']
),
'fc38349c5d084e920925e614c420be9f',
$_REQUEST['timestamp']
) != $_REQUEST['sign']) {
echo json_encode(array(
'errcode' => 100,
'errmsg' => '签名错误',
));
return;
}
$mysqls = $this->getAllMysql();
foreach($mysqls as $mysql_conf) {
$conn = $this->getAppointMysql($mysql_conf);
$minIdx = 10000;
$maxIdx = $this->getAwardDBMaxIdx($conn);
$this->sendOneDBInfo($minIdx, $maxIdx, $conn);
}
} }
private function valid() private function valid()
{ {
$echoStr = $_REQUEST['echostr']; $echoStr = $_REQUEST['echostr'];
if ($this->checkSignature()) { if ($this->checkSignature()) {
echo $echoStr; echo $echoStr;
@ -276,7 +283,6 @@ class KefuController {
echo $echoStr . '+++' . WEIXIN_TOKEN; echo $echoStr . '+++' . WEIXIN_TOKEN;
exit; exit;
} }
} }
private function checkSignature() private function checkSignature()
@ -318,7 +324,6 @@ class KefuController {
} else { } else {
#error_log($errCode . "\n"); #error_log($errCode . "\n");
} }
} }
private function sendMsg($data, $accountid) private function sendMsg($data, $accountid)
@ -347,7 +352,6 @@ class KefuController {
private function sendMsgSomeUser($arrayInfo) private function sendMsgSomeUser($arrayInfo)
{ {
foreach($arrayInfo as $userInfo) { foreach($arrayInfo as $userInfo) {
$shareInfo = require('../config/kefu.share.config.php'); $shareInfo = require('../config/kefu.share.config.php');
$miniprogrampateInfo = $shareInfo['1011']; $miniprogrampateInfo = $shareInfo['1011'];
$data = array ( $data = array (
@ -376,36 +380,8 @@ class KefuController {
$this->sendMsgSomeUser($arrayInfo); $this->sendMsgSomeUser($arrayInfo);
$selectMin = $selectMin + $selectOneCount; $selectMin = $selectMin + $selectOneCount;
} }
} }
public function sendMsgAllUser()
{
error_log('sendMsgAllUser:');
error_log('request:' . json_encode($_REQUEST));
if (phpcommon\md5Sign(array
(
'exclude_accountids' => $_REQUEST['key']
),
'fc38349c5d084e920925e614c420be9f',
$_REQUEST['timestamp']
) != $_REQUEST['sign']) {
echo json_encode(array(
'errcode' => 100,
'errmsg' => '签名错误',
));
return;
}
$mysqls = $this->getAllMysql();
foreach($mysqls as $mysql_conf) {
$conn = $this->getAppointMysql($mysql_conf);
$minIdx = 10000;
$maxIdx = $this->getAwardDBMaxIdx($conn);
$this->sendOneDBInfo($minIdx, $maxIdx, $conn);
}
}
private function disposeText($postArr, $accountid) private function disposeText($postArr, $accountid)
{ {
#error_log('text'); #error_log('text');
@ -417,8 +393,7 @@ class KefuController {
#error_log('awardConfig:' . json_encode($awardConfig)); #error_log('awardConfig:' . json_encode($awardConfig));
if (isset($awardConfig)) { if (isset($awardConfig)) {
$checkTimeRet = $this->checkAward($accountid); $checkTimeRet = $this->checkAward($accountid);
if ($checkTimeRet) if ($checkTimeRet) {
{
$awardRet = $this->sendAward($accountid, $awardConfig); $awardRet = $this->sendAward($accountid, $awardConfig);
if ($awardRet) { if ($awardRet) {
$time = time(); $time = time();
@ -452,7 +427,6 @@ class KefuController {
); );
$this->sendMsg($data, $accountid); $this->sendMsg($data, $accountid);
} }
} }
private function disposeImage($postArr, $accountid) private function disposeImage($postArr, $accountid)
@ -465,13 +439,11 @@ class KefuController {
private function disposeEvent($postArr, $accountid) private function disposeEvent($postArr, $accountid)
{ {
#error_log('disposeEvent'); #error_log('disposeEvent');
$openid = $postArr['FromUserName']; $openid = $postArr['FromUserName'];
$CreateTime = $postArr['CreateTime']; $CreateTime = $postArr['CreateTime'];
if($postArr['Event'] == 'user_enter_tempsession') if ($postArr['Event'] == 'user_enter_tempsession') {
{
$check_ret = $this->checkAccountKefuExist($accountid); $check_ret = $this->checkAccountKefuExist($accountid);
#error_log('check_ret:' . json_encode($check_ret)); #error_log('check_ret:' . json_encode($check_ret));
if (empty($check_ret)) { if (empty($check_ret)) {
@ -499,7 +471,7 @@ class KefuController {
private function responseMsg() private function responseMsg()
{ {
$postStr_key = $GLOBALS ["HTTP_RAW_POST_DATA" ]; $postStr_key = $GLOBALS["HTTP_RAW_POST_DATA"];
#error_log('!!!begin:' . $postStr_key); #error_log('!!!begin:' . $postStr_key);
#error_log('request:' . json_encode($_REQUEST)); #error_log('request:' . json_encode($_REQUEST));
@ -514,11 +486,8 @@ class KefuController {
$errCode = $pc->decryptJsonMsg($msg_sign, $timeStamp, $nonce, $postStr_key, $postStr); $errCode = $pc->decryptJsonMsg($msg_sign, $timeStamp, $nonce, $postStr_key, $postStr);
#error_log('#error_log:' . json_encode($errCode)); #error_log('#error_log:' . json_encode($errCode));
if ($errCode == 0) { if ($errCode == 0) {
#error_log("解密后: " . $postStr . "\n"); #error_log("解密后: " . $postStr . "\n");
if (!empty( $postStr ) && is_string( $postStr )){ if (!empty( $postStr ) && is_string( $postStr )){
$postArr = json_decode( $postStr , true ); $postArr = json_decode( $postStr , true );
$accountid = phpcommon\createAccountId(6001, $gameid, $postArr['FromUserName']); $accountid = phpcommon\createAccountId(6001, $gameid, $postArr['FromUserName']);
@ -531,28 +500,23 @@ class KefuController {
} else { } else {
exit (); exit ();
} }
} else { } else {
echo "" ; echo "" ;
exit ; exit ;
} }
} else { } else {
#error_log($errCode . "\n"); #error_log($errCode . "\n");
} }
} }
private function getAccessToken($accountid) private function getAccessToken($accountid)
{ {
$r = $this->getRedis($accountid); $r = $this->getRedis($accountid);
$access_token = $r->get('kf_token:' . $accountid . ':'); $access_token = $r->get('kf_token:' . $accountid . ':');
#error_log('acc_token:' . $access_token); #error_log('acc_token:' . $access_token);
if (!empty($access_token)) { if (!empty($access_token)) {
return $access_token; return $access_token;
} } else {
else {
$gameid = phpcommon\extractGameId($accountid); $gameid = phpcommon\extractGameId($accountid);
$config_name = "../config/game$gameid/weixin/config.php"; $config_name = "../config/game$gameid/weixin/config.php";
@require $config_name; @require $config_name;
@ -576,7 +540,7 @@ class KefuController {
$r->pexpire('kf_token:' . $accountid . ':', 1000 * ($res['expires_in'] - 60 * 1)); $r->pexpire('kf_token:' . $accountid . ':', 1000 * ($res['expires_in'] - 60 * 1));
return $res['access_token']; return $res['access_token'];
} else { } else {
die; die();
} }
} }