{"id":15374481,"url":"https://github.com/yurunsoft/apiagent","last_synced_at":"2025-04-15T11:33:06.595Z","repository":{"id":57088752,"uuid":"93714874","full_name":"Yurunsoft/ApiAgent","owner":"Yurunsoft","description":"PHP开发的API接口代理，支持跨域接口代理和接口合并请求功能。程序员聚集群：74401592","archived":false,"fork":false,"pushed_at":"2018-04-12T01:22:06.000Z","size":38,"stargazers_count":36,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T21:01:51.792Z","etag":null,"topics":["api","composer","php"],"latest_commit_sha":null,"homepage":"http://git.oschina.net/yurunsoft/apiagent","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/Yurunsoft.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":"2017-06-08T06:28:03.000Z","updated_at":"2024-12-16T05:39:10.000Z","dependencies_parsed_at":"2022-08-20T15:30:16.579Z","dependency_job_id":null,"html_url":"https://github.com/Yurunsoft/ApiAgent","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FApiAgent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FApiAgent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FApiAgent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FApiAgent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yurunsoft","download_url":"https://codeload.github.com/Yurunsoft/ApiAgent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249061231,"owners_count":21206474,"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":["api","composer","php"],"created_at":"2024-10-01T13:58:52.905Z","updated_at":"2025-04-15T11:33:06.365Z","avatar_url":"https://github.com/Yurunsoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ApiAgent\r\n\r\n## 简介\r\n\r\nAPI接口代理，支持跨域接口代理和接口合并请求功能。\r\n\r\n## [在线文档](http://doc.yurunsoft.com/ApiAgent \"在线文档\")\r\n\r\n## 安装\r\n\r\n### 当作类库使用\r\n\r\n在您的composer.json中加入配置：\r\n\r\n```json\r\n{\r\n    \"require\": {\r\n        \"yurunsoft/api-agent\": \"1.0.*\"\r\n    }\r\n}\r\n```\r\n\r\n### 作为项目运行\r\n\r\n切换到ApiAgent目录下，执行下列命令：\r\n\r\n```\r\ncomposer install\r\n```\r\n\r\n## 跨域接口代理\r\n\r\n通过`index.php`文件访问，默认参数为`url`，注意需要`urlencode`编码。\r\n\r\n例子：`http://apiagent.toolapi.net/?url=http://www.baidu.com`\r\n\r\n\u003e （上面是在线演示地址，随时可能崩掉，正式使用时请改成你自己的！）\r\n\r\n该接口原样返回状态码、返回头（包括cookie）、返回内容。\r\n\r\n配置文件：`Config/cross.php`\r\n\r\n## 接口合并请求\r\n\r\n通过`batch.php`文件访问，请求规则是POST提交json格式内容。\r\n\r\n配置文件：`Config/batch.php`\r\n\r\njQuery调用样例代码：\r\n\r\n~~~js\r\n// 设置跨域传递cookie，如果不需要可以去除\r\n$.ajaxSetup({\r\n\txhrFields: {\r\n\t\twithCredentials: true\r\n\t},\r\n});\r\n$.ajax({\r\n\t// 在线演示地址，随时可能崩掉，正式使用时请改成你自己的\r\n\turl: 'http://apiagent.toolapi.net/batch.php',\r\n\tmethod: 'post',\r\n\tdata: JSON.stringify({\r\n\t\t/*aip: {\r\n\t\t\turl: 'ip', // 在apis中预定义的接口，传别名即可\r\n\t\t\tgetData: {ip: '218.4.255.255'},\r\n\t\t},*/\r\n\t\taip: {\r\n\t\t\turl: 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json',\r\n\t\t\tgetData: {ip: '218.4.255.255'}, // 这里的IP改变也会改变下面baike的结果哦\r\n\t\t},\r\n\t\t// weather2是错误的结果，会中断\r\n\t\t/*weather2: {\r\n\t\t\turl: 'http://www.weather.com.cn/data/sk/1010101001.html',\r\n\t\t\tcondition: { // 返回结果.weatherinfo不为null\r\n\t\t\t\tvalue: '{$weather2.weatherinfo}',\r\n\t\t\t\tregular: 'is not null',\r\n\t\t\t},\r\n\t\t},*/\r\n\t\tbaike: {\r\n\t\t\turl: 'http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?scope=103\u0026format=json\u0026appid=379020\u0026bk_length=600',\r\n\t\t\t// get参数\r\n\t\t\tgetData: {\r\n\t\t\t\tbk_key: '{$aip.city}', // api接口中返回的数据.city\r\n\t\t\t},\r\n\t\t\t// post参数\r\n\t\t\tpostData: {},\r\n\t\t\t// GET请求数据类型\r\n\t\t\tgetDataType: 'form',\r\n\t\t\t// POST请求数据类型\r\n\t\t\tbodyDataType: 'form',\r\n\t\t\t// 自定义header，不定义则使用默认\r\n\t\t\theader: {\r\n\t\t\t\t'test': 'aaa',\r\n\t\t\t},\r\n\t\t\t// 验证返回结果是否正确，不正确会中断请求并返回\r\n\t\t\tcondition: {\r\n\t\t\t\tvalue: '{$baike.errno}',\r\n\t\t\t\tregular: 'is not null',\r\n\t\t\t},\r\n\t\t},\r\n\t}),\r\n\tsuccess: function(data)\t{\r\n\t\tconsole.debug(data);\r\n\t}\r\n});\r\n~~~\r\n\r\n### 接口合并请求返回结构\r\n\r\n```js\r\n{\r\n\t// 是否成功\r\n    \"success\": true,\r\n\t// 错误信息\r\n    \"message\": \"\",\r\n\t// 返回正文数据\r\n    \"data\": {\r\n        \"test\": \"\"\r\n    },\r\n\t// 返回结果\r\n    \"result\": {\r\n\t\t// 键名=\u003e返回头数据\r\n        \"test\": {\r\n\t\t\t// 状态码\r\n            \"status_code\": 208,\r\n\t\t\t// 返回头\r\n            \"header\": {\r\n                \"Server\": \"squid/3.5.20\",\r\n                \"Date\": \"Mon, 09 Oct 2017 07:38:54 GMT\",\r\n                \"Content-Type\": \"application/octet-stream\",\r\n                \"Content-Length\": \"0\",\r\n                \"Connection\": \"keep-alive\"\r\n            },\r\n\t\t\t// 请求耗时\r\n            \"time\": 0.047\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n### 预定义验证规则\r\n\r\n| 代码 | 含义 |\r\n| --- | --- |\r\n| is null | null === $value |\r\n| is not null | null !== $value |\r\n| empty array | 0 === count($value[0]) |\r\n| not empty array | count($value[0]) \u003e 0 |\r\n| true | true === $value |\r\n| false | false === $value |\r\n\r\n\u003e 除了预定义规则，你还可以编写正则来验证。如：\\d+\r\n\r\n### dataType数据类型\r\n\r\n| 名称 | 含义 |\r\n| --- | --- |\r\n| form | 表单参数格式(如：a=1\u0026b=2)，默认 |\r\n| json | 转为json格式提交 |\r\n\u003e 不传默认为form，其它名称不对传递来的参数做任何处理","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurunsoft%2Fapiagent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyurunsoft%2Fapiagent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurunsoft%2Fapiagent/lists"}