ThirdApi.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * 第三方接口
  4. * User: solu
  5. * Date: 2018/12/10
  6. * Time: 4:40 PM
  7. */
  8. class ThirdApi {
  9. /**
  10. * 上报游戏结果
  11. * @author solu
  12. * @param $gameId
  13. * @param $betAmount
  14. * @param $winAmount
  15. * @param string $appid
  16. * @return mixed
  17. */
  18. public static function reportGameResult($gameId, $betAmount, $winAmount, $appid = 'box') {
  19. $api = URL_SICBO . 'eos/gameResult';
  20. $data = [
  21. 'gameid' => $gameId,
  22. 'game_name' => $appid,
  23. 'bet_amount' => $betAmount,
  24. 'win_amount' => $winAmount,
  25. ];
  26. $objEosAES = new EosAES($GLOBALS['codeGtAdmin']);
  27. $objHttp = new dwHttp();
  28. $seed = "{$appid}|{$gameId}";
  29. $data['sign'] = $objEosAES->encode($seed);
  30. $resp = $objHttp->post2($api, $data);
  31. return json_decode($resp, true);
  32. }
  33. /**
  34. * 推送事件
  35. * @author solu
  36. * @param $channel
  37. * @param $data
  38. * @param null $objRedis
  39. * @return int
  40. */
  41. public static function event($channel, $data, $objRedis = null) {
  42. !$objRedis && $objRedis = dwRedis::initNewOne();
  43. if (is_array($data)) {
  44. $data = json_encode($data);
  45. }
  46. return $objRedis->publish($channel, $data);
  47. }
  48. public static function pushPersonEvent($to, array $data) {
  49. $channel = "chat:person:{$to}";
  50. !$data['timestamp'] && $data['timestamp'] = Session::getMS();
  51. return self::event($channel, $data);
  52. }
  53. public static function pushGroupEvent($groupId, array $data) {
  54. $channel = 'chat:group'; // 全局
  55. !$data['timestamp'] && $data['timestamp'] = Session::getMS();
  56. $data['group_id'] = (int) $groupId;
  57. $groupId > 0 && $channel .= ":{$groupId}";
  58. return self::event($channel, $data);
  59. }
  60. }