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; + } +}