1 Star 0 Fork 18

baitongda / ApiAgent

forked from 宇润 / ApiAgent 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ApiAgent

简介

API接口代理,支持跨域接口代理和接口合并请求功能。

composer安装命令

composer install

中国用户如果使用composer很卡,请查看:https://pkg.phpcomposer.com/

跨域接口代理

通过index.php文件访问,默认参数为url,注意需要urlencode编码。

例子:http://apiagent.toolapi.net/?url=http://www.baidu.com

(上面是在线演示地址,随时可能崩掉,正式使用时请改成你自己的!)

该接口原样返回状态码、返回头(包括cookie)、返回内容。

配置文件:Config/cross.php

接口合并请求

通过batch.php文件访问,请求规则是POST提交json格式内容。

配置文件:Config/batch.php

jQuery调用样例代码:

// 设置跨域传递cookie,如果不需要可以去除
$.ajaxSetup({
	xhrFields: {
		withCredentials: true
	},
});
$.ajax({
	// 在线演示地址,随时可能崩掉,正式使用时请改成你自己的
	url: 'http://apiagent.toolapi.net/batch.php',
	method: 'post',
	data: JSON.stringify({
		/*aip: {
			url: 'ip', // 在apis中预定义的接口,传别名即可
			getData: {ip: '218.4.255.255'},
		},*/
		aip: {
			url: 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json',
			getData: {ip: '218.4.255.255'}, // 这里的IP改变也会改变下面baike的结果哦
		},
		// weather2是错误的结果,会中断
		/*weather2: {
			url: 'http://www.weather.com.cn/data/sk/1010101001.html',
			condition: { // 返回结果.weatherinfo不为null
				value: '{$weather2.weatherinfo}',
				regular: 'is not null',
			},
		},*/
		baike: {
			url: 'http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?scope=103&format=json&appid=379020&bk_length=600',
			// get参数
			getData: {
				bk_key: '{$aip.city}', // api接口中返回的数据.city
			},
			// post参数
			postData: {},
			// 数据类型
			dataType: 'form',
			condition: {
				value: '{$baike.errno}',
				regular: 'is not null',
			},
		},
	}),
	success: function(data)	{
		console.debug(data);
	}
});

预定义验证规则

代码 含义
is null null === $value
is not null null !== $value
empty array 0 === count($value[0])
not empty array count($value[0]) > 0
true true === $value
false false === $value

除了预定义规则,你还可以编写正则来验证。如:\d+

dataType数据类型

名称 含义
form 表单参数格式(如:a=1&b=2),默认
json 转为json格式提交
The MIT License (MIT) Copyright (c) 2017 宇润 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

PHP开发的API接口代理,支持跨域接口代理和接口合并请求功能。 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/baiotngda/apiagent.git
git@gitee.com:baiotngda/apiagent.git
baiotngda
apiagent
ApiAgent
master

搜索帮助