From 230fe7df11b0b70b1edbffc3a36dbf9401e130d6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 1 Feb 2019 17:43:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E4=BA=AB=E5=9B=BE?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/controller/KefuController.class.php | 56 +++++++++++++++------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/webapp/controller/KefuController.class.php b/webapp/controller/KefuController.class.php index 544d5e0..0b54745 100644 --- a/webapp/controller/KefuController.class.php +++ b/webapp/controller/KefuController.class.php @@ -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 ''; + } + } + }