This commit is contained in:
aozhiwei 2019-07-29 15:51:06 +08:00
parent dd2458c21f
commit d1bbfce14e

View File

@ -169,6 +169,7 @@ class KefuController {
public function notifyAllUser() public function notifyAllUser()
{ {
$media_conf = array();
$dbconfs = require('../config/kefu.mysql.cluster.php');; $dbconfs = require('../config/kefu.mysql.cluster.php');;
foreach($dbconfs as $dbconf) { foreach($dbconfs as $dbconf) {
$conn = new phpcommon\Mysql(array( $conn = new phpcommon\Mysql(array(
@ -178,7 +179,7 @@ class KefuController {
'passwd' => $dbconf['passwd'], 'passwd' => $dbconf['passwd'],
'dbname' => 'kefudb' . $dbconf['instance_id'] 'dbname' => 'kefudb' . $dbconf['instance_id']
)); ));
$this->sendOneDBInfo($conn); $this->sendOneDBInfo($conn, $media_conf);
} }
} }
@ -220,28 +221,29 @@ class KefuController {
return !empty($ret_info) && $ret_info['errcode'] == 0; return !empty($ret_info) && $ret_info['errcode'] == 0;
} }
private function sendOneDBInfo($conn) private function sendOneDBInfo($conn, &$media_conf)
{ {
$mediaId = $this->getMediaId(2001);
$last_idx = 0; $last_idx = 0;
$share_conf = require('../config/kefu.share.config.php');
while (true) { while (true) {
$rows = $conn->execQuery('SELECT idx, accountid, openid, awardtime ' . $rows = $conn->execQuery('SELECT idx, accountid, openid, awardtime, gameid ' .
"FROM accounts WHERE idx > :last_idx LIMIT 0, 1000;", "FROM accounts WHERE idx > :last_idx LIMIT 0, 1000;",
array( array(
':last_idx' => $last_idx, ':last_idx' => $last_idx,
)); ));
if (!$rows || count($rows) <= 0) { if ($rows) {
break;
}
foreach ($rows as $row) { foreach ($rows as $row) {
$shareInfo = require('../config/kefu.share.config.php'); if (isset($share_conf[$row['gameid']])) {
$shareInfo[2001]['thumb_media_id'] = $mediaId; $game_conf = $share_conf[$row['gameid']];
$gameid = phpcommon\extractGameId($row['accountid']); if (!isset($media_conf[$row['gameid']])) {
$media_conf['gameid'] = $this->getMediaId($row['gameid']);
}
$game_conf['thumb_media_id'] = $media_conf[$row['gameid']];
$this->sendKefuMsg($row['accountid'], $this->sendKefuMsg($row['accountid'],
array ( array (
"touser" => $row['openid'], "touser" => $row['openid'],
"msgtype" => "miniprogrampage", "msgtype" => "miniprogrampage",
"miniprogrampage" => $shareInfo[$gameid] "miniprogrampage" => $game_conf
)); ));
if ($row['idx'] > $last_idx) { if ($row['idx'] > $last_idx) {
@ -250,6 +252,8 @@ class KefuController {
} }
} }
} }
}
}
private function processText($msg, $accountid) private function processText($msg, $accountid)
{ {
@ -375,12 +379,12 @@ class KefuController {
$type = "image"; $type = "image";
$filepath = "../config/game$gameid/share.jpg"; $filepath = "../config/game$gameid/share.jpg";
$filedata = array( $filedata = array(
"media" => "@".$filepath "media" => "@" . $filepath
); );
$access_token = $this->getAccessToken($gameid); $access_token = $this->getAccessToken($gameid);
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=$type"; $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=$type";
$response = ''; $response = '';
if (phpcommon\upload($url, $filedata, $response)) { if (phpcommon\HttpClient::upload($url, $filedata, $response)) {
$jsonobj = json_decode($response, true); $jsonobj = json_decode($response, true);
if(isset($jsonobj['media_id'])) { if(isset($jsonobj['media_id'])) {
return $jsonobj['media_id']; return $jsonobj['media_id'];