完成sendAwardMail改造
This commit is contained in:
parent
be0443b4a2
commit
6ce1837ec1
@ -45,38 +45,6 @@ class KefuController {
|
|||||||
return require('../config/kefu.mysql.cluster.php');
|
return require('../config/kefu.mysql.cluster.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function saveAwardTimeToDB($accountid, $time)
|
|
||||||
{
|
|
||||||
$conn = $this->getMysql($accountid);
|
|
||||||
$select_tbl_name = 'accounts_kefu';
|
|
||||||
$row = $conn->execScript("UPDATE $select_tbl_name SET " .
|
|
||||||
' awardtime=:awardtime ' .
|
|
||||||
'WHERE accountid=:accountid; ',
|
|
||||||
array(
|
|
||||||
':accountid' => $accountid,
|
|
||||||
':awardtime' => $time
|
|
||||||
));
|
|
||||||
return $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getAwardtimeFromDB($accountid)
|
|
||||||
{
|
|
||||||
$conn = $this->getMysql($accountid);
|
|
||||||
$select_tbl_name = 'accounts_kefu';
|
|
||||||
$row = $conn->execQueryOne('SELECT awardtime ' .
|
|
||||||
"FROM $select_tbl_name WHERE accountid = :accountid ;",
|
|
||||||
array(
|
|
||||||
':accountid' => $accountid,
|
|
||||||
));
|
|
||||||
|
|
||||||
#error_log('getAward_row:' . json_encode($row));
|
|
||||||
if ($row) {
|
|
||||||
return $row['awardtime'];
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getAwardDBMaxIdx($conn)
|
private function getAwardDBMaxIdx($conn)
|
||||||
{
|
{
|
||||||
$select_tbl_name = 'accounts_kefu';
|
$select_tbl_name = 'accounts_kefu';
|
||||||
@ -116,16 +84,13 @@ class KefuController {
|
|||||||
$url = 'https://center.kingsome.cn/api/replays/';
|
$url = 'https://center.kingsome.cn/api/replays/';
|
||||||
}
|
}
|
||||||
$url .= $gameid . '/' . $condition;
|
$url .= $gameid . '/' . $condition;
|
||||||
#error_log($url);
|
|
||||||
$response = '';
|
$response = '';
|
||||||
$params = array();
|
$params = array();
|
||||||
if (!phpcommon\HttpClient::get($url, $params ,$response)) {
|
if (!phpcommon\HttpClient::get($url, $params ,$response)) {
|
||||||
#error_log('奖励配置发送失败');
|
|
||||||
die();
|
die();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$ret = json_decode($response, true);
|
$ret = json_decode($response, true);
|
||||||
#error_log('awardconfig:' . $response);
|
|
||||||
if ($ret['errcode'] == 0) {
|
if ($ret['errcode'] == 0) {
|
||||||
return $ret['items'];
|
return $ret['items'];
|
||||||
} else {
|
} else {
|
||||||
@ -134,65 +99,40 @@ class KefuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translateAttachments($config)
|
private function sendAwardMail($accountid, $config)
|
||||||
{
|
|
||||||
$attachments = '';
|
|
||||||
#error_log('config:' . json_encode($config));
|
|
||||||
foreach ($config as $attachment) {
|
|
||||||
#error_log('attachment:'. json_encode($attachment));
|
|
||||||
$attachments .= $attachment['item_id'] . ':' . $attachment['count'] . ';';
|
|
||||||
}
|
|
||||||
return $attachments;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkAward($accountid)
|
|
||||||
{
|
|
||||||
$awardtime = $this->getAwardtimeFromDB($accountid);
|
|
||||||
if (isset($awardtime) and time() - $awardtime > 60 * 60 * 24 * 1) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
$url = 'https://gamemail.kingsome.cn/webapp/index.php?';
|
$url = 'https://gamemail.kingsome.cn/webapp/index.php?';
|
||||||
}
|
}
|
||||||
$to = $accountid;
|
$attachments = '';
|
||||||
$from = 'kefu';
|
foreach ($config as $attachment) {
|
||||||
$mail_type = '1';
|
$attachments .= $attachment['item_id'] . ':' . $attachment['count'] . ';';
|
||||||
$mail_subtype = '0';
|
}
|
||||||
$subject = '奖励';
|
|
||||||
$content = '领取奖励';
|
|
||||||
$sendtime = time();
|
|
||||||
$ext = '';
|
|
||||||
$expire_time = time() + 60 * 60 * 24 * 1;
|
|
||||||
#error_log('congifsendaward:' . json_encode($config));
|
|
||||||
$attachments = $this->translateAttachments($config);
|
|
||||||
$game_id = phpcommon\extractGameId($accountid);
|
|
||||||
|
|
||||||
$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 = '';
|
$response = '';
|
||||||
if (!phpcommon\HttpClient::get($url, array(), $response)) {
|
if (!phpcommon\HttpClient::get($url,
|
||||||
#error_log('邮件发送失败');
|
array(
|
||||||
return;
|
'c' => 'Mail',
|
||||||
|
'a' => 'sendMail',
|
||||||
|
'to' => $accountid,
|
||||||
|
'game_id' => phpcommon\extractGameId($accountid),
|
||||||
|
'from' => '客服',
|
||||||
|
'mail_type' => '1',
|
||||||
|
'mail_subtype' => '0',
|
||||||
|
'subject' => '领奖',
|
||||||
|
'content' => '领取奖励',
|
||||||
|
'sendtime' => time(),
|
||||||
|
'ext' => '',
|
||||||
|
'expire_time' => time() + 3600 * 24,
|
||||||
|
'attachments' => $this->translateAttachments($config)
|
||||||
|
),
|
||||||
|
$response)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
$data = json_decode($response, true);
|
$data = json_decode($response, true);
|
||||||
#error_log('邮件返回:' . $response);
|
return $data && $data['errcode'] == 0;
|
||||||
if (isset($data) && $data['errcode'] == 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkServer() // 校验服务器地址URL
|
public function checkServer() // 校验服务器地址URL
|
||||||
@ -299,18 +239,11 @@ class KefuController {
|
|||||||
$text = $postStr;
|
$text = $postStr;
|
||||||
$errcode = $pc->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str);
|
$errcode = $pc->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str);
|
||||||
if ($errcode == 0) {
|
if ($errcode == 0) {
|
||||||
#error_log("加密后: " . $encryptMsg_str . "\n");
|
|
||||||
$encryptMsg = json_decode($encryptMsg_str, true);
|
$encryptMsg = json_decode($encryptMsg_str, true);
|
||||||
|
|
||||||
$errcode = $pc->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce,
|
$errcode = $pc->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce,
|
||||||
$encryptMsg_str, $postStr2);
|
$encryptMsg_str, $postStr2);
|
||||||
#error_log('#error_log:' . json_encode($errcode));
|
|
||||||
if ($errcode == 0) {
|
|
||||||
|
|
||||||
#error_log("解密后: " . $postStr2 . "\n");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
#error_log($errcode . "\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,15 +308,38 @@ class KefuController {
|
|||||||
$text = $msg['Content'];
|
$text = $msg['Content'];
|
||||||
$gameid = phpcommon\extractGameId($accountid);
|
$gameid = phpcommon\extractGameId($accountid);
|
||||||
$awardConfig = $this->getAwardConfig($gameid, $text);
|
$awardConfig = $this->getAwardConfig($gameid, $text);
|
||||||
if (isset($awardConfig)) {
|
if (!isset($awardConfig)) {
|
||||||
$checkTimeRet = $this->checkAward($accountid);
|
$this->sendMsg($accountid, array (
|
||||||
if ($checkTimeRet) {
|
"touser" => $openid,
|
||||||
$awardRet = $this->sendAward($accountid, $awardConfig);
|
"msgtype" => "text",
|
||||||
if ($awardRet) {
|
"text" => array ("content" => '回复指定文字领取奖励!')
|
||||||
$time = time();
|
));
|
||||||
$save_ret = $this->saveAwardTimeToDB($accountid, $time);
|
return;
|
||||||
if ($save_ret) {
|
}
|
||||||
#error_log('save_ret:' . $save_ret);
|
$conn = $this->getMysql($accountid);
|
||||||
|
$row = $conn->execQueryOne('SELECT awardtime ' .
|
||||||
|
"FROM accounts_kefu WHERE accountid = :accountid;",
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid,
|
||||||
|
));
|
||||||
|
if ($row && time() - $row['awardtime'] < 3600 * 24) {
|
||||||
|
$this->sendMsg($accountid, array (
|
||||||
|
"touser" => $openid,
|
||||||
|
"msgtype" => "text",
|
||||||
|
"text" => array ("content" => "一天内只能领取一次奖励!\n请明天再来!")
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->sendAwardMail($accountid, $awardConfig)) {
|
||||||
|
$ret = $conn->execScript("UPDATE accounts_kefu SET " .
|
||||||
|
' awardtime=:awardtime ' .
|
||||||
|
'WHERE accountid=:accountid; ',
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid,
|
||||||
|
':awardtime' => time()
|
||||||
|
));
|
||||||
|
if ($ret) {
|
||||||
$this->sendMsg($accountid, array (
|
$this->sendMsg($accountid, array (
|
||||||
"touser" => $openid,
|
"touser" => $openid,
|
||||||
"msgtype" => "text",
|
"msgtype" => "text",
|
||||||
@ -391,20 +347,6 @@ class KefuController {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$this->sendMsg($accountid, array (
|
|
||||||
"touser" => $openid,
|
|
||||||
"msgtype" => "text",
|
|
||||||
"text" => array ("content" => "一天内只能领取一次奖励!\n请明天再来!")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->sendMsg($accountid, array (
|
|
||||||
"touser" => $openid,
|
|
||||||
"msgtype" => "text",
|
|
||||||
"text" => array ("content" => '回复指定文字领取奖励!')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processImage($msg, $accountid)
|
private function processImage($msg, $accountid)
|
||||||
@ -441,7 +383,6 @@ class KefuController {
|
|||||||
{
|
{
|
||||||
$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);
|
|
||||||
if (!empty($access_token)) {
|
if (!empty($access_token)) {
|
||||||
return $access_token;
|
return $access_token;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user