AtmosferaService.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <?php
  2. namespace App\Game\Services;
  3. use App\Util;
  4. use GuzzleHttp\Client;
  5. class AtmosferaService
  6. {
  7. protected $client;
  8. protected $baseUrl;
  9. protected $privateKey;
  10. protected $contractor;
  11. public function __construct()
  12. {
  13. $this->client = new Client();
  14. $this->baseUrl = "https://atmob2b.net";
  15. $this->privateKey = "PqcOolNF5gusaMiQGxzOIrSey3qp0Adw";
  16. $this->contractor = 105;
  17. // $this->baseUrl = "https://api-bb.igramba.com:30445";
  18. // $this->privateKey = "c48BgNi8p8xsebe0wGMGhICfDeyo0Xzx";
  19. // $this->contractor = 105;
  20. }
  21. // 生成SHA256签名
  22. protected function generateSignature($time, $data)
  23. {
  24. return hash('sha256', $time . json_encode($data) . $this->privateKey);
  25. }
  26. public function checkSignature($post)
  27. {
  28. Util::WriteLog('24680_atmosfera',$post);
  29. return true;
  30. $hash = hash('sha256', $post['time'] . $post['data'] . $this->privateKey);
  31. return $hash === $post['hash'];
  32. }
  33. // 发送POST请求
  34. protected function postRequest($endpoint, $time, $data)
  35. {
  36. $hash = $this->generateSignature($time, $data);
  37. $post = [
  38. 'contractor' => $this->contractor,
  39. 'version' => 3,
  40. 'time' => $time,
  41. 'data' => json_encode($data),
  42. 'hash' => $hash
  43. ];
  44. // echo $this->baseUrl . $endpoint;
  45. // echo "\r\n";
  46. // echo "\r\n";
  47. // echo json_encode($post);
  48. // echo "\r\n";
  49. // echo "\r\n";
  50. Util::WriteLog('24680_atmosfera_req', $this->baseUrl . $endpoint);
  51. Util::WriteLog('24680_atmosfera_req', $post);
  52. $rs = Util::curlPost2($this->baseUrl . $endpoint,$post,true);
  53. Util::WriteLog('24680_atmosfera_req', $rs);
  54. return json_decode($rs, true);
  55. }
  56. /**
  57. * 获取玩家余额
  58. *
  59. * @param string $userId 玩家ID,必须是先前传递给create_user_ex方法的值
  60. * @param int $merchantId 商户ID
  61. * @param string|null $sessionId 会话ID,可选
  62. * @return array 响应数据
  63. *
  64. * 调用示例:
  65. * {
  66. * "time": "31-12-2018 10:35:58",
  67. * "data": {
  68. * "merchant_id": 0,
  69. * "user_id": "123654"
  70. * },
  71. * "hash": "123456789987654321"
  72. * }
  73. */
  74. public function getBalance($userId, $merchantId, $sessionId = null)
  75. {
  76. $time = now()->format('d-m-Y H:i:s');
  77. $data = [
  78. 'user_id' => $userId,
  79. 'merchant_id' => $merchantId,
  80. 'session_id' => $sessionId
  81. ];
  82. return $this->postRequest('/get_balance', $time, $data);
  83. }
  84. /**
  85. * 获取玩家账户详情
  86. *
  87. * @param string $userId 玩家ID,必须是先前传递给create_user_ex方法的值
  88. * @param int $merchantId 商户ID
  89. * @param string|null $sessionId 会话ID,可选
  90. * @return array 响应数据
  91. *
  92. * 调用示例:
  93. * {
  94. * "time": "31-12-2018 10:35:58",
  95. * "data": {
  96. * "merchant_id": 0,
  97. * "user_id": "123654"
  98. * },
  99. * "hash": "123456789987654321"
  100. * }
  101. */
  102. public function getAccountDetails($userId, $merchantId, $sessionId = null)
  103. {
  104. $time = now()->format('d-m-Y H:i:s');
  105. $data = [
  106. 'user_id' => $userId,
  107. 'merchant_id' => $merchantId,
  108. 'session_id' => $sessionId
  109. ];
  110. return $this->postRequest('/get_account_details', $time, $data);
  111. }
  112. /**
  113. * 提现
  114. *
  115. * @param string $userId 玩家ID,必须是先前传递给create_user_ex方法的值
  116. * @param string $transactionId 在ATMOSFERA端的唯一事务标识
  117. * @param string $currency 货币ISO代码
  118. * @param float $amount 提现金额
  119. * @param float $bonusAmount 从玩家的奖金账户中提现的金额
  120. * @param int $gameType 游戏标识符
  121. * @param string $gameId 游戏回合标识符
  122. * @param int $merchantId 商户ID
  123. * @param string|null $sessionId 会话ID,可选
  124. * @param bool $bonusGame 如果为true,bonusAmount大于0且amount等于0
  125. * @param array $betData 包含下注信息的JSON编码数组
  126. * @return array 响应数据
  127. *
  128. * 调用示例:
  129. * {
  130. * "time": "31-12-2018 10:35:58",
  131. * "data": {
  132. * "user_id": "123654",
  133. * "transaction_id": "123456_0",
  134. * "currency": "EUR",
  135. * "amount": 0.25,
  136. * "bonus_amount": 0,
  137. * "game_type": 70,
  138. * "game_id": 1234,
  139. * "merchant_id": 1,
  140. * "bonus_game": false,
  141. * "bet_data": [
  142. * {"bet_id": 123, "nominal": 0.15, "content": "{\"numbers\":[34],\"pos\":\"34\"}"},
  143. * {"bet_id": 124, "nominal": 0.1, "content": "{\"numbers\":[33],\"pos\":\"33\"}"}
  144. * ]
  145. * },
  146. * "hash": "123456789987654321"
  147. * }
  148. */
  149. public function withdraw($userId, $transactionId, $currency, $amount, $bonusAmount, $gameType, $gameId, $merchantId, $sessionId = null, $bonusGame = false, $betData = [])
  150. {
  151. $time = now()->format('d-m-Y H:i:s');
  152. $data = [
  153. 'user_id' => $userId,
  154. 'transaction_id' => $transactionId,
  155. 'currency' => $currency,
  156. 'amount' => $amount,
  157. 'bonus_amount' => $bonusAmount,
  158. 'game_type' => $gameType,
  159. 'game_id' => $gameId,
  160. 'merchant_id' => $merchantId,
  161. 'session_id' => $sessionId,
  162. 'bonus_game' => $bonusGame,
  163. 'bet_data' => $betData
  164. ];
  165. return $this->postRequest('/withdraw', $time, $data);
  166. }
  167. /**
  168. * 存款
  169. *
  170. * @param string $userId 玩家ID,必须是先前传递给create_user_ex方法的值
  171. * @param string $transactionId 在ATMOSFERA端的唯一事务标识
  172. * @param string $currency 货币ISO代码
  173. * @param float $amount 存款金额
  174. * @param string $startOperationId 在withdraw方法中接收到的操作ID
  175. * @param int $gameType 游戏标识符
  176. * @param string $gameId 游戏回合标识符
  177. * @param string $gameData 包含游戏结果信息的字符串或对象
  178. * @param int $merchantId 商户ID
  179. * @param string|null $sessionId 会话ID,可选
  180. * @param bool $bonusGame 如果为true,表示奖金游戏
  181. * @param array $betData 包含下注信息的JSON编码数组
  182. * @return array 响应数据
  183. *
  184. * 调用示例:
  185. * {
  186. * "time": "31-12-2018 10:35:58",
  187. * "data": {
  188. * "user_id": "123654",
  189. * "transaction_id": "123457_0",
  190. * "start_operation_id": "123",
  191. * "currency": "EUR",
  192. * "amount": 1,
  193. * "game_type": 70,
  194. * "game_id": 1234,
  195. * "merchant_id": 1,
  196. * "game_data": "{\"balls\":[3],\"cards\":null}",
  197. * "bonus_game": false,
  198. * "bet_data": [
  199. * {"bet_id": 123, "win_amount": 1, "jp_amount": 0},
  200. * {"bet_id": 124, "win_amount": 0, "jp_amount": 0}
  201. * ]
  202. * },
  203. * "hash": "123456789987654321"
  204. * }
  205. */
  206. public function deposit($userId, $transactionId, $currency, $amount, $startOperationId, $gameType, $gameId, $gameData, $merchantId, $sessionId = null, $bonusGame = false, $betData = [])
  207. {
  208. $time = now()->format('d-m-Y H:i:s');
  209. $data = [
  210. 'user_id' => $userId,
  211. 'transaction_id' => $transactionId,
  212. 'currency' => $currency,
  213. 'amount' => $amount,
  214. 'start_operation_id' => $startOperationId,
  215. 'game_type' => $gameType,
  216. 'game_id' => $gameId,
  217. 'game_data' => $gameData,
  218. 'merchant_id' => $merchantId,
  219. 'session_id' => $sessionId,
  220. 'bonus_game' => $bonusGame,
  221. 'bet_data' => $betData
  222. ];
  223. return $this->postRequest('/deposit', $time, $data);
  224. }
  225. /**
  226. * 回滚
  227. *
  228. * @param string $userId 玩家ID,必须是先前传递给create_user_ex方法的值
  229. * @param string $transactionId 需要回滚的提现事务的唯一标识符
  230. * @param int $merchantId 商户ID
  231. * @param string|null $sessionId 会话ID,可选
  232. * @param bool $bonusGame 如果为true,表示奖金游戏
  233. * @return array 响应数据
  234. *
  235. * 调用示例:
  236. * {
  237. * "time": "31-12-2018 10:35:58",
  238. * "data": {
  239. * "user_id": "123654",
  240. * "transaction_id": "123457_0",
  241. * "merchant_id": 1
  242. * },
  243. * "hash": "123456789987654321"
  244. * }
  245. */
  246. public function rollback($userId, $transactionId, $merchantId, $sessionId = null, $bonusGame = false)
  247. {
  248. $time = now()->format('d-m-Y H:i:s');
  249. $data = [
  250. 'user_id' => $userId,
  251. 'transaction_id' => $transactionId,
  252. 'merchant_id' => $merchantId,
  253. 'session_id' => $sessionId,
  254. 'bonus_game' => $bonusGame
  255. ];
  256. return $this->postRequest('/rollback', $time, $data);
  257. }
  258. // 调用API方法:check_user_ex
  259. /**
  260. * 调用API方法:check_user_ex
  261. *
  262. * @param string $extUserId 集成商系统中的用户ID
  263. * @param int|null $merchantId 集成商系统中的商户ID,可选
  264. * @return array 响应数据
  265. *
  266. * 调用示例:
  267. * {
  268. * "time": "31-12-2018 10:35:58",
  269. * "data": {
  270. * "ext_user_id": "test"
  271. * },
  272. * "hash": "123456789987654321"
  273. * }
  274. */
  275. public function checkUserEx($extUserId, $merchantId = 0)
  276. {
  277. $time = now()->format('d-m-Y H:i:s');
  278. $data = [
  279. 'ext_user_id' => strval($extUserId),
  280. 'merchant_id' => $merchantId
  281. ];
  282. return $this->postRequest('/check_user_ex', $time, $data);
  283. }
  284. // 调用API方法:create_user_ex
  285. /**
  286. * 调用API方法:create_user_ex
  287. *
  288. * @param string $extUserId 集成商系统中的用户ID
  289. * @param int|null $merchantId 集成商系统中的商户ID,可选
  290. * @return array 响应数据
  291. *
  292. * 调用示例:
  293. * {
  294. * "time": "31-12-2018 10:35:58",
  295. * "data": {
  296. * "ext_user_id": "test"
  297. * },
  298. * "hash": "123456789987654321"
  299. * }
  300. */
  301. public function createUserEx($extUserId, $merchantId = 0)
  302. {
  303. $time = now()->format('d-m-Y H:i:s');
  304. $data = [
  305. 'ext_user_id' => strval($extUserId),
  306. 'merchant_id' => $merchantId
  307. ];
  308. return $this->postRequest('/create_user_ex', $time, $data);
  309. }
  310. // 调用API方法:register_token_ex
  311. /**
  312. * 调用API方法:register_token_ex
  313. *
  314. * @param string $extUserId 集成商系统中的用户ID
  315. * @param int|null $merchantId 集成商系统中的商户ID,可选
  316. * @param string|null $sessionId 集成商系统中的会话ID,可选
  317. * @return array 响应数据
  318. *
  319. * 调用示例:
  320. * {
  321. * "time": "31-12-2018 10:35:58",
  322. * "data": {
  323. * "ext_user_id": "test",
  324. * "merchant_id": 1,
  325. * "session_id": "session123"
  326. * },
  327. * "hash": "123456789987654321"
  328. * }
  329. */
  330. public function registerTokenEx($extUserId, $merchantId = 0, $sessionId = 'session123')
  331. {
  332. $time = now()->format('d-m-Y H:i:s');
  333. $data = [
  334. 'ext_user_id' => strval($extUserId),
  335. 'merchant_id' => $merchantId,
  336. 'session_id' => $sessionId
  337. ];
  338. return $this->postRequest('/register_token_ex', $time, $data);
  339. }
  340. // 调用API方法:create_demo_user
  341. /**
  342. * 调用API方法:create_demo_user
  343. *
  344. * @return array 响应数据
  345. *
  346. * 调用示例:
  347. * {
  348. * "time": "31-12-2018 10:35:58",
  349. * "data": {},
  350. * "hash": "123456789987654321"
  351. * }
  352. */
  353. public function createDemoUser()
  354. {
  355. $time = now()->format('d-m-Y H:i:s');
  356. $data = [];
  357. return $this->postRequest('/create_demo_user', $time, $data);
  358. }
  359. // 调用API方法:settings/games_list
  360. /**
  361. * 调用API方法:settings/games_list
  362. *
  363. * @return array 响应数据
  364. *
  365. * 调用示例:
  366. * {
  367. * "time": "31-12-2018 10:35:58",
  368. * "data": {},
  369. * "hash": "123456789987654321"
  370. * }
  371. */
  372. public function getGamesList()
  373. {
  374. $time = now()->format('d-m-Y H:i:s');
  375. $data = [];
  376. return $this->postRequest('/settings/games_list', $time, $data);
  377. }
  378. // 调用API方法:reports/game/ext_cashback_bets
  379. /**
  380. * 调用API方法:reports/game/ext_cashback_bets
  381. *
  382. * @param string $startDate UTC起始日期
  383. * @param string $stopDate UTC结束日期
  384. * @param int $gameType 游戏类型
  385. * @param string|null $extUserId 可选,集成商系统中的玩家ID
  386. * @return array 响应数据
  387. *
  388. * 调用示例:
  389. * {
  390. * "time": "31-12-2018 10:35:58",
  391. * "data": {
  392. * "start_date": "2023-01-01",
  393. * "stop_date": "2023-01-31",
  394. * "game_type": 70,
  395. * "ext_user_id": "123"
  396. * },
  397. * "hash": "123456789987654321"
  398. * }
  399. */
  400. public function getCashbackBets($startDate, $stopDate, $gameType, $extUserId = null)
  401. {
  402. $time = now()->format('d-m-Y H:i:s');
  403. $data = [
  404. 'start_date' => $startDate,
  405. 'stop_date' => $stopDate,
  406. 'game_type' => $gameType,
  407. 'ext_user_id' => $extUserId
  408. ];
  409. return $this->postRequest('/reports/game/ext_cashback_bets', $time, $data);
  410. }
  411. }