Jlyx.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\api\complex;
  3. /**
  4. * 九龙游戏 - V960
  5. */
  6. class Jlyx implements ComplexInterface
  7. {
  8. private $channel = 'jlyx';
  9. public $postHandleData = []; // 回调处理过的数据
  10. /**
  11. * ## 登陆 - 校验
  12. *
  13. * @param $data
  14. * @param $polyChannelGame
  15. *
  16. * @return false
  17. */
  18. public function getSpecialParam($data, $polyChannelGame = [])
  19. {
  20. // 参数:channel_token = token
  21. if (!isset($data['channel_token'])) {
  22. return false;
  23. }
  24. if (empty($polyChannelGame['param'])) {
  25. return false;
  26. }
  27. if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
  28. return false;
  29. }
  30. $param = [
  31. 'appId' => $channelConfig['app_id'],
  32. 'token' => $data['channel_token'],
  33. ];
  34. $param['sign'] = md5($param['appId'].$param['token'].$channelConfig['server_key']);
  35. $res = getHttpPost('http://user-api.yd999.com.cn/game/verify/token', $param);
  36. $res = json_decode($res, true);
  37. if ($res['code'] == 1) {
  38. return $res['data']['userId'];
  39. } else {
  40. return false;
  41. }
  42. }
  43. // ## 登陆 - 登陆
  44. public function checkLogin($data, $polyChannelGame = [])
  45. {
  46. return true;
  47. }
  48. // ## 下单 - 客户端需要的参数
  49. public function getOrder($data)
  50. {
  51. return ['code' => 200, 'msg' => 'success', 'param' => []];
  52. }
  53. // ## 回调 - 效验
  54. public function paySign($data, $polyChannelGame = [])
  55. {
  56. try {
  57. if (empty($data['data'])) {
  58. return false;
  59. }
  60. if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
  61. return false;
  62. }
  63. $postInput = urldecode($data['data']);
  64. $postData = $this->rsaDecode($postInput, $channelConfig['public_key']);
  65. if(!$postData){
  66. return false;
  67. }
  68. $postData = json_decode($postData, true);
  69. if (array_diff(['appId', 'userId', 'serverId', 'roleId', 'orderNum', 'orderMoneyFen', 'extInfo'], array_keys($postData))) {
  70. return false;
  71. }
  72. $param = [
  73. 'appId' => $postData['appId'],
  74. 'userId' => $postData['userId'],
  75. 'orderNum' => $postData['orderNum'],
  76. 'orderMoneyFen' => $postData['orderMoneyFen'],
  77. ];
  78. $param['sign'] = md5($param['appId'].$param['userId'].$param['orderNum'].$param['orderMoneyFen'].$channelConfig['server_key']);
  79. $res = getHttpPost('http://pay-center.yd999.com.cn/game_order_check', $param);
  80. // {"code":1,"msg":"订单校验成功","data":{"orderNum":"BR202411191745071616893946011","orderMoneyFen":"1"}}
  81. $res = json_decode($res, true);
  82. if ($res['code'] == 1) {
  83. $this->postHandleData = ['orderid' => $postData['orderNum'], 'amount' => $postData['orderMoneyFen'], 'sub_orderid' => $postData['extInfo']];
  84. return true;
  85. } else {
  86. return false;
  87. }
  88. } catch (\Exception $e){
  89. trace('jlyx: error=' . $e->getCode().' - '.$e->getMessage(), 'ComplexNotify.Exception');
  90. return false;
  91. }
  92. }
  93. // ## 回调 - 下单参数获取
  94. public function getData($data)
  95. {
  96. $data = $this->postHandleData;
  97. if (!isset($data['orderid']) || !isset($data['amount']) || !isset($data['sub_orderid'])) {
  98. return false;
  99. }
  100. return [
  101. 'orderid' => $data['sub_orderid'], // 我方聚合订单
  102. 'amount' => formatFenToYuan($data['amount']), // 充值金额(单位:元)
  103. 'sub_orderid' => $data['orderid'], // 渠道订单
  104. ];
  105. }
  106. // ## 回调 - 成功返回
  107. public function getSuccess($msg = '')
  108. {
  109. echo "SUCCESS";
  110. exit();
  111. }
  112. // ## 回调 - 失败返回
  113. public function getFail($msg = '')
  114. {
  115. echo "FAILURE:" . $msg;
  116. exit();
  117. }
  118. public function rsaDecode($dataStr = "", $publicKey = "")
  119. {
  120. $publicPem = $this->getPublicPem($publicKey);
  121. $data = base64_decode($dataStr);
  122. $crypto = '';
  123. $r = 0;
  124. foreach (str_split($data, 128) as $chunk) {
  125. $r = openssl_public_decrypt($chunk, $decrypted, $publicPem, OPENSSL_PKCS1_PADDING);
  126. $crypto .= $decrypted;
  127. }
  128. return $r ? $crypto : null;
  129. }
  130. private function getPublicPem($publicKey = "")
  131. {
  132. if (!$publicKey) {
  133. return "";
  134. }
  135. $publicKey = trim($publicKey);
  136. $needle = "BEGIN PUBLIC KEY";
  137. if (stripos($publicKey, $needle) !== false) {
  138. return openssl_pkey_get_public($publicKey);
  139. } else {
  140. $publicKey = str_replace(array("\r\n", "\n", "\r", " "), "", $publicKey);
  141. $key = chunk_split($publicKey, 64, "\r\n");//转换为pem格式的公钥
  142. $key = "-----BEGIN PUBLIC KEY-----\r\n" . $key . "-----END PUBLIC KEY-----";
  143. //输出key 可查看公钥格式后的原数据
  144. return openssl_pkey_get_public($key);
  145. }
  146. }
  147. }