Skip to content

Commit ad2bc96

Browse files
author
sisishiliu
committed
beta version
1 parent 3c6c114 commit ad2bc96

File tree

70 files changed

+2230
-463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2230
-463
lines changed

src/config.sample.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
'apiPageWidget' => './index.php?action=page.widget',
1616
'apiPageSiteInit' => "./index.php?action=installDB",
1717
'apiSiteLogin' => './index.php?action=api.site.login&body_format=pb',
18-
'session_verify_100' => 'http://open.akaxin.com:5208/index.php?action=api.session.verify&body_format=pb',
19-
'session_verify_105' => 'http://127.0.0.1:5207/index.php?action=api.session.verify&body_format=pb',
18+
'session_verify_101' => 'http://open.akaxin.com:5208/index.php?action=api.session.verify&body_format=pb',
19+
'session_verify_102' => 'http://127.0.0.1/index.php?action=api.session.verify&body_format=pb',
2020
"siteAddress" => '',
21+
'passport_cookie_name' => "duckchat_passport_cookie",
2122
'mail' =>
2223
array (
2324
'host' => 'smtp.126.com',

src/controller/Api/Group/Api_Group_InvitableFriendsController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
4848
throw new Exception($errorInfo);
4949
}
5050

51-
$results = $this->getInvitableFriendsFromDB($groupId, $offset, $pageSize);
51+
$results = $this->getInvitableFriendsFromDB($this->userId, $groupId, $offset, $pageSize);
5252
$userCount = $this->getUserCount($groupId);
5353

5454
$response = $this->buildGroupInvitableFriendsResponse($results, $userCount);
@@ -63,10 +63,10 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
6363

6464
}
6565

66-
///TODO 理论上 加群的时候,不会返回已经在群里的人
67-
private function getInvitableFriendsFromDB($groupId, $offset, $pageSize)
66+
67+
private function getInvitableFriendsFromDB($userId, $groupId, $offset, $pageSize)
6868
{
69-
$result = $this->ctx->SiteUserTable->getUserListNotInGroup($groupId, $offset, $pageSize);
69+
$result = $this->ctx->SiteUserFriendTable->getUserFriendListNotInGroup($userId, $groupId, $offset, $pageSize);
7070
return $result;
7171
}
7272

