From 1b8224ba5fd180f7ed75bbd999bec05cc151fd80 Mon Sep 17 00:00:00 2001 From: liapples Date: Wed, 15 Sep 2021 19:29:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/OpenPlatform.php | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 app/Service/OpenPlatform.php diff --git a/app/Service/OpenPlatform.php b/app/Service/OpenPlatform.php new file mode 100644 index 0000000..017f1a7 --- /dev/null +++ b/app/Service/OpenPlatform.php @@ -0,0 +1,73 @@ +config = [ + 'app_id' => $setting['service_appid'], + 'secret' => $setting['service_appsecret'], + 'token' => $setting['service_token'], + 'aes_key' => $setting['service_aeskey'], + ]; + + $this->openPlatform = Factory::openPlatform($this->config); + return $this->openPlatform; + } + + /*public static function getInstance(): self + { + if (!self::$instance instanceof self) { + self::$instance = new self(); + } + return self::$instance; + }*/ + + public function refreshToken($appid) + { + return $this->openPlatform->getAuthorizer($appid)['authorization_info']['authorizer_refresh_token'] ?? null; + } + + public function miniProgram($appid, $refreshToken = null) + { + if (is_null($refreshToken)) { + $refreshToken = $this->refreshToken($appid); + } + return $this->openPlatform->miniProgram($appid, $refreshToken)['code'] ?? null; + } + + public function codeTemplate() + { + return $this->openPlatform['code_template'] ?? null; + } + + public function code($appid, $refreshToken = null) + { + if (is_null($refreshToken)) { + $refreshToken = $this->refreshToken($appid); + } + return $this->openPlatform->miniProgram($appid, $refreshToken)['code'] ?? null; + } + + public function component() + { + return $this->openPlatform['component'] ?? null; + } +}