You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Service;
use App\Models\AdminSetting;use EasyWeChat\Factory;use EasyWeChat\OpenPlatform\Application;
/** * 微信第三方开放平台 * Class OpenPlatform * @package App\Service */class OpenPlatform{ public array $config = []; private Application $openPlatform;
// private static self $instance;
public function __construct() { $setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); $this->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); }
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; }}
|