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