PHPackages                             yurunsoft/api-agent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. yurunsoft/api-agent

ActiveProject[API Development](/categories/api)

yurunsoft/api-agent
===================

v1.0.1(8y ago)36866PHP

Since Jul 3Pushed 8y ago5 watchersCompare

[ Source](https://github.com/Yurunsoft/ApiAgent)[ Packagist](https://packagist.org/packages/yurunsoft/api-agent)[ RSS](/packages/yurunsoft-api-agent/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

ApiAgent
========

[](#apiagent)

简介
--

[](#简介)

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

[在线文档](http://doc.yurunsoft.com/ApiAgent "在线文档")
------------------------------------------------

[](#在线文档)

安装
--

[](#安装)

### 当作类库使用

[](#当作类库使用)

在您的composer.json中加入配置：

```
{
    "require": {
        "yurunsoft/api-agent": "1.0.*"
    }
}
```

### 作为项目运行

[](#作为项目运行)

切换到ApiAgent目录下，执行下列命令：

```
composer install

```

跨域接口代理
------

[](#跨域接口代理)

通过`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: {},
			// GET请求数据类型
			getDataType: 'form',
			// POST请求数据类型
			bodyDataType: 'form',
			// 自定义header，不定义则使用默认
			header: {
				'test': 'aaa',
			},
			// 验证返回结果是否正确，不正确会中断请求并返回
			condition: {
				value: '{$baike.errno}',
				regular: 'is not null',
			},
		},
	}),
	success: function(data)	{
		console.debug(data);
	}
});
```

### 接口合并请求返回结构

[](#接口合并请求返回结构)

```
{
	// 是否成功
    "success": true,
	// 错误信息
    "message": "",
	// 返回正文数据
    "data": {
        "test": ""
    },
	// 返回结果
    "result": {
		// 键名=>返回头数据
        "test": {
			// 状态码
            "status_code": 208,
			// 返回头
            "header": {
                "Server": "squid/3.5.20",
                "Date": "Mon, 09 Oct 2017 07:38:54 GMT",
                "Content-Type": "application/octet-stream",
                "Content-Length": "0",
                "Connection": "keep-alive"
            },
			// 请求耗时
            "time": 0.047
        }
    }
}
```

### 预定义验证规则

[](#预定义验证规则)

代码含义is nullnull === $valueis not nullnull !== $valueempty array0 === count($value\[0\])not empty arraycount($value\[0\]) &gt; 0truetrue === $valuefalsefalse === $value> 除了预定义规则，你还可以编写正则来验证。如：\\d+

### dataType数据类型

[](#datatype数据类型)

名称含义form表单参数格式(如：a=1&amp;b=2)，默认json转为json格式提交> 不传默认为form，其它名称不对传递来的参数做任何处理

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~33 days

Total

4

Last Release

3140d ago

Major Versions

v0.2 → v1.0.02017-10-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (46 commits)")

---

Tags

apicomposerphp

### Embed Badge

![Health badge](/badges/yurunsoft-api-agent/health.svg)

```
[![Health](https://phpackages.com/badges/yurunsoft-api-agent/health.svg)](https://phpackages.com/packages/yurunsoft-api-agent)
```

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23414.2M16](/packages/hubspot-api-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
