kefu updata

This commit is contained in:
aozhiwei 2019-01-21 15:42:23 +08:00
parent 0420d0aa69
commit eb01bd5ecd

View File

@ -52,7 +52,7 @@ class KefuController {
private function checkAccountKefuExist($accountid)
{
$conn = $this->getMysql($accountid);
$conn = $this->getMysql();
$select_tbl_name = 'accounts_kefu';
$row = $conn->execQueryOne('SELECT accountid ' .
@ -68,6 +68,43 @@ class KefuController {
}
}
private function saveAwardTimeToDB($accountid, $time)
{
$conn = $this->getMysql();
$select_tbl_name = 'accounts_kefu';
$row = $conn->execScript("UPDATE $select_tbl_name SET " .
' awardtime=:awardtime ' .
'WHERE accountid=:accountid; ',
array(
':accountid' => $accountid,
':awardtime' => $time
)
);
error_log('award_check_row:' . json_encode($row));
return $row;
}
private function getAwardtimeFromDB($accountid)
{
$conn = $this->getMysql();
$select_tbl_name = 'accounts_kefu';
$row = $conn->execQueryOne('SELECT awardtime ' .
"FROM $select_tbl_name WHERE accountid = :accountid ;",
array(
':accountid' => $accountid,
));
error_log('checkAward_row:' . json_encode($row));
if ($row) {
return $row['awardtime'];
} else {
return '';
}
}
private function getAwardConfig($gameid, $condition)
{
@ -101,7 +138,6 @@ class KefuController {
{
$attachments = '';
error_log('config:' . json_encode($config));
error_log('attachment0:' . $config[0]);
foreach ($config as $attachment) {
error_log('attachment:'. json_encode($attachment));
$attachments .= $attachment['item_id'] . ':' . $attachment['count'] . ';';
@ -109,6 +145,19 @@ class KefuController {
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)
{
@ -118,7 +167,7 @@ class KefuController {
$url = 'https://gamemail.kingsome.cn/webapp/index.php?';
}
$to = $accountid;
$from = 'from';
$from = 'kefu';
$mail_type = '1';
$mail_subtype = '0';
$subject = '奖励';
@ -137,14 +186,14 @@ class KefuController {
error_log('sendAward.url:' . $url);
$response = '';
error_log();
if (!phpcommon\HttpClient::get($url, array(), $response)) {
error_log('邮件发送失败');
return;
}
$data = json_decode($response, true);
error_log('邮件返回:' . $response);
if(isset($data) && $data['ErrorCode'] == 0) {
if(isset($data) && $data['errcode'] == 0) {
return true;
} else{
return;
@ -202,7 +251,7 @@ class KefuController {
}
}
private function sendMsg()
private function encryptJson()
{
$pc2 = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID);
$encryptMsg = '';
@ -224,6 +273,48 @@ class KefuController {
}
private function sendMsg($data)
{
$postarray = json_encode( $data ,JSON_UNESCAPED_UNICODE);
error_log($postarray);
//POST发送https请求客服接口api
$access_token = $this->getAccessToken($openid, $accountid);
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
error_log('aturl:' . $url);
$response = '';
if (!phpcommon\HttpClient::post($url, $postarray, $response)) {
phpcommon\sendError(ERR_RETRY, '系统繁忙');
return;
}
$ret_info = json_decode($response, true);
error_log('sendMsg:' . $response);
if ($ret_info['errcode'] == 0) {
exit ;
} else {
error_log($response);
echo(json_encode(array(
'errcode' => 0,
'errmsg' => ''
)));
}
}
public function mytest()
{
error_log('mytest');
$content = 'hahah';
$data = array (
"touser"=> $_REQUEST['openid'],
"msgtype"=>"text",
"text"=> array ("content" => $content)
);
$this->sendMsg($data);
}
private function disposeText($postArr, $accountid)
{
error_log('text');
@ -234,9 +325,32 @@ class KefuController {
$awardConfig = $this->getAwardConfig($gameid, $test);
error_log('awardConfig:' . json_encode($awardConfig));
if (isset($awardConfig)) {
$checkTimeRet = $this->checkAward($accountid);
if ($checkTimeRet)
{
$awardRet = $this->sendAward($accountid, $awardConfig);
if ($awardRet) {
error_log('发送奖励成功!');
$time = time();
$save_ret = $this->saveAwardTimeToDB($accountid, $time);
if ($save_ret) {
error_log('save_ret:' . $save_ret);
$content = '奖励领取成功,请查收邮件!';
$data = array (
"touser" => $openid,
"msgtype" => "text",
"text" => array ("content" => $content)
);
$this->sendMsg($data);
}
}
} else {
$content = '一天内只能领取一次奖励!';
$data = array (
"touser" => $openid,
"msgtype" => "text",
"text" => array ("content" => $content)
);
$this->sendMsg($data);
}
}
}
@ -273,36 +387,14 @@ class KefuController {
);
$this->insertKefuInfoToDB($accountid, $kefu_info);
}
$content = '您好,有什么能帮助你? 回复【1】领取奖励。 ' ;
$content = '您好,有什么能帮助你? 回复【111】领取奖励。 ' ;
$data = array (
"touser" => $openid,
"msgtype" => "text",
"text" => array ("content" => $content)
);
$postarray = json_encode( $data ,JSON_UNESCAPED_UNICODE);
error_log($postarray);
$this->sendMsg($data);
//POST发送https请求客服接口api
$access_token = $this->getAccessToken($openid, $accountid);
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
error_log('aturl:' . $url);
$response = '';
if (!phpcommon\HttpClient::post($url, $postarray, $response)) {
phpcommon\sendError(ERR_RETRY, '系统繁忙');
return;
}
$ret_info = json_decode($response, true);
error_log($response);
if ($ret_info['errcode'] == 0) {
echo(json_encode(array(
'errcode' => 0,
'errmsg' => ''
)));
exit ;
} else {
phpcommon\sendError(ERR_RETRY, 'token失败');
error_log($response);
}
}
}