Skip to content

Commit 38a2584

Browse files
Merge pull request #61 from lienze741/master
二维码相关和短链接
2 parents b841923 + 78297c9 commit 38a2584

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

src/Bean/OfficialAccount/RequestConst.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,4 @@ class RequestConst
7676
//点击菜单跳转小程序的事件推送
7777
const EVENT_VIEW_MINIPROGRAM = 'view_miniprogram';
7878

79-
8079
}

src/OfficialAccount/ApiUrl.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ class ApiUrl
347347
*/
348348
const MESSAGE_CUSTOM_TYPING = 'https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN';
349349

350+
/*
351+
* 将一条长链接转成短链接
352+
*/
353+
const SHORT_URL = 'https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN';
354+
350355
/*
351356
* 创建二维码ticket
352357
*/

src/OfficialAccount/Comment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function delete($msgDataId, $userCommentId, $index = 0)
9292
* @throws \EasySwoole\HttpClient\Exception\InvalidUrl
9393
* @throws \EasySwoole\WeChat\Exception\RequestError
9494
*/
95-
public function UnMarkelect($msgDataId, $userCommentId, $index = 0)
95+
public function unMarkelect($msgDataId, $userCommentId, $index = 0)
9696
{
9797
return $this->send(ApiUrl::COMMENT_UNMARKELECT, [
9898
'msg_data_id' => $msgDataId,
@@ -113,7 +113,7 @@ public function UnMarkelect($msgDataId, $userCommentId, $index = 0)
113113
* @throws \EasySwoole\HttpClient\Exception\InvalidUrl
114114
* @throws \EasySwoole\WeChat\Exception\RequestError
115115
*/
116-
public function Markelect($msgDataId, $userCommentId, $index = 0)
116+
public function markelect($msgDataId, $userCommentId, $index = 0)
117117
{
118118
return $this->send(ApiUrl::COMMENT_MARKELECT, [
119119
'msg_data_id' => $msgDataId,
@@ -136,7 +136,7 @@ public function Markelect($msgDataId, $userCommentId, $index = 0)
136136
* @throws \EasySwoole\HttpClient\Exception\InvalidUrl
137137
* @throws \EasySwoole\WeChat\Exception\RequestError
138138
*/
139-
public function View($msgDataId, $begin, $count, $type, $index = 0)
139+
public function view($msgDataId, $begin, $count, $type, $index = 0)
140140
{
141141
return $this->send(ApiUrl::COMMENT_LIST, [
142142
'msg_data_id' => $msgDataId,

src/OfficialAccount/QrCode.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,34 @@ public static function tickToImageUrl(QrCodeBean $code): ?string
5151
'TICKET' => $code->getTicket()
5252
]);
5353
}
54+
55+
/**
56+
* 将一条长链接转成短链接
57+
*
58+
* @param string $url
59+
*
60+
* @return null|string
61+
* @throws InvalidUrl
62+
* @throws OfficialAccountError
63+
* @throws RequestError
64+
*/
65+
public function shorturl(string $url): ?string
66+
{
67+
68+
$response = NetWork::postJsonForJson(ApiUrl::generateURL(ApiUrl::SHORT_URL, [
69+
'ACCESS_TOKEN' => $this->getOfficialAccount()->accessToken()->getToken()
70+
]), [
71+
'action' => 'long2short',
72+
'long_url' => $url
73+
]);
74+
75+
$ex = OfficialAccountError::hasException($response);
76+
if ($ex) {
77+
throw $ex;
78+
} else {
79+
return $response['short_url'];
80+
}
81+
}
82+
83+
5484
}

src/OfficialAccount/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function blacklist(string $beginOpenid = null)
119119
* @throws \EasySwoole\WeChat\Exception\OfficialAccountError
120120
* @throws \EasySwoole\WeChat\Exception\RequestError
121121
*/
122-
public function block($openidList)
122+
public function black($openidList)
123123
{
124124
$url = ApiUrl::generateURL(ApiUrl::BATCH_BLACKLIST, [
125125
'ACCESS_TOKEN'=> $this->getOfficialAccount()->accessToken()->getToken()
@@ -135,7 +135,7 @@ public function block($openidList)
135135
* @throws \EasySwoole\WeChat\Exception\OfficialAccountError
136136
* @throws \EasySwoole\WeChat\Exception\RequestError
137137
*/
138-
public function unblock($openidList)
138+
public function unblack($openidList)
139139
{
140140
$url = ApiUrl::generateURL(ApiUrl::BATCH_UNBLACKLIST, [
141141
'ACCESS_TOKEN'=> $this->getOfficialAccount()->accessToken()->getToken()

0 commit comments

Comments
 (0)