Skip to content

Commit 1c664dd

Browse files
Merge pull request #106 from LinkedDestiny/1.2.x
add miniprogram urlscheme api
2 parents dac28e6 + 0e49ea2 commit 1c664dd

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
vendor/
3+
composer.lock

src/MiniProgram/ApiUrl.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ class ApiUrl
387387
*/
388388
const SUBSCRIBE_SEND = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN';
389389

390+
/**
391+
* 获取小程序scheme码
392+
* @see https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
393+
*/
394+
const URL_SCHEME_GENERATE = 'https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN';
395+
396+
390397
/**
391398
* 生成访问链接
392399
* @param string $baseUrl 基础链接

src/MiniProgram/MiniProgram.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MiniProgram
2020
private $qrCode;
2121
private $templateMsg;
2222
private $subscribeMsg;
23+
private $urlscheme;
2324

2425
public function __construct(MiniProgramConfig $config = null, AccessTokenInterface $accessToken = null)
2526
{
@@ -131,4 +132,16 @@ public function subscribeMsg():SubscribeMsg
131132

132133
return $this->subscribeMsg;
133134
}
135+
136+
/**
137+
* @return UrlScheme
138+
*/
139+
public function urlScheme():UrlScheme
140+
{
141+
if (!isset($this->urlscheme)) {
142+
$this->urlscheme = new UrlScheme($this);
143+
}
144+
145+
return $this->urlscheme;
146+
}
134147
}

src/MiniProgram/UrlScheme.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
namespace EasySwoole\WeChat\MiniProgram;
7+
8+
9+
use EasySwoole\WeChat\Exception\MiniProgramError;
10+
use EasySwoole\WeChat\Exception\RequestError;
11+
use EasySwoole\WeChat\Utility\NetWork;
12+
13+
class UrlScheme extends MinProgramBase
14+
{
15+
/**
16+
* 生成URL SCHEME
17+
* @param string $path
18+
* @param string $query
19+
* @param bool $isExpire
20+
* @param int $expireAt
21+
* @return array
22+
* @throws MiniProgramError
23+
* @throws RequestError
24+
*/
25+
public function generate(string $path, string $query, bool $isExpire = false, int $expireAt = 0)
26+
{
27+
$token = $this->getMiniProgram()->accessToken()->getToken();
28+
$url = ApiUrl::generateURL(ApiUrl::URL_SCHEME_GENERATE, [
29+
'ACCESS_TOKEN' => $token,
30+
]);
31+
32+
$responseArray = NetWork::postJsonForJson($url, [
33+
'jump_wxa' => [
34+
'path' => $path,
35+
'query' => $query
36+
],
37+
'is_expire' => $isExpire,
38+
'expire_time' => $expireAt
39+
]);
40+
$ex = MiniProgramError::hasException($responseArray);
41+
if ($ex) {
42+
throw $ex;
43+
}
44+
45+
return $responseArray;
46+
}
47+
}

0 commit comments

Comments
 (0)