# PHP SDK

### 获取SDK

GitHub下载：<https://github.com/Asiabill/asiabill_php_sdk>

Composer安装：composer require asiabill/asiabill\_php\_sdk

### 要求

### 要求

PHP 5.6 或更高版本

### PHP依赖

PHP SDK 需要以下扩展才能正常工作：

* [curl](https://www.php.net/manual/en/book.curl.php)
* [json](https://www.php.net/manual/en/book.json.php)
* [openssl](https://www.php.net/manual/en/book.openssl.php)

### 使用PHP SDK

1、 加载AsiabillIntegration.php文件（如果使用Composer安装，跳过此步骤）

```php
include_once "/classes/AsiabillIntegration.php";
```

2、初始化对象

```php
use \Asiabill\Classes\AsiabillIntegration;
$model = 'test'; // test or live
$asiabill = new AsiabillIntegration($model,$gateway_no,$sign_key);
```

3、开启日志，可以通过$dir设置目录，如果不开启则跳过这一步

```php
$asiabill->startLogger($bool，$dir);
```

4、发起请求

```php
$asiabill->request($type,$data) or $asiabill->payment()->request($type,$data);
$asiabill->openapi()->request($type,$data);
```

### 参数说明

**type**：请求类型：字符串

**data**：请求参数：包含path，body，query三个部分

### payment类型

<table><thead><tr><th>类型</th><th width="315.3333333333333">说明</th></tr></thead><tbody><tr><td>customers</td><td>操作客户（包含创建、修改、删除） <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/customer">查看</a></td></tr><tr><td>sessionToken</td><td>生成sessionToken <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/sessiontoken">查看</a></td></tr><tr><td>paymentMethods</td><td>创建支付方式 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/payment-methods">查看</a></td></tr><tr><td>paymentMethods_list</td><td>根据客户获取所有支付方式 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/payment-methods">查看</a></td></tr><tr><td>paymentMethods_update</td><td>更新paymentMethod信息 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/payment-methods">查看</a></td></tr><tr><td>paymentMethods_query</td><td>获取支付方式 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/payment-methods">查看</a></td></tr><tr><td>paymentMethods_detach</td><td>解绑支付方式 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/payment-methods">查看</a></td></tr><tr><td>paymentMethods_attach</td><td>客户附加支付方式 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/payment-methods">查看</a></td></tr><tr><td>confirmCharge</td><td>确认扣款 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/confirm-charge">查看</a></td></tr><tr><td>checkoutPayment</td><td>获取支付页面地址 <a href="https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi/checkout-payment">查看</a></td></tr></tbody></table>

### openApi类型

| 类型            | 说明                                                                                                                        |
| ------------- | ------------------------------------------------------------------------------------------------------------------------- |
| Authorize     | 预授权 [查看](https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/shou-quan-jiao-yi-wan-cheng-che-xiao/authorization) |
| chargebacks   | 拒付查询 [查看](https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/ju-fu)                                             |
| refund        | 退款申请 [查看](https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/tui-kuan)                                          |
| refund\_query | 退款查询 [查看](https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/tui-kuan)                                          |
| logistics     | 上传物流信息 [查看](https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/wu-liu)                                          |
| transactions  | 交易流水列表 [查看](https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi-cha-xun)                                 |
| orderInfo     | 交易详情 [查看](https://app.gitbook.com/s/Mb9UzyxGUyxHylm4UJSJ/api-reference/jiao-yi-cha-xun)                                   |

### 添加自定义类型

**$request\_type** 请求类型，自定义字符，与request第一个参数一致，已经存在的类型不能添加\
\&#xNAN;**$request\_path** 接口路径，参考asiabill接口文档

```php
$asiabill->addRequest($request_type,$request_path);
$asiabill->request($request_type,$data) or $asiabill->openapi()->request($request_type,$data)
```
