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()
{
$media_conf = array();
$dbconfs = require('../config/kefu.mysql.cluster.php');;
foreach($dbconfs as $dbconf) {
$conn = new phpcommon\Mysql(array(
@ -178,7 +179,7 @@ class KefuController {
'passwd' => $dbconf['passwd'],
'dbname' => 'kefudb' . $dbconf['instance_id']
));
$this->sendOneDBInfo($conn);
$this->sendOneDBInfo($conn, $media_conf);
}
}
@ -220,32 +221,35 @@ class KefuController {
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;
$share_conf = require('../config/kefu.share.config.php');
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;",
array(
':last_idx' => $last_idx,
));
if (!$rows || count($rows) <= 0) {
break;
}
foreach ($rows as $row) {
$shareInfo = require('../config/kefu.share.config.php');
$shareInfo[2001]['thumb_media_id'] = $mediaId;
$gameid = phpcommon\extractGameId($row['accountid']);
$this->sendKefuMsg($row['accountid'],
array (
"touser" => $row['openid'],
"msgtype" => "miniprogrampage",
"miniprogrampage" => $shareInfo[$gameid]
));
if ($rows) {
foreach ($rows as $row) {
if (isset($share_conf[$row['gameid']])) {
$game_conf = $share_conf[$row['gameid']];
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'],
array (
"touser" => $row['openid'],
"msgtype" => "miniprogrampage",
"miniprogrampage" => $game_conf
));
if ($row['idx'] > $last_idx) {
$last_idx = $row['idx'];
if ($row['idx'] > $last_idx) {
$last_idx = $row['idx'];
}
}
}
}
}
@ -375,12 +379,12 @@ class KefuController {
$type = "image";
$filepath = "../config/game$gameid/share.jpg";
$filedata = array(
"media" => "@".$filepath
"media" => "@" . $filepath
);
$access_token = $this->getAccessToken($gameid);
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=$type";
$response = '';
if (phpcommon\upload($url, $filedata, $response)) {
if (phpcommon\HttpClient::upload($url, $filedata, $response)) {
$jsonobj = json_decode($response, true);
if(isset($jsonobj['media_id'])) {
return $jsonobj['media_id'];