Repository navigation
Expand file tree
/
Copy pathApi_User_ProfileController.php
More file actions
79 lines (65 loc) · 2.7 KB
/
Copy pathApi_User_ProfileController.php
File metadata and controls
79 lines (65 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Created by PhpStorm.
* User: childeYin<尹少爷>
* Date: 23/07/2018
* Time: 4:20 PM
*/
class Api_User_ProfileController extends BaseController
{
private $classNameForRequest = '\Zaly\Proto\Site\ApiUserProfileRequest';
private $classNameForResponse = '\Zaly\Proto\Site\ApiUserProfileResponse';
public function rpcRequestClassName()
{
return $this->classNameForRequest;
}
/**
* @param \Zaly\Proto\Site\ApiUserProfileRequest $request
* @param \Google\Protobuf\Internal\Message $transportData
*/
public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf\Internal\Message $transportData)
{
///处理request,
$tag = __CLASS__ . '-' . __FUNCTION__;
$response = new Zaly\Proto\Site\ApiUserProfileResponse();
try {
$userId = $this->userId;
$profile = $this->getUserSelfProfile($userId);
if (!empty($profile)) {
$publicProfile = new Zaly\Proto\Core\PublicUserProfile();
$publicProfile->setUserId($profile['userId']);
$publicProfile->setAvatar($profile['avatar']);
$publicProfile->setLoginName($profile['loginName']);
$publicProfile->setRealNickname($profile['nickname']);
$publicProfile->setNickname($profile['nickname']);
$publicProfile->setNicknameInLatin($profile['nicknameInLatin']);
if ($profile['availableType']) {
$publicProfile->setAvailableType($profile['availableType']);
} else {
$publicProfile->setAvailableType(\Zaly\Proto\Core\UserAvailableType::UserAvailableNormal);
}
$AllUserProfile = new \Zaly\Proto\Core\AllUserProfile();
$AllUserProfile->setPublic($publicProfile);
$AllUserProfile->setTimeReg($profile['timeReg']);
$response->setProfile($AllUserProfile);
$this->setRpcError($this->defaultErrorCode, "");
} else {
$this->setRpcError("error.nouser", "no current user");
}
} catch (Exception $ex) {
$this->setRpcError("error.alert", "get user profile error");
$this->ctx->Wpf_Logger->error($tag, "error_msg=" . $ex->getMessage());
}
$this->rpcReturn($transportData->getAction(), $response);
}
protected function getUserSelfProfile($userId)
{
$tag = __CLASS__ . "->" . __FUNCTION__;
try {
return $this->ctx->SiteUserTable->getUserByUserId($userId);
} catch (Exception $e) {
$this->ctx->Wpf_Logger->error($tag, e);
}
return [];
}
}