123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace app\common\Enum;
- /**
- * 分享枚举类
- */
- class ShareEnum
- {
- // 分享来源类型
- const FROM_FORWARD = 'forward';
- const FROM_POSTER = 'poster';
- const FROM_LINK = 'link';
- // 分享平台类型
- const PLATFORM_H5 = 'H5';
- const PLATFORM_WECHAT_OFFICIAL_ACCOUNT = 'WechatOfficialAccount';
- const PLATFORM_WECHAT_MINI_PROGRAM = 'WechatMiniProgram';
- const PLATFORM_APP = 'App';
- /**
- * 获取分享来源列表
- */
- public static function getFromList()
- {
- return [
- self::FROM_FORWARD => '直接转发',
- self::FROM_POSTER => '识别海报',
- self::FROM_LINK => '分享链接',
- ];
- }
- /**
- * 获取分享平台列表
- */
- public static function getPlatformList()
- {
- return [
- self::PLATFORM_H5 => 'H5网页',
- self::PLATFORM_WECHAT_OFFICIAL_ACCOUNT => '微信公众号网页',
- self::PLATFORM_WECHAT_MINI_PROGRAM => '微信小程序',
- self::PLATFORM_APP => 'APP',
- ];
- }
- /**
- * 获取分享来源文本
- */
- public static function getFromText($from)
- {
- return self::getFromList()[$from] ?? $from;
- }
- /**
- * 获取分享平台文本
- */
- public static function getPlatformText($platform)
- {
- return self::getPlatformList()[$platform] ?? $platform;
- }
- /**
- * 验证分享来源是否有效
- */
- public static function isValidFrom($from)
- {
- return array_key_exists($from, self::getFromList());
- }
- /**
- * 验证分享平台是否有效
- */
- public static function isValidPlatform($platform)
- {
- return array_key_exists($platform, self::getPlatformList());
- }
- /**
- * 平台映射到数字ID (与前端buildSpmQuery保持一致)
- * 1=H5,2=微信公众号网页,3=微信小程序,4=App
- */
- public static function getPlatformIdMap()
- {
- return [
- self::PLATFORM_H5 => 1,
- self::PLATFORM_WECHAT_OFFICIAL_ACCOUNT => 2,
- self::PLATFORM_WECHAT_MINI_PROGRAM => 3,
- self::PLATFORM_APP => 4,
- ];
- }
- /**
- * 根据平台获取数字ID
- */
- public static function getPlatformId($platform)
- {
- return self::getPlatformIdMap()[$platform] ?? 3; // 默认微信小程序
- }
- }
|