{"id":13603130,"url":"https://github.com/lmhfq/easyopen","last_synced_at":"2026-01-11T14:01:58.426Z","repository":{"id":62518488,"uuid":"288068221","full_name":"lmhfq/easyopen","owner":"lmhfq","description":"一个基于Hyperf框架的简单易用的接口开放平台，平台封装了常用的参数校验、结果返回等功能，开发者只需实现业务代码即可。","archived":false,"fork":false,"pushed_at":"2020-09-15T12:37:39.000Z","size":80,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-08T03:29:39.410Z","etag":null,"topics":["easyopen","hyperf","openapi"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmhfq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-17T02:46:37.000Z","updated_at":"2023-09-12T06:05:32.000Z","dependencies_parsed_at":"2022-11-02T10:31:40.072Z","dependency_job_id":null,"html_url":"https://github.com/lmhfq/easyopen","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lmhfq/easyopen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmhfq%2Feasyopen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmhfq%2Feasyopen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmhfq%2Feasyopen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmhfq%2Feasyopen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmhfq","download_url":"https://codeload.github.com/lmhfq/easyopen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmhfq%2Feasyopen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28306985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easyopen","hyperf","openapi"],"created_at":"2024-08-01T18:01:52.458Z","updated_at":"2026-01-11T14:01:58.406Z","avatar_url":"https://github.com/lmhfq.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"\n# easyopen\n一个简单易用的接口开放平台，平台封装了常用的参数校验、结果返回等功能，开发者只需实现业务代码即可。\n\neasyopen的功能类似于[淘宝开放平台](http://open.taobao.com/docs/api.htm?spm=a219a.7629065.0.0.6cQDnQ\u0026apiId=4)，它的所有接口只提供一个url，通过参数来区分不同业务。这样做的好处是接口url管理方便了，平台管理者只需维护好接口参数即可。由于参数的数量是可知的，这样可以在很大程度上进行封装。封装完后平台开发者只需要写业务代码，其它功能可以通过配置来完成。\n\n\n## 示例\n- 1、定义自己的控制器和网关路由，注入OpenRequestDispatcher 即可\n```\n\u003c?php\nnamespace App\\Controller;\n\nuse Hyperf\\HttpServer\\Annotation\\Controller;\nuse Hyperf\\HttpServer\\Annotation\\RequestMapping;\nuse Hyperf\\HttpServer\\Contract\\RequestInterface;\nuse Lmh\\EasyOpen\\Dispatcher\\OpenRequestDispatcher;\n\n/**\n * @Controller\n */\nclass GateWayController\n{\n    /**\n     * @RequestMapping(path=\"/gateway\",methods={\"GET\",\"POST\"})\n     * @param RequestInterface $request\n     * @param OpenRequestDispatcher $openRequestDispatcher\n     * @return \\Psr\\Http\\Message\\ResponseInterface\n     */\n    public function index(RequestInterface $request, OpenRequestDispatcher $openRequestDispatcher)\n    {\n        return $openRequestDispatcher-\u003edispatch($request);\n    }\n}\n```\n\n- 2、定义开发服务类如下，引入OpenService 和 OpenMapping即可\n```\n\u003c?php\nnamespace App\\Service\\Merchant;\n\n\nuse Lmh\\EasyOpen\\Annotation\\OpenService;\nuse Lmh\\EasyOpen\\Annotation\\OpenMapping;\n/**\n * @OpenService()\n */\nclass MerchantService\n{\n    /**\n     * @OpenMapping(path=\"merchant.create\")\n     * @param array $params\n     * @return string\n     */\n    public function create(array $params = [])\n    {\n        return json_encode($params);\n    }\n}\n```\n\n- 3、 请求数据：\n\n```\n{\n    \"method\": \"merchant.create\",\n    \"app_id\": \"2016072300007148\",\n    \"sign_type\":\"MD5\",\n    \"nonce\":\"xsadasd823mxdjrewrew\",\n    \"sign\": \"2FF9EE4B7908DF976FD11E405529DD67\",\n    \"version\": \"1.0\",\n    \"biz_content\": {\n        \"merchant_name\": \"测试公司\",\n        \"city\": \"杭州\"\n    }\n}\n```\n## 签名密钥获取\n \n- 1、定义数据获取类实现ApplicationDataFetchInterface接口，例如：\n ```\n\u003c?php\nclass ApplicationDataFetchFactory implements ApplicationDataFetchInterface{\n     /**\n     * @var\n     */\n    private $data;\n\n    /**\n     * @param string $appId\n     * @return ApplicationDataFetchInterface\n     * @throws ApplicationDataFetchException\n     */\n    public function make(string $appId): ApplicationDataFetchInterface\n    {\n        //可以存入redis\n        $data = Application::query()-\u003eselect(['appid', 'secret', 'public_key', 'status'])-\u003ewhere(['appid' =\u003e $appId])-\u003efirst();\n        if (!$data) {\n            throw new ApplicationDataFetchException(ErrorSubCode::getMessage(ErrorSubCode::INVALID_APP_ID));\n        }\n        $this-\u003edata = $data;\n        return $this;\n    }\n\n    /**\n     * @inheritDoc\n     */\n    public function getSecret(?string $appId = null): string\n    {\n        return $this-\u003edata['secret'] ?? '';\n    }\n\n    /**\n     * @inheritDoc\n     */\n    public function getPublicKey(?string $appId = null): string\n    {\n        return $this-\u003edata['public_key'] ?? '';\n    }\n\n}\n```\n\n- 2、在 config/autoload/dependencies.php 内完成关系配置：\n ```\n\u003c?php\nreturn [\n   \\Lmh\\EasyOpen\\ApplicationDataFetchInterface::class =\u003e \\App\\Factory\\ApplicationDataFetchFactory::class,\n];\n ```\n\n- 3、发布平台密钥配置文件\n ```\n php bin/hyperf.php vendor:publish lmh/easyopen\n ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmhfq%2Feasyopen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmhfq%2Feasyopen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmhfq%2Feasyopen/lists"}