1. Go to this page and download the library: Download lmh/easyopen library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lmh / easyopen example snippets
namespace App\Service\Merchant;
use Lmh\EasyOpen\Annotation\OpenService;
use Lmh\EasyOpen\Annotation\OpenMapping;
/**
* @OpenService()
*/
class MerchantService
{
/**
* @OpenMapping(path="merchant.create")
* @param array $params
* @return string
*/
public function create(array $params = [])
{
return json_encode($params);
}
}
class ApplicationDataFetchFactory implements ApplicationDataFetchInterface{
/**
* @var
*/
private $data;
/**
* @param string $appId
* @return ApplicationDataFetchInterface
* @throws ApplicationDataFetchException
*/
public function make(string $appId): ApplicationDataFetchInterface
{
//可以存入redis
$data = Application::query()->select(['appid', 'secret', 'public_key', 'status'])->where(['appid' => $appId])->first();
if (!$data) {
throw new ApplicationDataFetchException(ErrorSubCode::getMessage(ErrorSubCode::INVALID_APP_ID));
}
$this->data = $data;
return $this;
}
/**
* @inheritDoc
*/
public function getSecret(?string $appId = null): string
{
return $this->data['secret'] ?? '';
}
/**
* @inheritDoc
*/
public function getPublicKey(?string $appId = null): string
{
return $this->data['public_key'] ?? '';
}
}