修复分享图问题
This commit is contained in:
parent
f4a1bceab2
commit
230fe7df11
@ -153,19 +153,6 @@ class KefuController {
|
||||
|
||||
public function notifyAllUser()
|
||||
{
|
||||
if (phpcommon\md5Sign(array
|
||||
(
|
||||
'key' => 'kingsome'
|
||||
),
|
||||
'fc38349c5d084e920925e614c420be9f',
|
||||
$_REQUEST['timestamp']
|
||||
) != $_REQUEST['sign']) {
|
||||
echo json_encode(array(
|
||||
'errcode' => 100,
|
||||
'errmsg' => '签名错误',
|
||||
));
|
||||
return;
|
||||
}
|
||||
$dbconfs = require('../config/kefu.mysql.cluster.php');;
|
||||
foreach($dbconfs as $dbconf) {
|
||||
$conn = new phpcommon\Mysql(array(
|
||||
@ -200,7 +187,8 @@ class KefuController {
|
||||
|
||||
private function sendKefuMsg($accountid, $data)
|
||||
{
|
||||
$access_token = $this->getAccessToken($accountid);
|
||||
$gameid = phpcommon\extractGameId($accountid);
|
||||
$access_token = $this->getAccessToken($gameid);
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
|
||||
|
||||
$response = '';
|
||||
@ -217,6 +205,7 @@ class KefuController {
|
||||
|
||||
private function sendOneDBInfo($conn)
|
||||
{
|
||||
$mediaId = $this->getMediaId(3003);
|
||||
$last_idx = 0;
|
||||
while (true) {
|
||||
$rows = $conn->execQuery('SELECT idx, accountid, openid, awardtime ' .
|
||||
@ -229,6 +218,7 @@ class KefuController {
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$shareInfo = require('../config/kefu.share.config.php');
|
||||
$shareInfo[3003]['thumb_media_id'] = $mediaId;
|
||||
$gameid = phpcommon\extractGameId($row['accountid']);
|
||||
$this->sendKefuMsg($row['accountid'],
|
||||
array (
|
||||
@ -326,9 +316,8 @@ class KefuController {
|
||||
}
|
||||
}
|
||||
|
||||
private function getAccessToken($accountid)
|
||||
private function getAccessToken($gameid)
|
||||
{
|
||||
$gameid = phpcommon\extractGameId($accountid);
|
||||
$r = $this->getRedis($gameid);
|
||||
$access_token = $r->get('kf_token:' . $gameid . ':');
|
||||
if (!empty($access_token)) {
|
||||
@ -357,4 +346,39 @@ class KefuController {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function https_request($url, $data = null)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
#curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
if (!empty($data)){
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getMediaId($gameid)
|
||||
{
|
||||
$type = "image";
|
||||
$filepath = "../config/game3003/share.jpg";
|
||||
$filedata = array(
|
||||
"media" => "@".$filepath
|
||||
);
|
||||
$access_token = $this->getAccessToken($gameid);
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=$type";
|
||||
$res_str = $this->https_request($url, $filedata);
|
||||
$res = json_decode($res_str, true);
|
||||
if(isset($res['media_id'])) {
|
||||
return $res['media_id'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user