$gameId, 'game_name' => $appid, 'bet_amount' => $betAmount, 'win_amount' => $winAmount, ]; $objEosAES = new EosAES($GLOBALS['codeGtAdmin']); $objHttp = new dwHttp(); $seed = "{$appid}|{$gameId}"; $data['sign'] = $objEosAES->encode($seed); $resp = $objHttp->post2($api, $data); return json_decode($resp, true); } /** * 推送事件 * @author solu * @param $channel * @param $data * @param null $objRedis * @return int */ public static function event($channel, $data, $objRedis = null) { !$objRedis && $objRedis = dwRedis::initNewOne(); if (is_array($data)) { $data = json_encode($data); } return $objRedis->publish($channel, $data); } public static function pushPersonEvent($to, array $data) { $channel = "chat:person:{$to}"; !$data['timestamp'] && $data['timestamp'] = Session::getMS(); return self::event($channel, $data); } public static function pushGroupEvent($groupId, array $data) { $channel = 'chat:group'; // 全局 !$data['timestamp'] && $data['timestamp'] = Session::getMS(); $data['group_id'] = (int) $groupId; $groupId > 0 && $channel .= ":{$groupId}"; return self::event($channel, $data); } /** * 校验Telegram数据合法性 * @param $auth_data * @return mixed * @throws Exception */ public static function checkTelegramAuthorization($auth_data) { $check_hash = $auth_data['hash']; unset($auth_data['hash']); $data_check_arr = []; foreach ($auth_data as $key => $value) { $data_check_arr[] = $key . '=' . $value; } sort($data_check_arr); $data_check_string = implode("\n", $data_check_arr); $secret_key = hash('sha256', BOT_TOKEN, true); $hash = hash_hmac('sha256', $data_check_string, $secret_key); if (strcmp($hash, $check_hash) !== 0) { throw new Exception('Data is NOT from Telegram'); } if ((time() - $auth_data['auth_date']) > 86400) { throw new Exception('Data is outdated'); } return $auth_data; } }