Aiyou.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\api\complex;
  3. header('Content-Type:text/html;charset=UTF-8');
  4. /**
  5. * 爱游
  6. */
  7. class Aiyou implements ComplexInterface
  8. {
  9. private $channel = 'aiyou';
  10. // 登陆效验
  11. public function checkLogin($data, $polyChannelGame = [])
  12. {
  13. if(empty($data['user_id']) || empty($data['channel_token'])){
  14. return false;
  15. }
  16. if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
  17. return false;
  18. }
  19. $param = [
  20. 'userID' => $data['user_id'],
  21. 'token' => $data['channel_token'],
  22. ];
  23. $signStr = sprintf('token=%s&userID=%s&key=%s', $param['token'], $param['userID'], $paramArr['appSecret']);
  24. $param['sign'] = md5($signStr);
  25. $result = get_http_response('https://iu-gateway.iyouhuyu.com/iug-sdk/user/verifyAccount', $param);
  26. $res = json_decode($result, true);
  27. if ($res['state'] == 1) {
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. }
  33. // 下单参数
  34. public function getData($data)
  35. {
  36. return [
  37. 'orderid' => $data['extension'], //我方聚合订单
  38. 'amount' => formatFenToYuan($data['money']), // 充值金额(单位:元)
  39. 'sub_orderid' => $data['orderID'], //渠道订单
  40. ];
  41. }
  42. // 回调效验
  43. public function paySign($data, $polyChannelGame = [])
  44. {
  45. if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
  46. return false;
  47. }
  48. $newData = [
  49. 'productID' => $data['productID'],
  50. 'orderID' => $data['orderID'],
  51. 'userID' => $data['userID'],
  52. 'channelID' => $data['channelID'],
  53. 'gameID' => $data['gameID'],
  54. 'serverID' => $data['serverID'],
  55. 'money' => $data['money'],
  56. 'currency' => $data['currency'],
  57. 'extension' => $data['extension'],
  58. 'roleID' => $data['roleID'],
  59. 'signType' => $data['signType'],
  60. 'sign' => $data['sign'],
  61. ];
  62. $sign = $this->sign($newData, $paramArr['appSecret']);
  63. if ($newData['sign'] == $sign) {
  64. return true;
  65. }
  66. return false;
  67. }
  68. /**
  69. * 生成签名
  70. *
  71. * @param array $data 参数数组
  72. * @param string $appSecret 密钥
  73. *
  74. * @return string 签名
  75. */
  76. function sign($data, $appSecret)
  77. {
  78. $newData = [];
  79. // 对参数进行 URL 解码
  80. foreach ($data as $key => $value) {
  81. if (!in_array($key, ['roleID', 'signType', 'sign'])) {
  82. $newData[$key] = urldecode($value);
  83. }
  84. }
  85. // 对参数进行首字母升序排序
  86. ksort($newData);
  87. // 拼接参数
  88. $signStr = '';
  89. foreach ($newData as $key => $value) {
  90. $signStr .= $key . '=' . $value . '&';
  91. }
  92. // 拼接密钥
  93. $signStr .= $appSecret;
  94. // 对字符串进行 MD5 签名
  95. $sign = md5($signStr);
  96. // dump($signStr, $sign);
  97. return $sign;
  98. }
  99. public function getFail($msg = '')
  100. {
  101. echo 'FAIL';
  102. exit();
  103. }
  104. public function getSuccess($msg = '')
  105. {
  106. echo 'SUCCESS';
  107. exit();
  108. }
  109. /**
  110. * 二次登陆效验
  111. *
  112. * @param $data
  113. * @param $polyChannelGame
  114. *
  115. * @return false
  116. */
  117. public function getSpecialParam($data,$polyChannelGame = [])
  118. {
  119. if(empty($data['user_id']) || empty($data['channel_token'])){
  120. return false;
  121. }
  122. if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
  123. return false;
  124. }
  125. $param = [
  126. 'userID' => $data['user_id'],
  127. 'token' => $data['channel_token'],
  128. ];
  129. $signStr = sprintf('token=%s&userID=%s&key=%s', $param['token'], $param['userID'], $paramArr['appSecret']);
  130. $param['sign'] = md5($signStr);
  131. $result = get_http_response('https://iu-gateway.iyouhuyu.com/iug-sdk/user/verifyAccount', $param);
  132. $res = json_decode($result, true);
  133. if ($res['state'] == 1) {
  134. return (string)$res['data']['userID'];
  135. } else {
  136. return false;
  137. }
  138. }
  139. }