| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- namespace app\api\library\mlbb;
- /**
- * 旅人游戏SDK
- */
- class LvRenSdk
- {
- protected $secretKey = 'fc50fc8a839e916fa9a6a40e14d1c66e'; // 密钥
- protected $config = [
- "appId" => "201030086", // 应用 ID,标识具体应用
- "channelId" => "201032019", // 渠道 ID,标识用户来源渠道
- ]; // 密钥
- public function __construct()
- {
- }
- // 获取角色列表
- public function getRoleList($userId, $serverId){
- // $userId = '103523_stable';
- // $serverId = '10082';
- $data = [
- 'appId' => $this->config['appId'], // 应用 ID,标识具体应用
- 'channelId' => $this->config['channelId'], // 渠道 ID,标识用户来源渠道
- 'channelUserId' => $userId, // 渠道用户 ID,用户在对应渠道的唯一标识
- 'serverId' => $serverId, // 服务器 ID,角色所在服务器标识
- 'ts' => time(), // 当前时间戳
- ];
- $data['sign'] = $this->handleSign($data, $this->secretKey);
- // https://mlbb-uapi.tarenwang.net/gameinfo/rolelist?appId=201030086&channelId=201032019&channelUserId=274113_stable&serverId=10082&ts=1757060026&sign=a0ad924403070fb58aa0bc05f8155ae2
- $result = getHttpGet('https://mlbb-uapi.tarenwang.net/gameinfo/rolelist', $data);
- $result = json_decode($result, true);
- if($result['code'] !== 0){
- return ['code' => -100, 'msg' => "请求失败!(code={$result['code']})", 'data' => []];
- }
- // ## 范例 ##
- // $result['data'] = [
- // [
- // "clientId" => "10082",
- // "clientName" => "水瓶座2服",
- // "roleId" => "1008200123118",
- // "roleName" => "大白菜叶子",
- // "roleLevel" => 7,
- // "createTs" => 1755600424,
- // "lastTs" => 1755601816
- // ],
- // ];
- return ['code' => 200, 'msg' => '请求成功!', 'data' => $result['data']];
- }
- /**
- * 发放奖励
- *
- * @param $userId string 渠道用户 ID,用户在对应渠道的唯一标识
- * @param $serverId string 服务器 ID,角色所在服务器标识
- * @param $roleId string 角色 ID,接收奖励的角色唯一标识
- * @param $actId string 活动 ID,标识奖励对应的活动
- * @param $actSubId string 子活动 ID,标识活动下的具体子活动
- *
- * @return array
- */
- public function sendRewards($userId, $serverId, $roleId, $actId, $actSubId){
- if(!$userId || !$serverId || !$roleId || !$actId || !$actSubId){
- return ['code' => -110, 'msg' => "缺少必要参数!", 'data' => []];
- }
- // $userId = '103523_stable';
- // $serverId = '10082';
- // $roleId = '1008200125959';
- $orderId = makeOrderid('MLBB'); // 订单 ID,奖励发放的唯一订单标识
- $data = [
- 'appId' => $this->config['appId'], // 应用 ID,标识具体应用
- 'channelId' => $this->config['channelId'], // 渠道 ID,标识用户来源渠道
- 'channelUserId' => $userId, // 渠道用户 ID,用户在对应渠道的唯一标识
- 'serverId' => $serverId, // 服务器 ID,角色所在服务器标识
- 'roleId' => $roleId, // 角色 ID,接收奖励的角色唯一标识
- 'actId' => $actId, // 活动 ID,标识奖励对应的活动
- 'actSubId' => $actSubId, // 子活动 ID,标识活动下的具体子活动
- 'orderId' => $orderId, // 订单 ID,奖励发放的唯一订单标识
- 'ts' => time(), // 当前时间戳
- ];
- $data['sign'] = $this->handleSign($data, $this->secretKey);
- $result = getHttpGet('https://mlbb-uapi.tarenwang.net/open/qimeng/sendRewards', $data);
- $result = json_decode($result, true);
- // if($result['code'] == 500 && $result['msg'] == 'call api-sendRewards fail'){
- // return ['code' => -130, 'msg' => "道具补货中,请稍后再来领取!", 'data' => []];
- // }
- if($result['code'] == 500){
- return ['code' => 200, 'msg' => "你已领取!", 'data' => []];
- }
- if(!empty($result['status'])){
- return ['code' => -120, 'msg' => "请求失败!(code={$result['error']})", 'data' => []];
- }
- if($result['code'] !== 0){
- return ['code' => -121, 'msg' => "请求失败!(code={$result['code']})", 'data' => []];
- }
- return ['code' => 200, 'msg' => '请求成功!', 'data' => $result['data']];
- }
- /**
- * 查询角色活动标签
- * PS:接口限定 IP 访问,需提供特定的 IP 地址
- *
- * @return array
- */
- public function getTagAndValByRole($serverId, $roleId){
- if(!$serverId || !$roleId){
- return ['code' => -100, 'msg' => "查询参数有误!", 'data' => []];
- }
- $data = [
- 'serverId' => $serverId, // 服务器 ID,角色所在服务器标识
- 'roleId' => $roleId, // 角色 ID,需要查询标签的角色唯一标识
- ];
- $result = getHttpPost('https://one.tarenwang.net/api/open/ac/qimeng/getTagAndValByRole', $data);
- $result = json_decode($result, true);
- if($result['code'] !== 0){
- return ['code' => -100, 'msg' => "请求失败!(code={$result['code']})", 'data' => []];
- }
- // ## 范例 ##
- /**
- * ## 活动标签说明 ##
- * 累计登录魔力宝贝7天(抽奖次数+1) 1
- * 游戏完成一次充值(抽奖次数+1) 2
- * 累计充值达到10000魔币(抽奖次数+2) 3
- * 累计登录魔力宝贝3天(次数+1) 4
- * 等级达到LV50级(次数+1) 5
- * 完成一次职业进阶(次数+1) 6
- * 战力达到12000(次数+1) 7
- *
- */
- // $result['data'] = [
- // "1" => "1", // 登录天数
- // "2" => "1", // 游戏完成一次充值
- // "3" => "1", // 累计充值魔币
- // "4" => "4", // 累计登录3天
- // "5" => "1", // 等级
- // "6" => "1", // 完成一次职业进阶(没有进阶则没有当前标签)
- // "7" => "2153" // 战力值
- // ];
- return ['code' => 200, 'msg' => '请求成功!', 'data' => $result['data']];
- }
- /**
- * 对接签名
- *
- * @param $param array 参数数组
- * @param $key string 密钥
- *
- * @return string
- */
- protected function handleSign($param, $key){
- ksort($param);
- $string = "";
- foreach ($param as $k => $v) {
- if($k == 'sign'){
- continue;
- }
- if ($string) {
- $string .= "&{$k}={$v}";
- } else {
- $string = "{$k}={$v}";
- }
- }
- $string = $string."&key=".$key;
- $sign = md5($string);
- return $sign;
- }
- }
|