src/controller/Api/Passport/Api_Passport_PasswordFindPasswordController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ private function sendEmail($loginName)
5858
$this->ctx->PassportPasswordTokenTable->insertCodeInfo($codeInfo);
5959
$this->ctx->ZalyMail->sendEmail($toEmail, $token, $sendSiteName);
6060
}catch (Exception $ex) {
61-
$this->ctx->Wpf_Logger->error($tag, "error_msg=" . $ex->getMessage());
6261
$where = [
6362
"loginName" => $user['loginName']
6463
];

src/controller/Api/Passport/Api_Passport_PasswordResetPasswordController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,11 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
3939

4040
private function checkToken($loginName, $token)
4141
{
42-
$tag = __CLASS__ . '-' . __FUNCTION__;
43-
4442
$codeInfo = $this->ctx->PassportPasswordTokenTable->getCodeInfoByLoginName($loginName);
4543
$time = ZalyHelper::getMsectime();
4644
$tokenTime = $codeInfo['timeReg'];
4745
$timeExpire = $time - $tokenTime;
4846

49-
$this->ctx->Wpf_Logger->info($tag, "code info =" .json_encode($codeInfo));
50-
51-
$this->ctx->Wpf_Logger->info($tag, " tokenTime=" . $tokenTime);
52-
$this->ctx->Wpf_Logger->info($tag, "now time =" .$time);
53-
$this->ctx->Wpf_Logger->info($tag, "time expire =" . $timeExpire);
5447
if(!$codeInfo || $token != $codeInfo['token'] || ($timeExpire > $this->tokenExipreTime)) {
5548
$errorCode = $this->zalyError->errorVerifyToken;
5649
$errorInfo = $this->zalyError->getErrorInfo($errorCode);

src/controller/Api/Plugin/Api_Plugin_ListController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
4949
case Zaly\Proto\Core\PluginUsageType::PluginUsageU2Message:
5050
case Zaly\Proto\Core\PluginUsageType::PluginUsageTmpMessage:
5151
case Zaly\Proto\Core\PluginUsageType::PluginUsageGroupMessage:
52+
case \Zaly\Proto\Core\PluginUsageType::PluginUsageAccountSafe:
5253
break;
5354
case Zaly\Proto\Core\PluginUsageType::PluginUsageLogin:
5455
default:

src/controller/Api/Site/Api_Site_ConfigController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
3030
$tag = __CLASS__ . '-' . __FUNCTION__;
3131

3232
try {
33-
3433
$requestHeader = $transportData->getHeader();
3534
$hostUrl = $requestHeader[TransportDataHeaderKey::HeaderHostUrl];
3635

@@ -217,6 +216,7 @@ private function buildSiteConfigResponse($host, $port, $configData, $isValid, $r
217216
$config->setEnableRealName($configData[SiteConfig::SITE_ENABLE_REAL_NAME]);
218217
$config->setEnableWidgetWeb($configData[SiteConfig::SITE_ENABLE_WEB_WIDGET]);
219218
$config->setSiteIdPubkBase64($configData[SiteConfig::SITE_ID_PUBK_PEM]);
219+
$config->setAccountSafePluginId($configData[SiteConfig::SITE_PASSPORT_ACCOUNT_SAFE_PLUGIN_ID]);
220220

221221
$response->setConfig($config);
222222

src/controller/BaseController.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,7 @@ public function checkSessionId($action)
286286
$timeActive = $sessionInfo['timeActive'];
287287
$nowTime = $this->ctx->ZalyHelper->getMsectime();
288288

289-
///TODO 临时屏蔽 sessionId 时间过期
290-
291-
$this->ctx->Wpf_Logger->info("sessionTime", "session nowtime=" . $nowTime);
292-
$this->ctx->Wpf_Logger->info("sessionTime", "session timeActive=" . $timeActive);
293-
$this->ctx->Wpf_Logger->info("sessionTime", "session sessonTimeOut=" . $this->sessionIdTimeOut);
294-
$this->ctx->Wpf_Logger->info("sessionTime", "(nowTime - timeActive) > sessionIdTimeOut" . (($nowTime - $timeActive) > $this->sessionIdTimeOut) ? 1 : 0);
295-
289+
///TODO 临时屏蔽 sessionId 时间过
296290
// if (($nowTime - $timeActive) > $this->sessionIdTimeOut) {
297291
// $this->ctx->Wpf_Logger->error($tag, "session time out , session id = " . $sessionId);
298292
//

src/controller/Duckchat/Duckchat_MiniProgramController.php

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ abstract class Duckchat_MiniProgramController extends \Wpf_Controller
3434
protected $language = Zaly\Proto\Core\UserClientLangType::UserClientLangEN;
3535

3636
protected $pluginMiniProgramId;
37+
protected $pluginMiniProgramProfile;
3738
/**
3839
* @var BaseCtx
3940
*/
@@ -79,12 +80,20 @@ public function doIndex()
7980

8081
$this->pluginMiniProgramId = $_GET['miniProgramId'];
8182

83+
if (empty($this->pluginMiniProgramId)) {
84+
throw new Exception("request with empty miniProgram ID");
85+
}
86+
87+
//校验miniProgram
88+
$this->pluginMiniProgramProfile = $this->getMiniProgramProfile($this->pluginMiniProgramId);
89+
90+
if (empty($this->pluginMiniProgramProfile)) {
91+
throw new Exception("request with error miniProgram profile");
92+
}
93+
8294
// 接收的 加密的数据流
8395
$secretReqData = file_get_contents("php://input");
8496

85-
// 将数据转为TransportData
86-
$this->requestTransportData = new \Zaly\Proto\Core\TransportData();
87-
8897
////判断 request proto 类 是否存在。
8998
$requestClassName = $this->rpcRequestClassName();
9099
if (class_exists($requestClassName, true)) {
@@ -93,16 +102,23 @@ public function doIndex()
93102
trigger_error("no request proto class: " . $requestClassName, E_USER_ERROR);
94103
die();
95104
}
105+
106+
$authKey = $this->pluginMiniProgramProfile['authKey'];
107+
108+
$requestData = $this->ctx->ZalyAes->decrypt($secretReqData, $authKey);
109+
110+
// 将数据转为TransportData
111+
$this->requestTransportData = new \Zaly\Proto\Core\TransportData();
96112
try {
97113
if ("json" == $this->bodyFormatType) {
98114
if (empty($secretReqData)) {
99115
$secretReqData = "{}";
100116
}
101-
$this->requestTransportData->mergeFromJsonString($secretReqData);
117+
$this->requestTransportData->mergeFromJsonString($requestData);
102118
} else if ("pb" == $this->bodyFormatType) {
103-
$this->requestTransportData->mergeFromString($secretReqData);
119+
$this->requestTransportData->mergeFromString($requestData);
104120
} else if ("base64pb" == $this->bodyFormatType) {
105-
$realData = base64_decode($secretReqData);
121+
$realData = base64_decode($requestData);
106122
$this->requestTransportData->mergeFromString($realData);
107123
}
108124
} catch (Exception $e) {
@@ -203,7 +219,30 @@ public function rpcReturn($action, $response)
203219
} else {
204220
return;
205221
}
206-
echo $body;
222+
223+
//这里用小程序的authKey进行AES加密
224+
$authKey = $this->pluginMiniProgramProfile['authKey'];
225+
$encryptedBody = $this->ctx->ZalyAes->encrypt($body, $authKey);
226+
echo $encryptedBody;
227+
}
228+
229+
230+
private function getMiniProgramProfile($miniProgramId)
231+
{
232+
$miniProgramProfile = $this->ctx->SitePluginTable->getPluginById($miniProgramId);
233+
234+
if (!empty($miniProgramProfile)) {
235+
236+
if (empty($miniProgramProfile['authKey'])) {
237+
if (empty($authKey)) {
238+
$config = $this->ctx->SiteConfigTable->selectSiteConfig(SiteConfig::SITE_PLUGIN_PLBLIC_KEY);
239+
$miniProgramProfile['authKey'] = $config[SiteConfig::SITE_PLUGIN_PLBLIC_KEY];
240+
}
241+
}
242+
243+
}
244+
245+
return $miniProgramProfile;
207246
}
208247

209248
protected function finish_request()
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: zhangjun
5+
* Date: 08/09/2018
6+
* Time: 12:11 PM
7+
*/
8+
9+
class Duckchat_Session_ClearController extends Duckchat_MiniProgramController
10+
{
11+
private $classNameForRequest = '\Zaly\Proto\Plugin\DuckChatSessionClearRequest';
12+
private $classNameForResponse = '\Zaly\Proto\Plugin\DuckChatSessionClearResponse';
13+
private $requestAction = "duckchat.session.clear";
14+
15+
public function rpcRequestClassName()
16+
{
17+
return $this->classNameForRequest;
18+
}
19+
20+
/**
21+
* @param \Zaly\Proto\Plugin\DuckChatSessionClearRequest $request
22+
* @param \Zaly\Proto\Core\TransportData $transportData
23+
*/
24+
public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf\Internal\Message $transportData)
25+
{
26+
try {
27+
$userId = $request->getUserId();
28+
29+
if(!$userId) {
30+
$errorCode = $this->zalyError->errorSessionClear;
31+
$errorInfo = $this->zalyError->getErrorInfo($errorCode);
32+
$this->setRpcError($errorCode, $errorInfo);
33+
throw new Exception("duckchat.session.id userid is not exits");
34+
}
35+
$this->clearSessionByUserId($userId);
36+
$this->setRpcError($this->defaultErrorCode, "");
37+
} catch (Exception $ex) {
38+
$tag = __CLASS__."-".__FUNCTION__;
39+
$errorCode = $this->zalyError->errorSessionClear;
40+
$errorInfo = $this->zalyError->getErrorInfo($errorCode);
41+
$this->setRpcError($errorCode, $errorInfo);
42+
$this->ctx->Wpf_Logger->error($tag, $ex->getMessage());
43+
}
44+
$this->rpcReturn($this->requestAction, new \Zaly\Proto\Plugin\DuckChatSessionClearResponse());
45+
return;
46+
}
47+
48+
private function clearSessionByUserId($userId)
49+
{
50+
$flag = $this->ctx->SiteSessionTable->deleteSessionByUserId($userId);
51+
52+
if($flag >0) {
53+
return true;
54+
}
55+
throw new Exception("delete session failed");
56+
}
57+
}

src/controller/Duckchat/Session/Duckchat_Session_ProfileController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
6565
$this->rpcReturn($this->requestAction, $response);
6666
} catch (Exception $e) {
6767
$this->setRpcError("error.alert", $e->getMessage());
68+
$response = new $this->classNameForResponse();
6869
$this->ctx->Wpf_Logger->error($this->requestAction, $e);
70+
$this->rpcReturn($this->requestAction, new Zaly\Proto\Plugin\DuckChatSessionProfileResponse());
6971
}
70-
$this->rpcReturn($this->requestAction, $response);
7172
return;
7273
}
7374

@@ -76,7 +77,6 @@ private function getPluginProfile($pluginId)
7677
return $this->ctx->SitePluginTable->getPluginById($pluginId);
7778
}
7879

79-
8080
private function buildRequestResponse($userProfile)
8181
{
8282
$publicProfile = new \Zaly\Proto\Core\PublicUserProfile();

0 commit comments

Comments
 (0)