SDKServerService.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. require_once dirname(__FILE__).'/BaseSDKService.php';
  3. require_once dirname(dirname(__FILE__)).'/util/LoggerHelper.php';
  4. require_once dirname(dirname(__FILE__)).'/constant/ServiceName.php';
  5. require_once dirname(dirname(__FILE__)).'/model/SidInfo.php';
  6. require_once dirname(dirname(__FILE__)).'/model/SessionInfo.php';
  7. require_once dirname(dirname(__FILE__)).'/model/gamedata/GameData.php';
  8. require_once dirname(dirname(__FILE__)).'/model/RealNameInfo.php';
  9. /**
  10. * 九游服务端有关的通信服务
  11. * Class SDKServerService
  12. */
  13. class SDKServerService extends BaseSDKService{
  14. /**
  15. * 用户会话验证接口-支持统一账号标识(account.verifySession)
  16. * @param sid
  17. * @return
  18. * @throws SDKException
  19. */
  20. public static function verifySession($sid) {
  21. try{
  22. $params = array();
  23. $params["sid"] = $sid;
  24. $result = parent::getSDKServerResponse($params, ServiceName::$CP_PREFIX, ServiceName::$VERIFYSESSION_SERVICE);
  25. $sessionInfo = new SessionInfo();
  26. $sessionInfo->nickName = $result["nickName"];
  27. $sessionInfo->accountId = $result["accountId"];
  28. $sessionInfo->creator = $result["creator"];
  29. }
  30. catch(SDKException $e){
  31. throw $e;
  32. }
  33. return $sessionInfo;
  34. }
  35. /**
  36. * 接收游戏服务器提交的游戏角色数据接口(ucid.game.gameData)
  37. * <br>
  38. * 请优先使用sdk客户端版接口,不推荐用服务器版接口
  39. * @param sid
  40. * @param gameData
  41. * @return
  42. * @throws SDKException
  43. */
  44. public static function gameData($accountId, array $gameData) {
  45. $categoryArray = array();
  46. if(empty($gameData)){
  47. throw new SDKException("游戏服务器角色数据类型为空", 10);
  48. }
  49. //遍历校验游戏参数
  50. foreach ($gameData as $model){
  51. if($model instanceof GameData){
  52. array_push($categoryArray, $model->getCategory());
  53. if(!$model->validate()){
  54. throw new SDKException("游戏数据有必填值为空", 10);
  55. }
  56. }
  57. else{
  58. throw new SDKException("游戏数据类型设置错误,非GameData", 10);
  59. }
  60. }
  61. //确定是否有必填的参数校验(下面个人信息类型,必须在sid和accountId中选填一个)
  62. if(in_array(GameDataCategory::$LOGIN_GAME_ROLE, $categoryArray) || in_array(GameDataCategory::$USER_INFO, $categoryArray)){
  63. if(!isset($accountId)){
  64. throw new SDKException("玩家类(非榜单)游戏数据,用户标示accountId为必填", 10);
  65. }
  66. }
  67. //转换游戏参数
  68. $gameDataStr = null;
  69. try {
  70. $gameDataStr = json_encode($gameData);
  71. $gameDataStr = urlencode($gameDataStr);
  72. } catch (Exception $e) {
  73. throw new SDKException("JsonEncode游戏服务器角色数据有误", -1);
  74. }
  75. try{
  76. $params = array();
  77. $params["accountId"] = $accountId;
  78. $params["gameData"] = $gameDataStr;
  79. $result = parent::getSDKGameDataResponse($params, ServiceName::$CP_GAMEDATA_PREFIX, ServiceName::$GAMEDATA_SERVICE);
  80. }
  81. catch(SDKException $e){
  82. throw $e;
  83. }
  84. return empty($result) ? true : false;
  85. }
  86. /**
  87. * 查询指定会话对应的玩家是否有身份证实名制(account.getRealNameStatus)
  88. * @param sid
  89. * @return
  90. * true - 已完成身份证实名
  91. * false - 未身份证实名
  92. * @throws SDKException
  93. */
  94. public static function getRealNameStatus($sid) {
  95. try{
  96. $params = array();
  97. $params["sid"] = $sid;
  98. $result = parent::getSDKRealNameResponse($params, ServiceName::$CP_REALNAME_PREFIX, ServiceName::$GET_REALNAME_STATUS);
  99. $realNameInfo = new RealNameInfo();
  100. $realNameInfo->realNameStatus = $result["realNameStatus"];
  101. }
  102. catch(SDKException $e){
  103. throw $e;
  104. }
  105. return $realNameInfo;
  106. }
  107. /**
  108. * 用户会话验证接口(ucid.user.sidInfo)
  109. * 仅供已接入过的老游戏使用
  110. * @param sid
  111. * @return
  112. * @throws SDKException
  113. */
  114. public static function verifySid($sid){
  115. try{
  116. $params = array();
  117. $params["sid"] = $sid;
  118. $result = parent::getSDKServerResponse($params, ServiceName::$SS_PREFIX, ServiceName::$SIDINFO_SERVICE);
  119. $sidInfo = new SidInfo();
  120. $sidInfo->nickName = $result["nickName"];
  121. $sidInfo->ucid = $result["ucid"];
  122. }
  123. catch(SDKException $e){
  124. throw $e;
  125. }
  126. return $sidInfo;
  127. }
  128. }