Переглянути джерело

添加火山引擎的接口. 以后依据运营需要添加事件埋点即可.

gwang 3 роки тому
батько
коміт
c2082779c0

+ 14 - 11
Gameserver/Amfphp/base/CmdCode.php

@@ -149,6 +149,11 @@ class CmdCode {
      * 更换玩家头像
      */
     const cmd_user_changeUserHeadImg = 6013;
+
+    /**
+     * 6014 初始化火山引擎
+     */
+    const cmd_user_stat_initvolc = 6014;
     // </editor-fold>
     //
     // <editor-fold defaultstate="collapsed" desc="好友操作码 - 61xx">
@@ -485,9 +490,9 @@ class CmdCode {
      * 突破
      */
     const cmd_hero_tupo = 6328;
-    
+
     /**
-     * 
+     *
      */
     const cmd_hero_YanLingReplace = 6329;
 // </editor-fold>
@@ -597,12 +602,12 @@ class CmdCode {
      * 武器突破
      */
     const cmd_store__weapon_tupo = 6422;
-    
+
     /**
      * 武器替换
      */
     const cmd_store_weaponReplace = 6423;
-    
+
 // </editor-fold>
     //
     // <editor-fold defaultstate="collapsed" desc="活动操作码 - 65xx">
@@ -1175,14 +1180,13 @@ class CmdCode {
     const cmd_college_ReceiveCourseReward = 7303;
 
 // </editor-fold>
-
 // <editor-fold defaultstate="collapsed" desc="学院操作码 - 74xx">
 
     /**
      *  获取全部拍卖信息
      */
     const cmd_Auction_GetUserAuctionItemsInfo = 7401;
-    
+
     /**
      *  玩家上架拍品信息
      */
@@ -1192,12 +1196,12 @@ class CmdCode {
      *  玩家竞拍信息
      */
     const cmd_Auction_GetUserAuctionItems = 7403;
-    
+
     /**
      * 一口价
      */
     const cmd_Auction_BuyoutPrice = 7404;
-      
+
     /**
      *  取消出售
      */
@@ -1207,14 +1211,13 @@ class CmdCode {
      * 上传拍品
      */
     const cmd_Auction_UploadAuctionItems = 7406;
-   
+
     /**
      * 竞拍
      */
     const cmd_Auction_UserAuctionBidItem = 7407;
-// </editor-fold>
- 
 
+// </editor-fold>
     // <editor-fold defaultstate="collapsed" desc="    反射方法    ">
 
     /**

+ 13 - 3
Gameserver/Amfphp/base/MemKey_User.php

@@ -84,7 +84,7 @@ class MemKey_User {
      * 主动挑战记录
      * @param type $zoneid
      * @param type $uid
-     * 
+     *
      */
     public static function OffensiveLog_zset($zoneid, $uid) {
         return self::Key_($zoneid, $uid) . (self::bUseShort() ? '-offlog' : '-offensivelog');
@@ -248,6 +248,16 @@ class MemKey_User {
 //
 // <editor-fold defaultstate="collapsed" desc="  status data  ">
 
+    /**
+     * 客户端属性信息(@火山引擎)
+     * @param type $zoneid
+     * @param type $uid
+     * @return type
+     */
+    public static function stat_volc_headers($zoneid, $uid) {
+        return self::Key_($zoneid, $uid) . (self::bUseShort() ? "-s-cp" : "stat-clientProperties");
+    }
+
     /**
      * 玩家抽奖数据
      * @param int $zoneid 分区id
@@ -304,7 +314,7 @@ class MemKey_User {
 // </editor-fold>
 //
     // <editor-fold defaultstate="collapsed" desc="   临时/时效性数据   ">
-    // 
+    //
 
     /**
      * 玩家临时/时效性数据 - 战场奖励与计算串的MD5值
@@ -315,6 +325,6 @@ class MemKey_User {
         return self::Key_($zoneid, $uid) . (self::bUseShort() ? "-t-aprwd5" : "-temp-arenasPreRewardMD5");
     }
 
-    // 
+    //
 // </editor-fold>
 }

+ 37 - 25
Gameserver/Amfphp/process/UserProc.php

@@ -31,7 +31,7 @@ class UserProc {
             case CmdCode::cmd_user_completeNewbieGuide:                         # 6007 提交新手引导步骤
                 return UserProc::completeNewbieGuide();
 //            case CmdCode::cmd_user_setNewbieGuideCards:                         # 6008 发放新手引导所需卡牌
-//                return self::SetNewbieGuideCards($req);                
+//                return self::SetNewbieGuideCards($req);
 //            case CmdCode::cmd_user_setNewbieGuideOver:                          # 6009 跳过新手引导
 //                return UserProc::setNewbieGuideOver();
             case CmdCode::cmd_user_setNickname:                                 # 6010 设置/修改玩家昵称
@@ -42,16 +42,28 @@ class UserProc {
                 return self::SetUserImage();
             case CmdCode::cmd_user_changeUserHeadImg:                           # 6013 更换玩家头像
                 return self::SetUserHeadImage();
+
+            case CmdCode::cmd_user_stat_initvolc:                               # 6014 初始化火山引擎所需数据
+                return self::InitVolcData();
             default:
                 Err(ErrCode::cmd_err);
         }
     }
 
+    /**
+     * 6014 初始化火山引擎所需数据
+     */
+    public static function InitVolcData() {
+        list($app_name, $app_package, $app_channel, $app_version, $os_name, $os_version, $device_model, $ab_version, $traffic_type) = req()->paras;
+        VolcUtil::Init($app_name, $app_package, $app_channel, $app_version, $os_name, $os_version, $device_model, $ab_version, $traffic_type);
+        return Resp::ok();
+    }
+
 //
 // <editor-fold defaultstate="collapsed" desc="玩家信息 修改">
 
     /**
-     * [6013]修改玩家头像 
+     * [6013]修改玩家头像
      */
     static function SetUserHeadImage() {
         list($headImage) = req()->paras;                                         # 参数, 新头像
@@ -61,7 +73,7 @@ class UserProc {
     }
 
     /**
-     * [6012]修改玩家形象 
+     * [6012]修改玩家形象
      */
     static function SetUserImage() {
         list($image) = req()->paras;                                             # 参数, 新形象
@@ -71,7 +83,7 @@ class UserProc {
     }
 
     /**
-     * [6011]修改玩家头像框  
+     * [6011]修改玩家头像框
      */
     static function SetUserImageBorder() {
         list($imgborderId) = req()->paras;                                       # 参数, 新头像框ID
@@ -81,7 +93,7 @@ class UserProc {
     }
 
     /**
-     * [6010] 设置/修改玩家昵称 
+     * [6010] 设置/修改玩家昵称
      */
     static function SetUserNickname() {
         list($newname) = req()->paras;                                          # 参数: 新昵称, 头像
@@ -105,7 +117,7 @@ class UserProc {
 //
 // <editor-fold defaultstate="collapsed" desc="新手引导">
 //    /**
-//     * [6009] 新手引导 发送n张碎片到玩家身上 
+//     * [6009] 新手引导 发送n张碎片到玩家身上
 //     */
 //    static function SetNewbieGuideCards() {
 //        Err(ErrCode::function_notopen_msg);                                     # 功能已经废弃 -wg
@@ -134,7 +146,7 @@ class UserProc {
 //    }
 
     /**
-     * [6009] 增加 设置引导结束的标志位 
+     * [6009] 增加 设置引导结束的标志位
      */
     public static function setNewbieGuideOver() {
         Err(ErrCode::function_notopen_msg);                                     # 功能已经废弃 -wg
@@ -152,7 +164,7 @@ class UserProc {
 
     /**
      * [6007] 更新初始的强制的新手引导阶段步骤
-     * 第一阶段的引导 
+     * 第一阶段的引导
      */
     public static function completeNewbieGuide() {
         $guideIndex = req()->paras[0];                                          # 参数: 新手引导步骤
@@ -178,7 +190,7 @@ class UserProc {
 //
 
     /**
-     * 6006 注册新角色 
+     * 6006 注册新角色
      */
     public static function RegisterNewRole() {
         $userID = req()->uid;
@@ -201,7 +213,7 @@ class UserProc {
     }
 
     /**
-     * 6000 【移动端】 获取分区列表 
+     * 6000 【移动端】 获取分区列表
      */
     public static function GetZoneList() {
         $defaultZone = new Ins_ZoneInfo(1, 0, "");                             # 新用户默认分区
@@ -221,7 +233,7 @@ class UserProc {
                 if ($zone->isRecommended > 0 && $zone->status == 1) {
                     $zoneList[] = $zone;
                 } else {
-                    
+
                 }
             } else {
                 $zoneList[] = $zone;
@@ -267,7 +279,7 @@ class UserProc {
     }
 
     /**
-     * 6002 客户端下载常量配置信息 
+     * 6002 客户端下载常量配置信息
      * @return type
      */
     public static function downloadConstInfo() {
@@ -282,12 +294,12 @@ class UserProc {
             return Resp::ok($ret);
         }
         $constInfo = GameConfig::client();                                      # 取出来的已经是base64过的压缩数据
-        my_Assert($constInfo, ErrCode::err_const_no);                           # 找不到配置数据 
+        my_Assert($constInfo, ErrCode::err_const_no);                           # 找不到配置数据
         return Resp::ok(array('data' => $constInfo));
     }
 
     /**
-     * 6001 客户端登录并返还玩家信息 
+     * 6001 客户端登录并返还玩家信息
      * @return Resp
      */
     public static function loginUserInfo() {
@@ -305,7 +317,7 @@ class UserProc {
             UserProc::updateUserInfo();                                         # 这一步回存操作只有在 userInfo正常存在的情况下才进行
             $resp = Resp::ok($userInfo);                                        # 设置返回值
             self::backupUserInfo();                                             # 数据回写
-            
+
             AuctionProc::TriggerSettlement();                                   #结算流拍信息
             self::updtateUserZoneInfo();                                        # 1. 更新玩家分区记录
         }
@@ -313,7 +325,7 @@ class UserProc {
     }
 
     /**
-     * 6003 领取连续登录奖励 
+     * 6003 领取连续登录奖励
      */
     public static function acceptContiDaysGift() {
         $resp = Resp::err(ErrCode::err_method_notimplement);
@@ -359,7 +371,7 @@ class UserProc {
     }
 
     /**
-     * 检测连续登录状态,重置必要字段[时间戳自动记录] 
+     * 检测连续登录状态,重置必要字段[时间戳自动记录]
      */
     static function checkContidays($isnew = 0) {
         $ret = TimeUtil::tsDay() - TimeUtil::tsDay(req()->userInfo->game->baseInfo->lastLogin); // 对比登录日期
@@ -377,7 +389,7 @@ class UserProc {
     }
 
     /**
-     *  处理当天第一次登录 
+     *  处理当天第一次登录
      * @param bool $isnew Description
      */
     static function OnNewDay($isnew) {
@@ -390,7 +402,7 @@ class UserProc {
 // <editor-fold defaultstate="collapsed" desc="创建新用户">
 
     /**
-     * 创建用户 
+     * 创建用户
      * @return UserInfoMo
      */
     static function createUser($rolename, $gender, $profile_img) {
@@ -406,7 +418,7 @@ class UserProc {
         $userInfo->game->baseInfo->firstLogin = now();
 //        $userInfo->game->pvp->socre = PVPProc::_getScore_by_uid($req, $req->uid); # 初始化pvp积分
 //        $userInfo->game->NewbieGuideOver = 1;
-//        UserProc::_intiHeroManual($userInfo->game);                             # 初始化图鉴 
+//        UserProc::_intiHeroManual($userInfo->game);                             # 初始化图鉴
 #Ps 6006是没有获得到Userinfo到Req中的
         UserProc::checkContidays(1);                                            # 每日状态检查
 //        UserProc::fetchFromInteract($mem, $req);  # 从interact拉取数据,Ps.初始化的过程应该还拉取不到什么有效数据
@@ -419,7 +431,7 @@ class UserProc {
     }
 
     /**
-     * 整理平台玩家记录集 
+     * 整理平台玩家记录集
      * @param int $isnew
      */
     private static function updatePlatUserRecord($isnew = 0) {
@@ -449,10 +461,10 @@ class UserProc {
 // <editor-fold defaultstate="collapsed" desc="读写玩家数据">
 
     /**
-     * 玩家数据 
+     * 玩家数据
      * @param type $zoneid
      * @param type $uid
-     * @return UserInfoMo 
+     * @return UserInfoMo
      */
     public static function getUserInfo($zoneid, $uid) {
         $key = MemKey_User::Info_hash($zoneid, $uid);
@@ -472,7 +484,7 @@ class UserProc {
     public static function updateUserInfo() {
         my_Assert(req(), "req()为空");
         my_Assert(req()->userInfo, "[" . req()->cmd . "] 玩家数据正在被清空!" . req()->uid);
-        req()->userInfoChanged = TRUE;                                          # 设置回写标志位 
+        req()->userInfoChanged = TRUE;                                          # 设置回写标志位
     }
 
     /**
@@ -495,7 +507,7 @@ class UserProc {
 // <editor-fold defaultstate="collapsed" desc="玩家分区记录">
 
     /**
-     * 读取玩家的分区记录 
+     * 读取玩家的分区记录
      * @return Data_UserZoneInfo Description
      */
     public static function getUserZoneInfo() {

+ 1 - 4
Gameserver/Amfphp/test.php

@@ -13,8 +13,5 @@ echoLine("phpver: " . PHP_VERSION . PHP_EOL);
 //var_dump(TimeUtil::Hour());
 //
 //var_dump(date('YmdH'));
-$index = 785555550;
-$key = 'gamerun-BossFight-byDateHour-zone1-2021052721';
-$kv = gMem()->zrevrange($key, 0, 0, true);
 
-var_dump($kv);
+ 

+ 2 - 2
Gameserver/Amfphp/util/TimeUtil.php

@@ -196,7 +196,7 @@ function tsDay($time = -1) {
  * @return float
  */
 function microsecond() {
-    return microtime(true) * 1000 * 1000;
+    return round(microtime(true) * 1000 * 1000);
 }
 
 /**
@@ -204,7 +204,7 @@ function microsecond() {
  * @return float
  */
 function millisecond() {
-    return microtime(true) * 1000;
+    return round(microtime(true) * 1000);
 }
 
 /**

+ 3 - 1
Gameserver/Amfphp/util/UtilInclude.php

@@ -12,9 +12,11 @@ require_once 'ErrHandler.php';
 //require_once 'CMemBase.php';                                                    # 内存数据库读写的基类
 require_once 'CRedisUtil.php';                                                  # Redis操作方法库(提升智能感知功能)
 require_once 'HttpUtil.php';                                                    # http协议辅助脚本
-require_once 'Event.php';                                                     # 模拟事件模式
+require_once 'Event.php';                                                       # 模拟事件模式
 require_once 'DebugHelper.php';                                                 # 调试辅助脚本
 require_once 'SelfChecker.php';                                                 # 自检模块
 require_once 'dao.php';                                                         # dao辅助脚本
 
+require_once __DIR__ . '/volcengin/VolcUtil.php';                               # 导入火山引擎封装
+
 //require_once ROOTDIR . '/Util/traits/RedisFlat.php';

+ 74 - 0
Gameserver/Amfphp/util/volcengine/VolcModels.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace loyalsoft;
+
+/**
+ * 火山引擎,事件类型枚举
+ */
+class Enum_Volc_EventName extends Enum {
+    // <editor-fold defaultstate="collapsed" desc="火山标准事件名称">
+
+    /**
+     * 玩家登陆
+     */
+    const Login = "gt_init_info";
+
+    /**
+     * 升级
+     */
+    const LevelUp = "gt_levelup";
+
+    /**
+     * 通关
+     */
+    const PassGate = "gt_end_play";
+    //
+// </editor-fold>
+//
+    // <editor-fold defaultstate="collapsed" desc="自定义事件名称">
+
+
+    Const Lottery = "抽奖";
+
+    // </editor-fold>
+}
+
+/**
+ * User
+ * @author gwang
+ */
+class Volc_User {
+
+    /**
+     * 用户的唯一身份标识,需要保证同一个用户在本应用内全局唯一,即需要与客户端上报一致
+     * @var string
+     */
+    public $user_unique_id;
+
+}
+
+/**
+ * Event
+ * @author gwang
+ */
+class Volc_Event {
+
+    /**
+     * 事件名
+     * @var type
+     */
+    public $event;
+
+    /**
+     * 事件参数,单层json map
+     * @var type
+     */
+    public $params;
+
+    /**
+     * 事件参数,单层json map
+     * @var type
+     */
+    public $local_time_ms;
+
+}

+ 64 - 0
Gameserver/Amfphp/util/volcengine/VolcUtil.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace loyalsoft;
+
+require_once __DIR__ . '/Volcengine_config.php';
+require_once __DIR__ . '/VolcModels.php';
+
+/**
+ * 火山引擎
+ * @author gwang
+ */
+class VolcUtil {
+
+    /**
+     * 初始化
+     *  接收客户端上传的附加参数信息.并存入redis
+     *  后面上报时直接提取信息并合并到headers
+     */
+    public static function Init($app_name, $app_package, $app_channel, $app_version, #
+            $os_name, $os_version, $device_model, #
+            $ab_version, $traffic_type) {
+        $client_ip = HttpUtil::clientIP();                                      # 客户端ip
+        $headers = compact($app_name, $app_package, $app_channel, $app_version, #
+                $os_name, $os_version, $device_model, #
+                $ab_version, $traffic_type, $client_ip
+        );
+        $zoneid = req()->zoneid;
+        $uid = req()->uid;
+        gMem()->add(MemKey_User::stat_volc_headers($zoneid, $uid), $headers);
+    }
+
+    private static function Headers() {
+        $zoneid = req()->zoneid;
+        $uid = req()->uid;
+        return gMem()->get(MemKey_User::stat_volc_headers($zoneid, $uid));
+    }
+
+    private static function User() {
+        $user = new Volc_User();
+        $user->user_unique_id = req()->uid;
+        return $user;
+    }
+
+    /**
+     * 上报统计事件
+     * @param type $event_name
+     * @param type $params
+     */
+    public static function Report($event_name, $params) {
+        $user = self::User();
+        $header = self::Headers();
+        $event = new Volc_Event();
+        $event->event = $event_name;
+        $event->local_time_ms = millisecond();
+        $event->params = $params;
+        $data = array(
+            'user' => $user,
+            'header' => $header,
+            'events' => array($event)
+        );
+        HttpUtil::makeRequest(Volcengine_config::ReportOneURL, $data, array(), Volcengine_config::Headers());
+    }
+
+}

+ 36 - 0
Gameserver/Amfphp/util/volcengine/Volcengine_config.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace loyalsoft;
+
+/**
+ * 火山引擎相关配置文件
+ * @author gwang
+ */
+class Volcengine_config {
+
+    //put your code here
+
+    const AppName = "言灵世界";
+    const AppId = "237519";
+    const AppKey = "c0a92b022fc76e56d0ab0e66f6e99a48";
+    const URLScheme = "rangersapplog.bf76a59a23857001";
+
+    /**
+     * 上报一条记录
+     */
+    public const ReportOneURL = "https://mcs.snssdk.com/v2/event/json";
+
+    /**
+     * 上报多条记录(max=20)
+     */
+    public const ReportListURL = "https://mcs.snssdk.com/v2/event/list";
+
+    /**
+     * 请求的headers
+     */
+    public static function Headers() {
+        return array('Content-Type' => 'application/json',
+            'X-MCS-AppKey' => self::AppKey);
+    }
+
+}