LvRenSdk.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\api\library\mlbb;
  3. /**
  4. * 旅人游戏SDK
  5. */
  6. class LvRenSdk
  7. {
  8. protected $secretKey = 'fc50fc8a839e916fa9a6a40e14d1c66e'; // 密钥
  9. protected $config = [
  10. "appId" => "201030086", // 应用 ID,标识具体应用
  11. "channelId" => "201032019", // 渠道 ID,标识用户来源渠道
  12. ]; // 密钥
  13. public function __construct()
  14. {
  15. }
  16. // 获取角色列表
  17. public function getRoleList($userId, $serverId){
  18. // $userId = '103523_stable';
  19. // $serverId = '10082';
  20. $data = [
  21. 'appId' => $this->config['appId'], // 应用 ID,标识具体应用
  22. 'channelId' => $this->config['channelId'], // 渠道 ID,标识用户来源渠道
  23. 'channelUserId' => $userId, // 渠道用户 ID,用户在对应渠道的唯一标识
  24. 'serverId' => $serverId, // 服务器 ID,角色所在服务器标识
  25. 'ts' => time(), // 当前时间戳
  26. ];
  27. $data['sign'] = $this->handleSign($data, $this->secretKey);
  28. // https://mlbb-uapi.tarenwang.net/gameinfo/rolelist?appId=201030086&channelId=201032019&channelUserId=274113_stable&serverId=10082&ts=1757060026&sign=a0ad924403070fb58aa0bc05f8155ae2
  29. $result = getHttpGet('https://mlbb-uapi.tarenwang.net/gameinfo/rolelist', $data);
  30. $result = json_decode($result, true);
  31. if($result['code'] !== 0){
  32. return ['code' => -100, 'msg' => "请求失败!(code={$result['code']})", 'data' => []];
  33. }
  34. // ## 范例 ##
  35. // $result['data'] = [
  36. // [
  37. // "clientId" => "10082",
  38. // "clientName" => "水瓶座2服",
  39. // "roleId" => "1008200123118",
  40. // "roleName" => "大白菜叶子",
  41. // "roleLevel" => 7,
  42. // "createTs" => 1755600424,
  43. // "lastTs" => 1755601816
  44. // ],
  45. // ];
  46. return ['code' => 200, 'msg' => '请求成功!', 'data' => $result['data']];
  47. }
  48. /**
  49. * 发放奖励
  50. *
  51. * @param $userId string 渠道用户 ID,用户在对应渠道的唯一标识
  52. * @param $serverId string 服务器 ID,角色所在服务器标识
  53. * @param $roleId string 角色 ID,接收奖励的角色唯一标识
  54. * @param $actId string 活动 ID,标识奖励对应的活动
  55. * @param $actSubId string 子活动 ID,标识活动下的具体子活动
  56. *
  57. * @return array
  58. */
  59. public function sendRewards($userId, $serverId, $roleId, $actId, $actSubId){
  60. if(!$userId || !$serverId || !$roleId || !$actId || !$actSubId){
  61. return ['code' => -110, 'msg' => "缺少必要参数!", 'data' => []];
  62. }
  63. // $userId = '103523_stable';
  64. // $serverId = '10082';
  65. // $roleId = '1008200125959';
  66. $orderId = makeOrderid('MLBB'); // 订单 ID,奖励发放的唯一订单标识
  67. $data = [
  68. 'appId' => $this->config['appId'], // 应用 ID,标识具体应用
  69. 'channelId' => $this->config['channelId'], // 渠道 ID,标识用户来源渠道
  70. 'channelUserId' => $userId, // 渠道用户 ID,用户在对应渠道的唯一标识
  71. 'serverId' => $serverId, // 服务器 ID,角色所在服务器标识
  72. 'roleId' => $roleId, // 角色 ID,接收奖励的角色唯一标识
  73. 'actId' => $actId, // 活动 ID,标识奖励对应的活动
  74. 'actSubId' => $actSubId, // 子活动 ID,标识活动下的具体子活动
  75. 'orderId' => $orderId, // 订单 ID,奖励发放的唯一订单标识
  76. 'ts' => time(), // 当前时间戳
  77. ];
  78. $data['sign'] = $this->handleSign($data, $this->secretKey);
  79. $result = getHttpGet('https://mlbb-uapi.tarenwang.net/open/qimeng/sendRewards', $data);
  80. $result = json_decode($result, true);
  81. // if($result['code'] == 500 && $result['msg'] == 'call api-sendRewards fail'){
  82. // return ['code' => -130, 'msg' => "道具补货中,请稍后再来领取!", 'data' => []];
  83. // }
  84. if($result['code'] == 500){
  85. return ['code' => 200, 'msg' => "你已领取!", 'data' => []];
  86. }
  87. if(!empty($result['status'])){
  88. return ['code' => -120, 'msg' => "请求失败!(code={$result['error']})", 'data' => []];
  89. }
  90. if($result['code'] !== 0){
  91. return ['code' => -121, 'msg' => "请求失败!(code={$result['code']})", 'data' => []];
  92. }
  93. return ['code' => 200, 'msg' => '请求成功!', 'data' => $result['data']];
  94. }
  95. /**
  96. * 查询角色活动标签
  97. * PS:接口限定 IP 访问,需提供特定的 IP 地址
  98. *
  99. * @return array
  100. */
  101. public function getTagAndValByRole($serverId, $roleId){
  102. if(!$serverId || !$roleId){
  103. return ['code' => -100, 'msg' => "查询参数有误!", 'data' => []];
  104. }
  105. $data = [
  106. 'serverId' => $serverId, // 服务器 ID,角色所在服务器标识
  107. 'roleId' => $roleId, // 角色 ID,需要查询标签的角色唯一标识
  108. ];
  109. $result = getHttpPost('https://one.tarenwang.net/api/open/ac/qimeng/getTagAndValByRole', $data);
  110. $result = json_decode($result, true);
  111. if($result['code'] !== 0){
  112. return ['code' => -100, 'msg' => "请求失败!(code={$result['code']})", 'data' => []];
  113. }
  114. // ## 范例 ##
  115. /**
  116. * ## 活动标签说明 ##
  117. * 累计登录魔力宝贝7天(抽奖次数+1) 1
  118. * 游戏完成一次充值(抽奖次数+1) 2
  119. * 累计充值达到10000魔币(抽奖次数+2) 3
  120. * 累计登录魔力宝贝3天(次数+1) 4
  121. * 等级达到LV50级(次数+1) 5
  122. * 完成一次职业进阶(次数+1) 6
  123. * 战力达到12000(次数+1) 7
  124. *
  125. */
  126. // $result['data'] = [
  127. // "1" => "1", // 登录天数
  128. // "2" => "1", // 游戏完成一次充值
  129. // "3" => "1", // 累计充值魔币
  130. // "4" => "4", // 累计登录3天
  131. // "5" => "1", // 等级
  132. // "6" => "1", // 完成一次职业进阶(没有进阶则没有当前标签)
  133. // "7" => "2153" // 战力值
  134. // ];
  135. return ['code' => 200, 'msg' => '请求成功!', 'data' => $result['data']];
  136. }
  137. /**
  138. * 对接签名
  139. *
  140. * @param $param array 参数数组
  141. * @param $key string 密钥
  142. *
  143. * @return string
  144. */
  145. protected function handleSign($param, $key){
  146. ksort($param);
  147. $string = "";
  148. foreach ($param as $k => $v) {
  149. if($k == 'sign'){
  150. continue;
  151. }
  152. if ($string) {
  153. $string .= "&{$k}={$v}";
  154. } else {
  155. $string = "{$k}={$v}";
  156. }
  157. }
  158. $string = $string."&key=".$key;
  159. $sign = md5($string);
  160. return $sign;
  161. }
  162. }