{"id":17933167,"url":"https://github.com/thisliu/easy-meituan","last_synced_at":"2025-03-24T06:31:50.766Z","repository":{"id":37715007,"uuid":"426678709","full_name":"thisliu/easy-meituan","owner":"thisliu","description":"PHP 美团开放平台（外卖）SDK","archived":false,"fork":false,"pushed_at":"2023-05-07T07:21:12.000Z","size":70,"stargazers_count":40,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T02:45:30.388Z","etag":null,"topics":["meituan","meituan-sdk","php","php-sdk"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thisliu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-10T15:38:09.000Z","updated_at":"2024-10-08T07:27:52.000Z","dependencies_parsed_at":"2024-10-28T21:38:01.002Z","dependency_job_id":"ff0c407c-6b0b-4f37-bc65-0c86605f4101","html_url":"https://github.com/thisliu/easy-meituan","commit_stats":{"total_commits":54,"total_committers":4,"mean_commits":13.5,"dds":0.2407407407407407,"last_synced_commit":"8ad2ffa4e7547522953b4bf2ddc41a57843f6ce7"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisliu%2Feasy-meituan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisliu%2Feasy-meituan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisliu%2Feasy-meituan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisliu%2Feasy-meituan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thisliu","download_url":"https://codeload.github.com/thisliu/easy-meituan/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245222693,"owners_count":20580212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["meituan","meituan-sdk","php","php-sdk"],"created_at":"2024-10-28T21:37:55.332Z","updated_at":"2025-03-24T06:31:45.733Z","avatar_url":"https://github.com/thisliu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e finecho/meituan \u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e 美团开放平台 SDK\u003c/p\u003e\n\n## 温馨提示\n⚠️  目前仅支持美团外卖服务\n\n## 安装\n\n环境要求：\n\n- PHP \u003e= 8.0\n\n```shell\ncomposer require finecho/meituan -vvv\n```\n\n## 配置\n\n```php\n$config = [\n    // 必填，app_id、secret_id\n    'app_id' =\u003e 10020201024, \n    'secret_id' =\u003e 'AKIDsiQzQla780mQxLLU2GJCxxxxxxxxxxx', \n    \n    // 是否开启表单验证\n    'form_verify' =\u003e false,\n];\n```\n\n## 使用\n\n您可以使用三种调用方式：封装方式调用、原始方式调用 和 链式调用，请根据你的喜好自行选择使用方式，效果一致。\n\n### 方式一 - 封装方式调用\n\n```php\nuse EasyMeiTuan\\Application;\n\n$app = new Application($config);\n\n$response = $app-\u003estore-\u003ecreate(\n    [\n        'name'    =\u003e 'finecho 的快餐店',\n        'address' =\u003e '深圳市南山区',\n    ]\n);\n\n// 也可以这样\n$response = $app-\u003estore-\u003ecreate(\n    [\n        'body' =\u003e [\n            'name'    =\u003e 'finecho 的快餐店',\n            'address' =\u003e '深圳市南山区',\n        ],\n        'headers' =\u003e [],\n    ]\n);\n```\n\n### 方式二 - 原始方式调用\n\n```php\nuse EasyMeiTuan\\Application;\n\n$app = new Application($config);\n\n$api = $app-\u003egetClient();\n\n$response = $api-\u003epost(\n    '/poi/save',\n    [\n        'name'    =\u003e 'finecho 的快餐店',\n        'address' =\u003e '深圳市南山区',\n    ]\n);\n```\n\n### 方式三 - 链式调用\n\n你可以将需要调用的 API 以 / 分割 + 驼峰写法的形式，写成如下模式：\n\n```php\nuse EasyMeiTuan\\Application;\n\n$app = new Application($config);\n\n$api = $app-\u003egetClient();\n\n$response = $api-\u003epoi-\u003esave-\u003epost(\n    [\n        'name'    =\u003e 'finecho 的快餐店',\n        'address' =\u003e '深圳市南山区',\n    ]\n);\n```\n\n## 表单校验\n\n如果开启表单校验，如果参数缺失或者异常，则会抛出 [InvalidParamsException](https://github.com/finecho/easy-meituan/blob/main/src/Exceptions/InvalidParamsException.php) 异常\n\n## 美团推送\n\n在接收美团推送的时候，`Server` 会对签名进行校验，并返回解码后的内容\n\n```php\n$server = $app-\u003egetServer();\n\n// url：在美团外卖设置的回调地址\n// content：美团外卖推送过来的内容, 在美团外卖开放平台配置回调地址美团服务器发起验证码时 content 为空数组\n$server-\u003ewithUrl($url)-\u003ewith(\n    function ($content) {\n        // ...\n    }\n);\n\nreturn $server-\u003eserve();\n```\n\n签名校验的时候, 需要将已编码的字段内容进行解码，SDK 提供属性可自行配置 decode 规则。\n- url：对值进行 `urldecode`\n- json：为对值进行 `json_decode(val, true)`\n```php\n// 默认需要解码字段以及规则\n\\EasyMeiTuan\\Server::$casts = [\n    'caution' =\u003e 'url',\n    'detail' =\u003e 'url|json',\n    'extras' =\u003e 'url|json',\n    'recipient_name' =\u003e 'url',\n    'wm_poi_address' =\u003e 'url',\n    'recipient_address' =\u003e 'url',\n    'incmp_modules' =\u003e 'url|json',\n    'order_tag_list' =\u003e 'url|json',\n    'backup_recipient_phone' =\u003e 'url|json',\n    'recipient_address_desensitization' =\u003e 'url',\n\n    // FBI Warning: nested content needs to pay attention to the order!\n    'poi_receive_detail_yuan' =\u003e 'url|json',\n    'poi_receive_detail_yuan.reconciliationExtras' =\u003e 'json',\n    'poi_receive_detail' =\u003e 'url|json',\n    'poi_receive_detail.reconciliationExtras' =\u003e 'json',\n];\n```\n\n## API\n\nAPI 接口众多，每一个 API 都会注释上美团文档地址，查询困难时，可以直接搜索匹配。\n\n### :globe_with_meridians: 门店\n\n[美团门店文档](https://developer.waimai.meituan.com/home/doc/food/1)\n\n具体方法：[src/Services/Store.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/Store.php)\n\n```php\n$app-\u003estore-\u003e$method();\n```\n\n### :truck: 配送范围\n\n[美团配送文档](https://developer.waimai.meituan.com/home/doc/food/2)\n\n具体方法：[src/Services/DeliveryRange.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/DeliveryRange.php)\n\n```php\n$app-\u003edeliveryRange-\u003e$method();\n```\n\n### :memo: 类目\n\n[美团类目文档](https://developer.waimai.meituan.com/home/doc/food/3)\n\n具体方法：[src/Services/Category.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/Category.php)\n\n```php\n$app-\u003ecategory-\u003e$method();\n```\n\n### :beers: 菜品\n\n[美团菜品文档](https://developer.waimai.meituan.com/home/doc/food/3)\n\n具体方法：[src/Services/Product.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/Product.php)\n\n```php\n$app-\u003eproduct-\u003e$method();\n```\n\n### :page_facing_up: 订单\n\n[美团订单文档](https://developer.waimai.meituan.com/home/doc/food/6)\n\n具体方法：[src/Services/Order.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/Order.php)\n\n```php\n$app-\u003eorder-\u003e$method();\n```\n\n#### :wastebasket: 订单退款\n\n具体方法：[src/Services/Refund.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/Refund.php)\n\n```php\n$app-\u003erefund-\u003e$method();\n```\n\n#### :truck: 订单配送\n\n具体方法：[src/Services/Logistic.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/Logistic.php)\n\n```php\n$app-\u003elogistic-\u003e$method();\n```\n\n#### :package: 众包\n\n具体方法：[src/Services/CrowdSourcing.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/CrowdSourcing.php)\n\n```php\n$app-\u003ecrowdSourcing-\u003e$method();\n```\n\n### :wrench: 全局公共\n\n具体方法：[src/Services/Product.php](https://github.com/finecho/easy-meituan/blob/main/src/Services/Product.php)\n\n```php\n$app-\u003ecommon-\u003e$method();\n```\n\n### 返回值\n\nAPI Client 基于 [symfony/http-client](https://symfony.com/doc/current/http_client.html) 实现，你可以通过以下方式对响应值进行访问：\n\n```php\n// 获取状态码\n$statusCode = $response-\u003egetStatusCode();\n// 获取全部响应头\n$headers = $response-\u003egetHeaders();\n// 获取响应原始内容\n$content = $response-\u003egetContent();\n// 获取 json 转换后的数组格式\n$content = $response-\u003etoArray();\n// 将内容转换成 Stream 返回\n$content = $response-\u003etoStream();\n// 获取其他信息，如：\"response_headers\", \"redirect_count\", \"start_time\", \"redirect_url\" 等.\n$httpInfo = $response-\u003egetInfo();\n// 获取指定信息\n$startTime = $response-\u003egetInfo('start_time');\n// 获取请求日志\n$httpLogs = $response-\u003egetInfo('debug');                                             \n```\n\n在原有 Response 的基础上，增加了以下几种方法：\n\n```php\n// 请求是否正常\n$isSuccess = $response-\u003eisSuccess(): bool;\n// 请求是否出现异常\n$hasError = $response-\u003ehasError(): bool;\n// 获取错误内容（code + msg）\n$error = $response-\u003egetError(): array;\n// 获取错误信息\n$error = $response-\u003egetErrorMsg(): ?string;\n// 获取错误码\n$error = $response-\u003egetErrorCode(): string|int|null;\n// 获取正常返回的数据\n$data = $response-\u003egetData(): mixed;\n\n```\n\n## 一个比较完整的示例\n\n```php\nrequire __DIR__ .'/vendor/autoload.php';\n\nuse EasyMeiTuan\\Application;\nuse EasyMeiTuan\\Exceptions\\InvalidParamsException;\n\n$config = [\n    'app_id' =\u003e 'xxx',\n    'secret_id' =\u003e 'xxxxxxxxxxx',\n    'form_verify' =\u003e true,\n];\n\n$app = new Application($config);\n\ntry {\n    $response = $app-\u003estore-\u003elist();\n\n    if ($response-\u003ehasError()) {\n        $error = $response-\u003egetError();\n\n        // .....\n    }\n\n    $data = $response-\u003egetData();\n\n    // ....\n\n} catch (InvalidParamsException $e) {\n    // 捕获到表单异常\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisliu%2Feasy-meituan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthisliu%2Feasy-meituan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisliu%2Feasy-meituan/lists"}