Skip to content

Commit 299492d

Browse files
committed
add gif
1 parent e87b1a4 commit 299492d

19 files changed

Lines changed: 689 additions & 96 deletions

src/config.sample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'port' => 25,
3131
),
3232
'dbType' => 'sqlite',
33-
'dbVersion' => '2',
33+
'dbVersion' => '3',
3434
'sqlite' =>
3535
array(
3636
'sqliteDBPath' => '.',

src/controller/InstallDBController.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -426,30 +426,30 @@ private function initPluginMiniProgram()
426426
'permissionType' => Zaly\Proto\Core\PluginPermissionType::PluginPermissionAll,
427427
'authKey' => "",
428428
],
429-
// [
430-
// 'pluginId' => 104,
431-
// 'name' => "gif小程序",
432-
// 'logo' => "",
433-
// 'sort' => 2, //order = 2
434-
// 'landingPageUrl' => "index.php?action=miniProgram.gif.index",
435-
// 'landingPageWithProxy' => 1, //1 表示走site代理
436-
// 'usageType' => Zaly\Proto\Core\PluginUsageType::PluginUsageU2Message,
437-
// 'loadingType' => Zaly\Proto\Core\PluginLoadingType::PluginLoadingChatbox,
438-
// 'permissionType' => Zaly\Proto\Core\PluginPermissionType::PluginPermissionAll,
439-
// 'authKey' => "",
440-
// ],
441-
// [
442-
// 'pluginId' => 104,
443-
// 'name' => "gif小程序",
444-
// 'logo' => "",
445-
// 'sort' => 2, //order = 2
446-
// 'landingPageUrl' => "index.php?action=miniProgram.gif.index",
447-
// 'landingPageWithProxy' => 1, //1 表示走site代理
448-
// 'usageType' => Zaly\Proto\Core\PluginUsageType::PluginUsageGroupMessage,
449-
// 'loadingType' => Zaly\Proto\Core\PluginLoadingType::PluginLoadingChatbox,
450-
// 'permissionType' => Zaly\Proto\Core\PluginPermissionType::PluginPermissionAll,
451-
// 'authKey' => "",
452-
// ],
429+
[
430+
'pluginId' => 104,
431+
'name' => "gif小程序",
432+
'logo' => "",
433+
'sort' => 2, //order = 2
434+
'landingPageUrl' => "index.php?action=miniProgram.gif.index",
435+
'landingPageWithProxy' => 1, //1 表示走site代理
436+
'usageType' => Zaly\Proto\Core\PluginUsageType::PluginUsageU2Message,
437+
'loadingType' => Zaly\Proto\Core\PluginLoadingType::PluginLoadingChatbox,
438+
'permissionType' => Zaly\Proto\Core\PluginPermissionType::PluginPermissionAll,
439+
'authKey' => "",
440+
],
441+
[
442+
'pluginId' => 104,
443+
'name' => "gif小程序",
444+
'logo' => "",
445+
'sort' => 2, //order = 2
446+
'landingPageUrl' => "index.php?action=miniProgram.gif.index",
447+
'landingPageWithProxy' => 1, //1 表示走site代理
448+
'usageType' => Zaly\Proto\Core\PluginUsageType::PluginUsageGroupMessage,
449+
'loadingType' => Zaly\Proto\Core\PluginLoadingType::PluginLoadingChatbox,
450+
'permissionType' => Zaly\Proto\Core\PluginPermissionType::PluginPermissionAll,
451+
'authKey' => "",
452+
],
453453
[
454454
'pluginId' => 105,
455455
'name' => "账户密码管理小程序",

src/controller/MiniProgram/Passport/MiniProgram_Passport_AccountController.php

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -65,70 +65,12 @@ private function modifyPassportPassword($loginName)
6565
$tag = __CLASS__ . "-". __FUNCTION__;
6666

6767
try{
68-
6968
$sessionClearRequest = new \Zaly\Proto\Plugin\DuckChatSessionClearRequest();
7069
$sessionClearRequest->setUserId($this->userId);
71-
$sessionClearUrl = "/index.php?action=" . $this->sessionClear . "&body_format=base64pb&miniProgramId=".$this->passporAccountPluginId;
72-
$sessionClearUrl = ZalyHelper::getFullReqUrl($sessionClearUrl);
73-
$this->sendReq($this->sessionClear, $sessionClearUrl, $sessionClearRequest);
70+
$this->requestDuckChatInnerApi($this->passporAccountPluginId, $this->sessionClear, $sessionClearRequest);
7471
}catch (Exception $ex) {
7572
$this->ctx->Wpf_Logger->error($tag, $ex->getMessage());
7673
throw new Exception($ex->getMessage());
7774
}
7875
}
79-
80-
private function sendReq($action, $url, $dataReq)
81-
{
82-
83-
$anyBody = new \Google\Protobuf\Any();
84-
$anyBody->pack($dataReq);
85-
86-
$transportData = new \Zaly\Proto\Core\TransportData();
87-
$transportData->setBody($anyBody);
88-
$transportData->setAction($action);
89-
$transportData->setTimeMillis(ZalyHelper::getMsectime());
90-
$transportData->setHeader(["_".\Zaly\Proto\Core\TransportDataHeaderKey::HeaderUserClientLang => $this->language]);
91-
$data = $transportData->serializeToString();
92-
$data = base64_encode($data);
93-
94-
$pluginProfile = $this->getMiniProgramProfile($this->passporAccountPluginId);
95-
$authKey = $pluginProfile['authKey'];
96-
$data = $this->ctx->ZalyAes->encrypt($data, $authKey);
97-
98-
$result = $this->ctx->ZalyCurl->request( $url, "POST", $data);
99-
$authKey = $pluginProfile['authKey'];
100-
$result = $this->ctx->ZalyAes->decrypt($result, $authKey);
101-
$result = base64_decode($result);
102-
103-
//解析数据
104-
$transportData = new \Zaly\Proto\Core\TransportData();
105-
$transportData->mergeFromString($result);
106-
107-
$header = $transportData->getHeader();
108-
109-
foreach ($header as $key => $val) {
110-
if ($key == "_1" && $val != "success") {
111-
$this->errorCode = $header["_2"];
112-
throw new Exception(" failed");
113-
}
114-
}
115-
}
116-
117-
private function getMiniProgramProfile($miniProgramId)
118-
{
119-
$miniProgramProfile = $this->ctx->SitePluginTable->getPluginById($miniProgramId);
120-
121-
if (!empty($miniProgramProfile)) {
122-
123-
if (empty($miniProgramProfile['authKey'])) {
124-
if (empty($authKey)) {
125-
$config = $this->ctx->SiteConfigTable->selectSiteConfig(SiteConfig::SITE_PLUGIN_PLBLIC_KEY);
126-
$miniProgramProfile['authKey'] = $config[SiteConfig::SITE_PLUGIN_PLBLIC_KEY];
127-
}
128-
}
129-
130-
}
131-
132-
return $miniProgramProfile;
133-
}
13476
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: zhangjun
5+
* Date: 05/09/2018
6+
* Time: 2:27 PM
7+
*/
8+
9+
class MiniProgram_Gif_IndexController extends MiniProgramController
10+
{
11+
12+
private $gifMiniProgramId = 104;
13+
private $action = "duckChat.message.send";
14+
private $groupType = "g";
15+
private $u2Type = "u";
16+
private $userRelationAction = "duckChat.user.relation";
17+
private $limit=30;
18+
19+
public function getMiniProgramId()
20+
{
21+
return $this->gifMiniProgramId;
22+
}
23+
24+
public function requestException($ex)
25+
{
26+
$this->showPermissionPage();
27+
}
28+
29+
public function preRequest()
30+
{
31+
}
32+
33+
public function doRequest()
34+
{
35+
header('Access-Control-Allow-Origin: *');
36+
$method = $_SERVER['REQUEST_METHOD'];
37+
$tag = __CLASS__ ."-".__FUNCTION__;
38+
if ($method == 'POST') {
39+
try{
40+
$type = isset($_POST['type']) ? $_POST['type'] :"send_msg";
41+
switch ($type) {
42+
case "send_msg" :
43+
$this->sendWebMessage($_POST);
44+
break;
45+
case "add_gif":
46+
$this->addGif($_POST);
47+
}
48+
$this->ctx->Wpf_Logger->error($tag, "post msg =" . json_encode($_POST));
49+
echo json_encode(["errorCode" => "success", "errorInfo" => ""]);
50+
}catch (Exception $ex) {
51+
echo json_encode(["errorCode" => "error.alert", 'errorInfo' => $ex->getMessage()]);
52+
}
53+
} else {
54+
$pageUrl = $_COOKIE['duckchat_page_url'];
55+
$pageUrl = parse_url($pageUrl);
56+
parse_str($pageUrl['query'], $queries);
57+
$x = $queries['x'];
58+
list($type, $toId) = explode("-", $x);
59+
if($toId == $this->userId) {
60+
return;
61+
}
62+
63+
if($type == $this->groupType) {
64+
$roomType = "MessageRoomGroup";
65+
}elseif($type == $this->u2Type) {
66+
$roomType = "MessageRoomU2";
67+
}
68+
69+
$results = [
70+
"roomType" => $roomType,
71+
"toId" => $toId,
72+
"fromUserId" => $this->userId,
73+
];
74+
75+
$gifs = [
76+
[
77+
"url" => "https://media.giphy.com/media/NWLUwtaivTes8/200w_d.gif",
78+
"width" => 200,
79+
"height" => 200
80+
],
81+
[
82+
"url" => "https://media.giphy.com/media/NWLUwtaivTes8/200w_d.gif",
83+
"width" => 200,
84+
"height" => 200
85+
],
86+
[
87+
"url" => "https://media.giphy.com/media/NWLUwtaivTes8/200w_d.gif",
88+
"width" => 200,
89+
"height" => 200
90+
],
91+
[
92+
"url" => "https://media.giphy.com/media/NWLUwtaivTes8/200w_d.gif",
93+
"width" => 200,
94+
"height" => 200
95+
],
96+
[
97+
"url" => "https://media.giphy.com/media/NWLUwtaivTes8/200w_d.gif",
98+
"width" => 200,
99+
"height" => 200
100+
],[
101+
"url" => "https://media.giphy.com/media/NWLUwtaivTes8/200w_d.gif",
102+
"width" => 200,
103+
"height" => 200
104+
]
105+
];
106+
$result = $this->ctx->SiteUserGifTable->getGif($this->userId, 0, $this->limit);
107+
$gifs = array_merge_recursive($result, $gifs);
108+
$results['gifs'] = $gifs;
109+
$results['gifs'] = json_encode($results['gifs']);
110+
echo $this->display("miniProgram_gif_index", $results);
111+
return;
112+
}
113+
}
114+
private function sendWebMessage($msg)
115+
{
116+
117+
$sendMsg = $msg['message'];
118+
$roomType = $sendMsg['roomType'] == "MessageRoomU2" ? \Zaly\Proto\Core\MessageRoomType::MessageRoomU2 : \Zaly\Proto\Core\MessageRoomType::MessageRoomGroup;
119+
120+
if($roomType == \Zaly\Proto\Core\MessageRoomType::MessageRoomU2) {
121+
$userRelationReq = new \Zaly\Proto\Plugin\DuckChatUserRelationRequest();
122+
$userRelationReq->setUserId($this->userId);
123+
$userRelationReq->setOppositeUserId($sendMsg['toUserId']);
124+
$response = $this->requestDuckChatInnerApi($this->gifMiniProgramId, $this->userRelationAction, $userRelationReq);
125+
126+
if($response->getRelationType() != \Zaly\Proto\Core\FriendRelationType::FriendRelationFollow) {
127+
$errorCode = $this->zalyError->errorFriend;
128+
$errorInfo = $this->zalyError->getErrorInfo($errorCode);
129+
throw new Exception($errorInfo);
130+
}
131+
132+
$userRelationReq = new \Zaly\Proto\Plugin\DuckChatUserRelationRequest();
133+
$userRelationReq->setUserId($sendMsg['toUserId']);
134+
$userRelationReq->setOppositeUserId($this->userId);
135+
$response = $this->requestDuckChatInnerApi($this->gifMiniProgramId, $this->userRelationAction, $userRelationReq);
136+
137+
if($response->getRelationType() != \Zaly\Proto\Core\FriendRelationType::FriendRelationFollow) {
138+
$errorCode = $this->zalyError->errorFriend;
139+
$errorInfo = $this->zalyError->getErrorInfo($errorCode);
140+
throw new Exception($errorInfo);
141+
}
142+
143+
}
144+
145+
$webMsg = new \Zaly\Proto\Core\WebMessage();
146+
147+
$webMsg->setWidth($sendMsg['web']['width']);
148+
$webMsg->setHeight($sendMsg['web']['height']);
149+
$webMsg->setCode($sendMsg['web']['code']);
150+
$webMsg->setHrefURL($sendMsg['web']['hrefURL']);
151+
152+
$message = new \Zaly\Proto\Core\Message();
153+
$message->setMsgId($sendMsg['msgId']);
154+
$message->setType(\Zaly\Proto\Core\MessageType::MessageWeb);
155+
$message->setTimeServer($sendMsg['timeServer']);
156+
$message->setWeb($webMsg);
157+
$message->setRoomType($roomType);
158+
$message->setFromUserId($this->userId);
159+
if($roomType == \Zaly\Proto\Core\MessageRoomType::MessageRoomU2) {
160+
$message->setToUserId($sendMsg['toUserId']);
161+
} else {
162+
$message->setToGroupId($sendMsg['toGroupId']);
163+
}
164+
165+
$duckchatReqData = new \Zaly\Proto\Plugin\DuckChatMessageSendRequest();
166+
$duckchatReqData->setMessage($message);
167+
$this->requestDuckChatInnerApi($this->gifMiniProgramId, $this->action, $duckchatReqData);
168+
}
169+
170+
public function addGif($data)
171+
{
172+
$gifId = $data['gifId'];
173+
$data = [
174+
'userId' => $this->userId,
175+
'gifId' => $gifId,
176+
'addTime' => ZalyHelper::getMsectime()
177+
];
178+
$this->ctx->SiteUserGifTable->addGif($data);
179+
}
180+
}

