Skip to content

Commit

Permalink
Merge pull request #106 from LinkedDestiny/1.2.x
Browse files Browse the repository at this point in the history
add miniprogram urlscheme api
  • Loading branch information
kiss291323003 authored Feb 26, 2021
2 parents dac28e6 + 0e49ea2 commit 1c664dd
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
vendor/
composer.lock
7 changes: 7 additions & 0 deletions src/MiniProgram/ApiUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ class ApiUrl
*/
const SUBSCRIBE_SEND = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN';

/**
* 获取小程序scheme码
* @see https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
*/
const URL_SCHEME_GENERATE = 'https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN';


/**
* 生成访问链接
* @param string $baseUrl 基础链接
Expand Down
13 changes: 13 additions & 0 deletions src/MiniProgram/MiniProgram.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MiniProgram
private $qrCode;
private $templateMsg;
private $subscribeMsg;
private $urlscheme;

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

return $this->subscribeMsg;
}

/**
* @return UrlScheme
*/
public function urlScheme():UrlScheme
{
if (!isset($this->urlscheme)) {
$this->urlscheme = new UrlScheme($this);
}

return $this->urlscheme;
}
}
47 changes: 47 additions & 0 deletions src/MiniProgram/UrlScheme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);


namespace EasySwoole\WeChat\MiniProgram;


use EasySwoole\WeChat\Exception\MiniProgramError;
use EasySwoole\WeChat\Exception\RequestError;
use EasySwoole\WeChat\Utility\NetWork;

class UrlScheme extends MinProgramBase
{
/**
* 生成URL SCHEME
* @param string $path
* @param string $query
* @param bool $isExpire
* @param int $expireAt
* @return array
* @throws MiniProgramError
* @throws RequestError
*/
public function generate(string $path, string $query, bool $isExpire = false, int $expireAt = 0)
{
$token = $this->getMiniProgram()->accessToken()->getToken();
$url = ApiUrl::generateURL(ApiUrl::URL_SCHEME_GENERATE, [
'ACCESS_TOKEN' => $token,
]);

$responseArray = NetWork::postJsonForJson($url, [
'jump_wxa' => [
'path' => $path,
'query' => $query
],
'is_expire' => $isExpire,
'expire_time' => $expireAt
]);
$ex = MiniProgramError::hasException($responseArray);
if ($ex) {
throw $ex;
}

return $responseArray;
}
}

0 comments on commit 1c664dd

Please sign in to comment.