From 8a79af322a4a1d2b904c02ff5aceb35cc2b1d12c Mon Sep 17 00:00:00 2001 From: EZ <123400558@qq.com> Date: Wed, 22 Apr 2020 22:19:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=92=8C=E7=9F=AD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Bean/OfficialAccount/QrCode.php | 17 +++++++++++++ src/Bean/OfficialAccount/RequestConst.php | 3 +-- src/OfficialAccount/ApiUrl.php | 5 ++++ src/OfficialAccount/Comment.php | 6 ++--- src/OfficialAccount/QrCode.php | 30 +++++++++++++++++++++++ src/OfficialAccount/User.php | 4 +-- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/Bean/OfficialAccount/QrCode.php b/src/Bean/OfficialAccount/QrCode.php index dbe8fb1..5dbe236 100644 --- a/src/Bean/OfficialAccount/QrCode.php +++ b/src/Bean/OfficialAccount/QrCode.php @@ -16,6 +16,7 @@ class QrCode extends SplBean protected $ticket; protected $expire_seconds; protected $url; + protected $short_url; /** * @return mixed @@ -64,4 +65,20 @@ public function setUrl($url): void { $this->url = $url; } + + /** + * @return mixed + */ + public function getShortUrl() + { + return $this->short_url; + } + + /** + * @param mixed $url + */ + public function setShortUrl($url): void + { + $this->short_url = $url; + } } \ No newline at end of file diff --git a/src/Bean/OfficialAccount/RequestConst.php b/src/Bean/OfficialAccount/RequestConst.php index ad88b89..b2eb12e 100644 --- a/src/Bean/OfficialAccount/RequestConst.php +++ b/src/Bean/OfficialAccount/RequestConst.php @@ -53,7 +53,7 @@ class RequestConst const EVENT_SCAN = 'SCAN'; // 上报地理位置事件 const EVENT_LOCATION = 'LOCATION'; - // 点击自定义菜单拉取消息事件 + // 点击自定义菜单拉取消息事件EVENT_LOCATION const EVENT_CLICK = 'CLICK'; // 点击自定义菜单跳转事件 const EVENT_VIEW = 'VIEW'; @@ -76,5 +76,4 @@ class RequestConst //点击菜单跳转小程序的事件推送 const EVENT_VIEW_MINIPROGRAM = 'view_miniprogram'; - } \ No newline at end of file diff --git a/src/OfficialAccount/ApiUrl.php b/src/OfficialAccount/ApiUrl.php index 53c8b0a..4d20b68 100644 --- a/src/OfficialAccount/ApiUrl.php +++ b/src/OfficialAccount/ApiUrl.php @@ -347,6 +347,11 @@ class ApiUrl */ const MESSAGE_CUSTOM_TYPING = 'https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN'; + /* + * 将一条长链接转成短链接 + */ + const SHORT_URL = 'https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN'; + /* * 创建二维码ticket */ diff --git a/src/OfficialAccount/Comment.php b/src/OfficialAccount/Comment.php index 4d23153..bfc9a9f 100644 --- a/src/OfficialAccount/Comment.php +++ b/src/OfficialAccount/Comment.php @@ -92,7 +92,7 @@ public function delete($msgDataId, $userCommentId, $index = 0) * @throws \EasySwoole\HttpClient\Exception\InvalidUrl * @throws \EasySwoole\WeChat\Exception\RequestError */ - public function UnMarkelect($msgDataId, $userCommentId, $index = 0) + public function unMarkelect($msgDataId, $userCommentId, $index = 0) { return $this->send(ApiUrl::COMMENT_UNMARKELECT, [ 'msg_data_id' => $msgDataId, @@ -113,7 +113,7 @@ public function UnMarkelect($msgDataId, $userCommentId, $index = 0) * @throws \EasySwoole\HttpClient\Exception\InvalidUrl * @throws \EasySwoole\WeChat\Exception\RequestError */ - public function Markelect($msgDataId, $userCommentId, $index = 0) + public function markelect($msgDataId, $userCommentId, $index = 0) { return $this->send(ApiUrl::COMMENT_MARKELECT, [ 'msg_data_id' => $msgDataId, @@ -136,7 +136,7 @@ public function Markelect($msgDataId, $userCommentId, $index = 0) * @throws \EasySwoole\HttpClient\Exception\InvalidUrl * @throws \EasySwoole\WeChat\Exception\RequestError */ - public function View($msgDataId, $begin, $count, $type, $index = 0) + public function view($msgDataId, $begin, $count, $type, $index = 0) { return $this->send(ApiUrl::COMMENT_LIST, [ 'msg_data_id' => $msgDataId, diff --git a/src/OfficialAccount/QrCode.php b/src/OfficialAccount/QrCode.php index 6374b2c..6555167 100644 --- a/src/OfficialAccount/QrCode.php +++ b/src/OfficialAccount/QrCode.php @@ -51,4 +51,34 @@ public static function tickToImageUrl(QrCodeBean $code): ?string 'TICKET' => $code->getTicket() ]); } + + /** + * 将一条长链接转成短链接 + * + * @param string $url + * + * @return null|string + * @throws InvalidUrl + * @throws OfficialAccountError + * @throws RequestError + */ + public function shorturl(string $url): ?string + { + + $response = NetWork::postJsonForJson(ApiUrl::generateURL(ApiUrl::SHORT_URL, [ + 'ACCESS_TOKEN' => $this->getOfficialAccount()->accessToken()->getToken() + ]), [ + 'action' => 'long2short', + 'long_url' => $url + ]); + + $ex = OfficialAccountError::hasException($response); + if ($ex) { + throw $ex; + } else { + return $response['short_url']; + } + } + + } \ No newline at end of file diff --git a/src/OfficialAccount/User.php b/src/OfficialAccount/User.php index d9b8db6..9780f92 100644 --- a/src/OfficialAccount/User.php +++ b/src/OfficialAccount/User.php @@ -119,7 +119,7 @@ public function blacklist(string $beginOpenid = null) * @throws \EasySwoole\WeChat\Exception\OfficialAccountError * @throws \EasySwoole\WeChat\Exception\RequestError */ - public function block($openidList) + public function black($openidList) { $url = ApiUrl::generateURL(ApiUrl::BATCH_BLACKLIST, [ 'ACCESS_TOKEN'=> $this->getOfficialAccount()->accessToken()->getToken() @@ -135,7 +135,7 @@ public function block($openidList) * @throws \EasySwoole\WeChat\Exception\OfficialAccountError * @throws \EasySwoole\WeChat\Exception\RequestError */ - public function unblock($openidList) + public function unblack($openidList) { $url = ApiUrl::generateURL(ApiUrl::BATCH_UNBLACKLIST, [ 'ACCESS_TOKEN'=> $this->getOfficialAccount()->accessToken()->getToken() From b6342981566a3a3ab43206a3b3bb6bb6073ecfc6 Mon Sep 17 00:00:00 2001 From: EZ <123400558@qq.com> Date: Wed, 22 Apr 2020 22:22:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Bean/OfficialAccount/QrCode.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Bean/OfficialAccount/QrCode.php b/src/Bean/OfficialAccount/QrCode.php index 5dbe236..dbe8fb1 100644 --- a/src/Bean/OfficialAccount/QrCode.php +++ b/src/Bean/OfficialAccount/QrCode.php @@ -16,7 +16,6 @@ class QrCode extends SplBean protected $ticket; protected $expire_seconds; protected $url; - protected $short_url; /** * @return mixed @@ -65,20 +64,4 @@ public function setUrl($url): void { $this->url = $url; } - - /** - * @return mixed - */ - public function getShortUrl() - { - return $this->short_url; - } - - /** - * @param mixed $url - */ - public function setShortUrl($url): void - { - $this->short_url = $url; - } } \ No newline at end of file From 78297c9d512204bbe87a41eb8d05895ba4dc9579 Mon Sep 17 00:00:00 2001 From: EZ <123400558@qq.com> Date: Wed, 22 Apr 2020 22:24:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Bean/OfficialAccount/RequestConst.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bean/OfficialAccount/RequestConst.php b/src/Bean/OfficialAccount/RequestConst.php index b2eb12e..2600f9d 100644 --- a/src/Bean/OfficialAccount/RequestConst.php +++ b/src/Bean/OfficialAccount/RequestConst.php @@ -53,7 +53,7 @@ class RequestConst const EVENT_SCAN = 'SCAN'; // 上报地理位置事件 const EVENT_LOCATION = 'LOCATION'; - // 点击自定义菜单拉取消息事件EVENT_LOCATION + // 点击自定义菜单拉取消息事件 const EVENT_CLICK = 'CLICK'; // 点击自定义菜单跳转事件 const EVENT_VIEW = 'VIEW';