src/controller/UpdateVersionController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public function index()
3939
if($configOlder['dbVersion'] < $configSampleNew['dbVersion']) {
4040
$className = "DB_Version_V".$configSampleNew['dbVersion'];
4141
require (dirname(__DIR__)."/model/DB/".$className.".php");
42-
$className::getInstance()->upgradeDB();
42+
new $className();
43+
$configOlder['dbVersion'] = $configSampleNew['dbVersion'];
44+
$contents = var_export($configOlder, true);
45+
file_put_contents($configFileName, "<?php\n return {$contents};\n ");
46+
if (function_exists("opcache_reset")) {
47+
opcache_reset();
48+
}
4349
}
4450
$indexUrl = ZalyConfig::getConfig("apiPageIndex");
4551
header("Location:".$indexUrl);

src/lib/Util/ZalyErrorBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ abstract class ZalyErrorBase
4646
public $errorFriendApplyFriendExists = "error.friend.apply.friendExist";
4747
public $errorFriendUpdate = "error.friend.update";
4848
public $errorFriendDelete = "error.friend.delete";
49+
public $errorFriend = "error.friend";
4950

5051
public $errorFileDownload = "error.file.download";
5152

src/lib/Util/ZalyErrorEn.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ZalyErrorEn extends ZalyErrorBase
2020
"error.group.create.permission" => "Not allow create group",
2121
"error.group.create" => "Create failed",
2222
"error.group.exist" => "The group has been dissolved",
23-
"error.group.owner" => "只有群主可以操作",
23+
"error.group.owner" => "No permission to operate",
2424
"error.group.admin" => "No permission to operate",
2525
"error.group.delete" => "No permission to operate",
2626
"error.group.maxMemberCount" => "Full of members",
@@ -40,6 +40,7 @@ class ZalyErrorEn extends ZalyErrorBase
4040
"error.friend.apply.friendExist" => "Already a friend",
4141
"error.friend.update" => "Update failed",
4242
"error.friend.delete" => "Delete failed",
43+
"error.friend" => "not friend",
4344
"error.file.download" => "Downlod Failed",
4445
"error.group.invite" => "Invitation failed",
4546

src/lib/Util/ZalyErrorZh.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ZalyErrorZh extends ZalyErrorBase
4141
"error.friend.apply.friendExist" => "已经是好友",
4242
"error.friend.update" => "更新数据失败",
4343
"error.friend.delete" => "删除失败",
44+
"error.friend" => "不是好友",
4445
"error.file.download" => "下载失败",
4546
"error.group.invite" => "邀请失败",
4647

src/model/BaseCtx.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @property ZalyRsa ZalyRsa
3636
* @property ZalyAes ZalyAes
3737
* @property ZalyHelper ZalyHelper
38+
* @property SiteUserGifTable SiteUserGifTable
3839
*
3940
* @property Pinyin Pinyin
4041
*

src/model/DB/DB_Base.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,4 @@ public function checkTableExists($tableName)
3737
$this->wpf_Logger->error($tag, "error_msg ==" . $ex->getMessage());
3838
}
3939
}
40-
41-
4240
}

0 commit comments

Comments
 (0)