Congyu.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\api\complex;
  3. use think\Request;
  4. /**
  5. * 从语
  6. */
  7. class Congyu implements ComplexInterface
  8. {
  9. private $channel = 'congyu';
  10. /**
  11. * ## 登陆 - 校验
  12. *
  13. * @param $data
  14. * @param $polyChannelGame
  15. *
  16. * @return false
  17. */
  18. public function getSpecialParam($data, $polyChannelGame = [])
  19. {
  20. // 参数:channel_token = sid
  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. $res = getHttpPost('http://api.cqchongyu.com/user/info', ['token' => $data['channel_token']]);
  31. $res = json_decode($res, true);
  32. if ($res['errorno'] == 200) {
  33. return $res['data']['uid'];
  34. }
  35. return false;
  36. }
  37. // ## 登陆 - 登陆
  38. public function checkLogin($data, $polyChannelGame = [])
  39. {
  40. return ['user_id' => $data['user_id']];
  41. }
  42. // ## 回调 - 效验
  43. public function paySign($data, $polyChannelGame = [])
  44. {
  45. $param = Request::instance()->only(['version', 'gameId', 'paySn', 'orderSn', 'itemName', 'userId', 'orderAmount', 'sign', 'developerInfo']);
  46. if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
  47. return false;
  48. }
  49. ksort($param);
  50. $string = "";
  51. foreach ($param as $k => $v) {
  52. if($k == 'sign'){
  53. continue;
  54. }
  55. if ($string) {
  56. $string .= "&{$k}={$v}";
  57. } else {
  58. $string = "{$k}={$v}";
  59. }
  60. }
  61. $sign = $string."&".$channelConfig['secretKey'];
  62. $md5Res = md5($sign);
  63. if ($param['sign'] == $md5Res) {
  64. return true;
  65. }
  66. return false;
  67. }
  68. // ## 回调 - 下单参数获取
  69. public function getData($data)
  70. {
  71. if (!isset($data['developerInfo']) || !isset($data['orderAmount']) || !isset($data['orderSn'])) {
  72. return false;
  73. }
  74. return [
  75. 'orderid' => $data['developerInfo'], // 我方聚合订单
  76. 'amount' => formatFenToYuan($data['orderAmount']),// 充值金额(单位:元)
  77. 'sub_orderid' => $data['orderSn'], // 渠道订单
  78. ];
  79. }
  80. // ## 回调 - 成功返回
  81. public function getSuccess($msg = '')
  82. {
  83. echo "success";
  84. exit();
  85. }
  86. // ## 回调 - 失败返回
  87. public function getFail($msg = '')
  88. {
  89. echo "fail";
  90. exit();
  91. }
  92. }