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