Jule.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\api\complex;
  3. use ComplexThree\JuLe\joloRsa;
  4. /**
  5. * 聚乐
  6. */
  7. class Jule implements ComplexInterface
  8. {
  9. private $channel = 'jule';
  10. /**
  11. * ## 登陆 - 校验
  12. *
  13. * @param $data
  14. * @param $polyChannelGame
  15. *
  16. * @return false
  17. */
  18. public function getSpecialParam($data, $polyChannelGame = [])
  19. {
  20. if (empty($data['extparam']) || empty($data['channel_token'])) {
  21. return false;
  22. }
  23. if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
  24. return false;
  25. }
  26. $rsa = new joloRsa();
  27. $ret = $rsa->verification_sign($data['extparam'], $data['channel_token'], $paramArr['htc_key']);
  28. if (!$ret) {
  29. return false;
  30. }
  31. $account = json_decode($data['extparam'], true);
  32. if (isset($account['user_code'])) {
  33. return $account['user_code'];
  34. } else {
  35. return false;
  36. }
  37. }
  38. // ## 登陆 - 登陆
  39. public function checkLogin($data, $polyChannelGame = [])
  40. {
  41. return true;
  42. }
  43. // ## 下单 - 客户端需要的参数(客户端自己做了,这块暂时不用)
  44. public function getOrder($data)
  45. {
  46. // ## 测试
  47. // $data['user_code'] = '104471097';
  48. // $data['session_id'] = '12842658';
  49. // $data['rolename'] = '无';
  50. // $data['rolelevel'] = '无';
  51. // $data['roleid'] = '无';
  52. // $data['serverid'] = '无';
  53. if (empty(array_intersect_key($data, ['user_code', 'session_id', 'rolename', 'rolelevel', 'roleid', 'serverid']))) {
  54. return ['code' => 100, 'msg' => '下单参数有误!', 'param' => []];
  55. }
  56. if (empty($data['channel_info']['param'])) {
  57. return ['code' => 100, 'msg' => '渠道配置参数有误!', 'param' => []];
  58. }
  59. $param = $data['channel_infox']['param'];
  60. $param = json_decode($param, true);
  61. $orderArr['game_name'] = $data['game_info']['nickname']; // 游戏名称
  62. $orderArr['game_code'] = $param['app_id']; // 游戏编号(gamecode)
  63. $orderArr['game_order_id'] = $data['pay_info']['orderid']; // 游戏订单id
  64. $orderArr['amount'] = formatYuanToFen($data['pay_info']['amount']); // 金额,单位为分
  65. $orderArr['notify_url'] = $data['notify_url']; // 支付回调地址
  66. $orderArr['product_id'] = $data['product_id'] ?? '无'; //商品ID
  67. $orderArr['product_name'] = $data['product_name'] ?? '无'; //商品名称
  68. $orderArr['product_des'] = $data['product_des'] ?? '无'; //商品描述
  69. $orderArr['user_code'] = $data['user_code']; // 聚乐用户编号
  70. $orderArr['session_id'] = $data['session_id']; // 聚乐登录凭证session_id
  71. $orderArr['role_name'] = $data['rolename']; // 游戏角色名
  72. $orderArr['role_level'] = $data['rolelevel']; // 游戏角色等级
  73. $orderArr['area_server'] = $data['area_server'] ?? '无'; // 游戏区服名称
  74. $orderArr['vip_level'] = $data['vip_level'] ?? '无'; //游戏vip等级
  75. $orderArr['role_id'] = $data['roleid']; // 游戏角色ID
  76. $orderArr['area_server_id'] = $data['serverid']; // 游戏区服ID
  77. $orderArr['channel_reserved '] = ""; //cp自定义字段返回
  78. $rsa = new joloRsa();
  79. $private_key = config('complex.ju_le')['private_key_pkcs8'];
  80. $result = $rsa->order_rsa_sign($orderArr, $private_key);
  81. if ($result) {
  82. $orderArr['sign '] = $result; // 签名
  83. return ['code' => 200, 'msg' => 'success', 'param' => $orderArr];
  84. }
  85. return ['code' => 100, 'msg' => '渠道配置参数有误!', 'param' => $orderArr];
  86. }
  87. // ## 回调 - 效验
  88. public function paySign($data, $polyChannelGame = [])
  89. {
  90. /**
  91. * $data['order'] = order="{"result_code":1,"gmt_create":"2024-03-06 16:30:24","real_amount":6,"result_msg":"支付成功","game_code":"3417175059607","game_order_id":"CMWL17097137368704152218","jolo_order_id":"ZF1072602186b443c9ffe9af051","gmt_payment":"2024-03-06 16:30:41","channel_reserved":""}"&sign="fNo3mRVb6p3grMtpEg01B/EfUl6isqiV3CgdgKBg6M6vJoT1RnBUfspCZttp1wv5b7E01EXeFue1tTw4iCS/JEYucb30parkdOzHe81CDHhLNcOCDFueMMN+75yGZ1TDgpDRsTvoMNUZa5bp4FmorYGLMEIKK6poDZ4sQJi4OA4="&sign_type="RSA"
  92. */
  93. if(empty($polyChannelGame['param'])){
  94. return false;
  95. }
  96. if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
  97. return false;
  98. }
  99. if (!isset($data['order']) || !isset($data['sign'])) {
  100. return false;
  101. }
  102. $order = substr(urldecode($data['order']), 1, -1);
  103. $sign = substr($data['sign'], 1, -1);
  104. $sign = str_replace(' ', '+', $sign);
  105. $rsa = new joloRsa();
  106. $pub_key = $rsa->setupPubKey($paramArr['htc_key']);
  107. $dataStatus = $rsa->rsa_verify($order, $sign, $pub_key);
  108. if (!$dataStatus) {
  109. return false;
  110. }
  111. $orderData = json_decode($order, true);
  112. if ($orderData['result_code'] == 1) {
  113. return true;
  114. }
  115. return false;
  116. }
  117. // ## 回调 - 下单参数获取
  118. public function getData($data)
  119. {
  120. $order = substr(urldecode($data['order']), 1, -1);
  121. $orderData = json_decode($order, true);
  122. return [
  123. 'orderid' => $orderData['game_order_id'], // 我方聚合订单
  124. 'amount' => formatFenToYuan($orderData['real_amount']), // 充值金额(单位:元)
  125. 'sub_orderid' => $orderData['jolo_order_id'], // 渠道订单
  126. ];
  127. }
  128. // ## 回调 - 成功返回
  129. public function getSuccess($msg = '')
  130. {
  131. echo 'success';
  132. exit();
  133. }
  134. // ## 回调 - 失败返回
  135. public function getFail($msg = '')
  136. {
  137. echo 'success';
  138. exit();
  139. }
  140. }