Sanjiu.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\api\complex;
  3. use think\Config;
  4. /**
  5. * 三九互娱
  6. */
  7. class Sanjiu implements ComplexInterface
  8. {
  9. private $channel = 'sanjiu';
  10. /**
  11. * ## 登陆 - 校验
  12. *
  13. * @param $data
  14. * @param $polyChannelGame
  15. *
  16. * @return false
  17. */
  18. public function getSpecialParam($data, $polyChannelGame = [])
  19. {
  20. // 参数:user_id = juhe_userid, channel_token = juhe_token, extparam = channel_userid
  21. if (!isset($data['user_id']) || !isset($data['channel_token']) || !isset($data['extparam'])) {
  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. 'juhe_userid' => $data['user_id'],
  32. 'juhe_token' => $data['channel_token'],
  33. 'app_id' => $channelConfig['app_id'],
  34. 'channel_userid' => $data['extparam'],
  35. ];
  36. $param['sign'] = $this->signLogin($param, $channelConfig['payment_key']);
  37. $res = get_http_response('https://juhesdk.3975ad.com/api/oauth/verify_token', $param);
  38. $res = json_decode($res, true);
  39. if ($res['success'] == true) {
  40. return $data['user_id'];
  41. } else {
  42. return false;
  43. }
  44. }
  45. // ## 登陆 - 登陆
  46. public function checkLogin($data, $polyChannelGame = [])
  47. {
  48. return true;
  49. }
  50. // ## 下单 - 客户端需要的参数(客户端自己做了,这块暂时不用)
  51. public function getOrder($data)
  52. {
  53. // 渠道游戏支付金额的产品标识获取
  54. $prefix = isComplexProduct($data['channel_mark'], $data['gameid']);
  55. if(!$prefix){
  56. return ['code' => 200, 'msg' => 'success', 'param' => "{}"];
  57. }
  58. if (!isset(config('config_complex_goods')[$prefix])) {
  59. return ['code' => 100, 'msg' => '当前渠道的游戏未配置商品:' . $prefix.' - '.$data['gameid'] . ' - ' . $data['amount'], 'param' => "{}"];
  60. }
  61. $cp_money = formatComplexProductMark($prefix, $data['gameid'], $data['amount']);
  62. if (!$cp_money) {
  63. return ['code' => 100, 'msg' => '当前渠道的游戏配置商品不存在: '. $prefix.' - '. $data['gameid'] . '-' . $data['amount'], 'param' => "{}"];
  64. }
  65. return ['code' => 200, 'msg' => 'success', 'param' => ['product_money_mark' => $cp_money, 'money' => $data['amount']]];
  66. }
  67. // ## 回调 - 效验
  68. public function paySign($data, $polyChannelGame = [])
  69. {
  70. // {"net_status":"WIFI","server_name":"区服名称","app_version":"1","bundleid":"com.qimeng.channel","unix_name":"产品名称","sign":"9218599D095E70EFDB9FF394D3311E1C","role_level":"1","package_id":"14821","channel_version":"9.9.8","uuid":"","mac":"0","platform":"2","product_desc":"产品描述","device_name":"GLK-AL00","role_id":"202005201314","product_id":"sanjiu_kdzz_0000100","juhesdk_version":"5.0.3","idfv":"","channel_userid":"0","wifi_ssid":"0","idfa":"","product_num":"1","server_id":"1","version":"10","role_name":"龙天","app_name":"channelSdk","net_isp":"UNKNOWN","money":"1","extends":"","user_id":"231971664","app_build_version":"1.0","cp_order_id":"CMWL17174002974091640934","imei":"dad55fca2b3cd65b","device_user_name":"unknown","ip":"183.156.238.137","ext":"0","juhe_order_id":"jh751-17df1664e288f7","is_sandbox":"0","real_money":"1"}
  71. $handleKeys = ['cp_order_id', 'package_id', 'channel_userid', 'money', 'unix_name', 'ext', 'juhe_order_id', 'sign'];
  72. if (array_diff($handleKeys, array_keys($data))) {
  73. return false;
  74. }
  75. $param = [
  76. 'cp_order_id' => $data['cp_order_id'],
  77. 'package_id' => $data['package_id'],
  78. 'channel_userid' => $data['channel_userid'],
  79. 'money' => $data['money'],
  80. 'unix_name' => $data['unix_name'],
  81. 'ext' => $data['ext'],
  82. 'juhe_order_id' => $data['juhe_order_id'],
  83. 'sign' => $data['sign'],
  84. ];
  85. if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
  86. return false;
  87. }
  88. $hadleSign = $this->signNotify($param, $channelConfig['payment_key'], true);
  89. if ($data['sign'] == $hadleSign) {
  90. return true;
  91. }
  92. return false;
  93. }
  94. // ## 回调处理相关参数
  95. public function getData($data)
  96. {
  97. if (!isset($data['cp_order_id']) || !isset($data['money']) || !isset($data['juhe_order_id'])) {
  98. return false;
  99. }
  100. return [
  101. 'orderid' => $data['cp_order_id'], // 我方聚合订单
  102. 'amount' => $data['money'], // 充值金额(单位:元)
  103. 'sub_orderid' => $data['juhe_order_id'], // 渠道订单
  104. ];
  105. }
  106. // ## 回调 - 成功返回
  107. public function getSuccess($msg = '')
  108. {
  109. echo 'success';
  110. exit();
  111. }
  112. // ## 回调 - 失败返回
  113. public function getFail($msg = '')
  114. {
  115. echo 'fail';
  116. exit();
  117. }
  118. // 登陆签名
  119. private function signLogin($param, $app_key)
  120. {
  121. ksort($param);
  122. $sign = http_build_query($param) . $app_key;
  123. $md5Res = strtoupper(md5($sign));
  124. trace('sign=' . $sign . ' - md5=' . $md5Res, 'Sanjiu@signLogin.result');
  125. return $md5Res;
  126. }
  127. // 回调签名
  128. private function signNotify($param, $app_key)
  129. {
  130. $oldSign = $param['sign'];
  131. unset($param['sign']);
  132. ksort($param);
  133. $string = '';
  134. foreach ($param as $k => $v) {
  135. $string .= $k. $v;
  136. // if ($string) {
  137. // } else {
  138. // $string = $k. $v;
  139. // }
  140. }
  141. $sign = $string. $app_key;
  142. $md5Res = strtoupper(md5($sign));
  143. trace('str=' . $sign . ' - sign: ' .$oldSign.' - '. $md5Res, 'Sanjiu@signNotify.result');
  144. return $md5Res;
  145. }
  146. }