TapDBEvent.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace loyalsoft;
  3. require_once ROOTDIR . '/service_call/pay/Mo/OrderNotice.php';
  4. require_once ROOTDIR . '/util/tapdb/TapDB_config.php';
  5. /**
  6. * tapdb普通事件
  7. * @author gwang
  8. */
  9. class TapDBEvent {
  10. /**
  11. * 事件的数据格式的构造函数
  12. * @param string $uid
  13. * @param dic $params 属性数组
  14. */
  15. public function __construct($uid, $eventName, $params) {
  16. $this->client_id = TapDB_config::Ins()->gameClientId;
  17. $this->user_id = $uid;
  18. $params['channel'] = self::getPlatStr($uid); # 插入下渠道信息
  19. $this->properties = $params;
  20. $this->name = str_starts_with($eventName, '#') ? $eventName : "#$eventName";
  21. }
  22. public $name = ""; // 必需, 事件名,一般为 "#xxx"
  23. public $type = "track"; // 必须, 固定为 "track"
  24. public $client_id; // 必需。注意 ClientID 需要被替换成游戏的 ClientID
  25. public $user_id; // 必需。用户ID。
  26. public $properties; // 属性值
  27. /**
  28. * 获得用户的平台字符串
  29. * @return string
  30. */
  31. static function getPlatStr($uid) {
  32. if (strrpos($uid, '_') > 0) {
  33. return substr($uid, strrpos($uid, '_') + 1); # 提取平台字符串
  34. } else {
  35. if (strlen($uid) == 32) {
  36. return "loyal";
  37. } else {
  38. return "taptap";
  39. }
  40. }
  41. //PS. substr() 函数返回字符串的一部分 strrpos() 函数查找字符串在另一字符串中最后一次出现的位置。
  42. }
  43. }
  44. /**
  45. * tapdb预定义事件
  46. * @author gwang
  47. */
  48. class TapDBPreEvent {
  49. /**
  50. * 事件的数据格式的构造函数
  51. * @param string $uid
  52. * @param dic $params 属性数组
  53. */
  54. public function __construct($uid, $eventName, $params) {
  55. $this->client_id = TapDB_config::Ins()->gameClientId;
  56. $this->user_id = $uid;
  57. $params['channel'] = self::getPlatStr($uid); # 插入下渠道信息
  58. $this->properties = $params;
  59. $this->name = $eventName; # 预定以事件名称一般不带#
  60. }
  61. public $name = ""; // 必需, 事件名,一般为 "#xxx"
  62. public $type = "track"; // 必须, 固定为 "track"
  63. public $client_id; // 必需。注意 ClientID 需要被替换成游戏的 ClientID
  64. public $user_id; // 必需。用户ID。
  65. public $properties; // 属性值
  66. public $device_id = "-"; // 设备id, 服务端上报可以传一个固定值。
  67. /**
  68. * 获得用户的平台字符串
  69. * @return string
  70. */
  71. static function getPlatStr($uid) {
  72. if (strrpos($uid, '_') > 0) {
  73. return substr($uid, strrpos($uid, '_') + 1); # 提取平台字符串
  74. } else {
  75. if (strlen($uid) == 32) {
  76. return "loyal";
  77. } else {
  78. return "taptap";
  79. }
  80. }
  81. //PS. substr() 函数返回字符串的一部分 strrpos() 函数查找字符串在另一字符串中最后一次出现的位置。
  82. }
  83. }