Skip to content

Commit b692c42

Browse files
committed
完善PC 端链接打开方式
1 parent d930456 commit b692c42

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/Message/ActionCardMessage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function setMessage(string $title, string $text, $hideAvatar = null, $btn
8787
*
8888
* @param string $singleTitle 单个按钮的方案。(设置此项和singleURL后btns无效。)
8989
* @param string $singleUrl 点击singleTitle按钮触发的URL
90-
* @param bool $pcSlide 链接在钉钉侧栏打开,false则在浏览器打开
90+
* @param bool $pcSlide 链接是否在 PC 端侧栏打开,true 在 PC 端侧栏打开;false 在系统默认浏览器
9191
*
9292
* @return $this
9393
*/
@@ -105,7 +105,7 @@ public function setSingle(string $singleTitle, string $singleUrl, bool $pcSlide
105105
*
106106
* @param string $title 按钮方案
107107
* @param string $actionUrl 点击按钮触发的URL
108-
* @param bool $pcSlide 链接在钉钉侧栏打开,false则在浏览器打开
108+
* @param bool $pcSlide 链接是否在 PC 端侧栏打开,true 在 PC 端侧栏打开;false 在系统默认浏览器
109109
*
110110
* @return ActionCardMessage
111111
*/

src/Message/FeedCardMessage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function setMessage()
3333
* @param string $title 单条信息文本
3434
* @param string $messageUrl 点击单条信息到跳转链接
3535
* @param string $picUrl 单条信息后面图片的URL
36-
* @param bool $pcSlide 链接在钉钉侧栏打开,false则在浏览器打开
36+
* @param bool $pcSlide 链接是否在 PC 端侧栏打开,true 在 PC 端侧栏打开;false 在系统默认浏览器
3737
*
3838
* @return FeedCardMessage
3939
*/
@@ -42,7 +42,7 @@ public function addLink(string $title, string $messageUrl, string $picUrl, bool
4242
$this->message['feedCard']['links'][] = [
4343
'title' => $title,
4444
'messageURL' => $this->getFinalUrl($messageUrl, $pcSlide),
45-
'picURL' => $this->getFinalUrl($picUrl, $pcSlide),
45+
'picURL' => $picUrl,
4646
];
4747

4848
return $this;

src/Message/LinkMessage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
* @param string $text 消息内容。如果太长只会部分展示
3434
* @param string $messageUrl 点击消息跳转的 URL
3535
* @param string $picUrl 图片 URL
36-
* @param bool $pcSlide 链接在钉钉侧栏打开,false则在浏览器打开
36+
* @param bool $pcSlide 链接是否在 PC 端侧栏打开,true 在 PC 端侧栏打开;false 在系统默认浏览器
3737
*
3838
* @return LinkMessage
3939
*/
@@ -44,7 +44,7 @@ public function setMessage(string $title, string $text, string $messageUrl, stri
4444
'link' => [
4545
'title' => $title,
4646
'text' => $text,
47-
'picUrl' => $this->getFinalUrl($picUrl, $pcSlide),
47+
'picUrl' => $picUrl,
4848
'messageUrl' => $this->getFinalUrl($messageUrl, $pcSlide),
4949
],
5050
];

src/Message/Message.php

+17-12
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ abstract class Message
1818
// 设置机器人名称,默认为 default,会根据名称去找配置
1919
protected $robot = 'default';
2020

21-
/**
22-
* 获取最终URL.
23-
* @param string $url
24-
* @param bool $pcSlide
25-
*
26-
* @return string
27-
*/
28-
public function getFinalUrl($url, $pcSlide = true): string
29-
{
30-
return sprintf('dingtalk://dingtalkclient/page/link?url=%s&pc_slide=%s', urlencode($url), $pcSlide ? 'true' : 'false');
31-
}
32-
3321
/**
3422
* 获取消息请求的请求体内容.
3523
*
@@ -63,4 +51,21 @@ public function getRobot(): string
6351
{
6452
return $this->robot;
6553
}
54+
55+
/**
56+
* 将 URL 转换成指定的 schema 形式,以便控制其 PC 端打开方式为钉钉侧边栏或系统默认浏览器
57+
*
58+
* @link https://ding-doc.dingtalk.com/doc#/serverapi2/iat9q8/e300ae98
59+
*
60+
* @param string $url
61+
* @param bool $pcSlide
62+
*
63+
* @return string
64+
*/
65+
public function getFinalUrl(string $url, bool $pcSlide = true): string
66+
{
67+
return sprintf(
68+
'dingtalk://dingtalkclient/page/link?url=%s&pc_slide=%s', urlencode($url), $pcSlide ? 'true' : 'false'
69+
);
70+
}
6671
}

0 commit comments

Comments
 (0)