123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * 第三方接口
- * User: solu
- * Date: 2018/12/10
- * Time: 4:40 PM
- */
- class ThirdApi {
- /**
- * 上报游戏结果
- * @author solu
- * @param $gameId
- * @param $betAmount
- * @param $winAmount
- * @param string $appid
- * @return mixed
- */
- public static function reportGameResult($gameId, $betAmount, $winAmount, $appid = 'box') {
- $api = URL_SICBO . 'eos/gameResult';
- $data = [
- 'gameid' => $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;
- }
- }
|