kefu updata
This commit is contained in:
parent
0420d0aa69
commit
eb01bd5ecd
@ -52,7 +52,7 @@ class KefuController {
|
|||||||
|
|
||||||
private function checkAccountKefuExist($accountid)
|
private function checkAccountKefuExist($accountid)
|
||||||
{
|
{
|
||||||
$conn = $this->getMysql($accountid);
|
$conn = $this->getMysql();
|
||||||
$select_tbl_name = 'accounts_kefu';
|
$select_tbl_name = 'accounts_kefu';
|
||||||
|
|
||||||
$row = $conn->execQueryOne('SELECT accountid ' .
|
$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)
|
private function getAwardConfig($gameid, $condition)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -101,7 +138,6 @@ class KefuController {
|
|||||||
{
|
{
|
||||||
$attachments = '';
|
$attachments = '';
|
||||||
error_log('config:' . json_encode($config));
|
error_log('config:' . json_encode($config));
|
||||||
error_log('attachment0:' . $config[0]);
|
|
||||||
foreach ($config as $attachment) {
|
foreach ($config as $attachment) {
|
||||||
error_log('attachment:'. json_encode($attachment));
|
error_log('attachment:'. json_encode($attachment));
|
||||||
$attachments .= $attachment['item_id'] . ':' . $attachment['count'] . ';';
|
$attachments .= $attachment['item_id'] . ':' . $attachment['count'] . ';';
|
||||||
@ -109,6 +145,19 @@ class KefuController {
|
|||||||
return $attachments;
|
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 sendAward($accountid, $config)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -118,7 +167,7 @@ class KefuController {
|
|||||||
$url = 'https://gamemail.kingsome.cn/webapp/index.php?';
|
$url = 'https://gamemail.kingsome.cn/webapp/index.php?';
|
||||||
}
|
}
|
||||||
$to = $accountid;
|
$to = $accountid;
|
||||||
$from = 'from';
|
$from = 'kefu';
|
||||||
$mail_type = '1';
|
$mail_type = '1';
|
||||||
$mail_subtype = '0';
|
$mail_subtype = '0';
|
||||||
$subject = '奖励';
|
$subject = '奖励';
|
||||||
@ -137,14 +186,14 @@ class KefuController {
|
|||||||
error_log('sendAward.url:' . $url);
|
error_log('sendAward.url:' . $url);
|
||||||
|
|
||||||
$response = '';
|
$response = '';
|
||||||
error_log();
|
|
||||||
if (!phpcommon\HttpClient::get($url, array(), $response)) {
|
if (!phpcommon\HttpClient::get($url, array(), $response)) {
|
||||||
error_log('邮件发送失败');
|
error_log('邮件发送失败');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$data = json_decode($response, true);
|
$data = json_decode($response, true);
|
||||||
error_log('邮件返回:' . $response);
|
error_log('邮件返回:' . $response);
|
||||||
if(isset($data) && $data['ErrorCode'] == 0) {
|
if(isset($data) && $data['errcode'] == 0) {
|
||||||
return true;
|
return true;
|
||||||
} else{
|
} else{
|
||||||
return;
|
return;
|
||||||
@ -202,7 +251,7 @@ class KefuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sendMsg()
|
private function encryptJson()
|
||||||
{
|
{
|
||||||
$pc2 = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID);
|
$pc2 = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID);
|
||||||
$encryptMsg = '';
|
$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)
|
private function disposeText($postArr, $accountid)
|
||||||
{
|
{
|
||||||
error_log('text');
|
error_log('text');
|
||||||
@ -234,9 +325,32 @@ class KefuController {
|
|||||||
$awardConfig = $this->getAwardConfig($gameid, $test);
|
$awardConfig = $this->getAwardConfig($gameid, $test);
|
||||||
error_log('awardConfig:' . json_encode($awardConfig));
|
error_log('awardConfig:' . json_encode($awardConfig));
|
||||||
if (isset($awardConfig)) {
|
if (isset($awardConfig)) {
|
||||||
|
$checkTimeRet = $this->checkAward($accountid);
|
||||||
|
if ($checkTimeRet)
|
||||||
|
{
|
||||||
$awardRet = $this->sendAward($accountid, $awardConfig);
|
$awardRet = $this->sendAward($accountid, $awardConfig);
|
||||||
if ($awardRet) {
|
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);
|
$this->insertKefuInfoToDB($accountid, $kefu_info);
|
||||||
}
|
}
|
||||||
$content = '您好,有什么能帮助你? 回复【1】领取奖励。 ' ;
|
$content = '您好,有什么能帮助你? 回复【111】领取奖励。 ' ;
|
||||||
$data = array (
|
$data = array (
|
||||||
"touser"=> $openid,
|
"touser" => $openid,
|
||||||
"msgtype"=>"text",
|
"msgtype" => "text",
|
||||||
"text"=> array ("content" => $content)
|
"text" => array ("content" => $content)
|
||||||
);
|
);
|
||||||
$postarray = json_encode( $data ,JSON_UNESCAPED_UNICODE);
|
$this->sendMsg($data);
|
||||||
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($response);
|
|
||||||
if ($ret_info['errcode'] == 0) {
|
|
||||||
echo(json_encode(array(
|
|
||||||
'errcode' => 0,
|
|
||||||
'errmsg' => ''
|
|
||||||
)));
|
|
||||||
exit ;
|
|
||||||
} else {
|
|
||||||
phpcommon\sendError(ERR_RETRY, 'token失败');
|
|
||||||
error_log($response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user