Skip to content

Commit

Permalink
新增沙箱配置
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 committed Oct 12, 2016
1 parent 1e798f5 commit ac3282e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
11 changes: 8 additions & 3 deletions README.md
@@ -1,11 +1,15 @@
# 阿里大于(鱼) - v2.0

![build=passing](https://img.shields.io/badge/build-passing-brightgreen.svg?maxAge=2592000) [![composer](https://img.shields.io/badge/composer-flc/alidayu-yellowgreen.svg?maxAge=2592000)](https://packagist.org/packages/flc/alidayu) [![tag=v2.0.2](https://img.shields.io/badge/tag-v2.0.2-yellow.svg?maxAge=2592000)](https://github.com/flc1125/alidayu/archive/v2.0.2.zip) ![php>=5.4](https://img.shields.io/badge/php->%3D5.4-orange.svg?maxAge=2592000) [![license=MIT](https://img.shields.io/badge/license-MIT-blue.svg?maxAge=2592000)](https://github.com/flc1125/alidayu/blob/master/LICENSE)

之前的旧版本(`v1.0`)开源出去后,使用者较多;但兼容各大框架较差;为此发布`v2.0`;该版本全新架构,适用任意框架!
![build=passing](https://img.shields.io/badge/build-passing-brightgreen.svg?maxAge=2592000) [![composer](https://img.shields.io/badge/composer-flc/alidayu-yellowgreen.svg?maxAge=2592000)](https://packagist.org/packages/flc/alidayu) [![tag=v2.0.3](https://img.shields.io/badge/tag-v2.0.2-yellow.svg?maxAge=2592000)](https://github.com/flc1125/alidayu/archive/v2.0.2.zip) ![php>=5.4](https://img.shields.io/badge/php->%3D5.4-orange.svg?maxAge=2592000) [![license=MIT](https://img.shields.io/badge/license-MIT-blue.svg?maxAge=2592000)](https://github.com/flc1125/alidayu/blob/master/LICENSE)

> `v2.0`不支持从`v1.0`直接升级,请抛弃`v1.0`
## 更新

##### v2.0.3 (2016-10-12)

- 新增沙箱配置

## 功能

- `通过` [短信发送](docs/alibaba_aliqin_fc_sms_num_send.md)
Expand Down Expand Up @@ -44,6 +48,7 @@ use Flc\Alidayu\Requests\AlibabaAliqinFcSmsNumSend;
$config = [
'app_key' => '*****',
'app_secret' => '************',
// 'sandbox' => true, // 是否为沙箱环境,默认false
];

$client = new Client(new App($config));
Expand Down
20 changes: 20 additions & 0 deletions src/Alidayu/App.php
Expand Up @@ -21,6 +21,12 @@ class App
*/
public $app_secret;

/**
* 是否沙箱地址
* @var boolean
*/
public $sandbox = false;

/**
* 初始化
* @param array $config 阿里大于配置
Expand All @@ -32,6 +38,9 @@ public function __construct($config = [])

if (array_key_exists('app_secret', $config))
$this->app_secret = $config['app_secret'];

if (array_key_exists('sandbox', $config))
$this->sandbox = $config['sandbox'];
}

/**
Expand All @@ -55,4 +64,15 @@ public function setAppSecret($value)

return $this;
}

/**
* 设置是否为沙箱环境
* @param boolean $value [description]
*/
public function setSandBox($value = false)
{
$this->sandbox = $value;

return $this;
}
}
11 changes: 10 additions & 1 deletion src/Alidayu/Client.php
Expand Up @@ -18,6 +18,12 @@ class Client
*/
protected $api_uri = 'http://gw.api.taobao.com/router/rest';

/**
* 沙箱请求地址
* @var string
*/
protected $api_sandbox_uri = 'http://gw.api.tbsandbox.com/router/rest';

/**
* 应用
* @var \Flc\Alidayu\App
Expand Down Expand Up @@ -73,7 +79,10 @@ public function execute(IRequest $request)
$params['sign'] = $this->generateSign($params);

// 请求数据
$resp = $this->curl($this->api_uri, $params);
$resp = $this->curl(
$this->app->sandbox ? $this->api_sandbox_uri : $this->api_uri,
$params
);

// 解析返回
return $this->parseRep($resp);
Expand Down
23 changes: 12 additions & 11 deletions tests/index.php
Expand Up @@ -17,18 +17,19 @@
$config = [
'app_key' => '*****',
'app_secret' => '************',
'sandbox' => true, // 是否为沙箱环境,默认false
];

$client = new Client(new App($config));

// 短信发送 passed
// $req = new AlibabaAliqinFcSmsNumSend;
// $req->setRecNum('13312341234')
// ->setSmsParam([
// 'number' => rand(100000, 999999)
// ])
// ->setSmsFreeSignName('叶子坑')
// ->setSmsTemplateCode('SMS_15105357');
$req = new AlibabaAliqinFcSmsNumSend;
$req->setRecNum('13312311231')
->setSmsParam([
'number' => rand(100000, 999999)
])
->setSmsFreeSignName('叶子坑')
->setSmsTemplateCode('SMS_15105357');

// 文本转语音通知 passed
// $req = new AlibabaAliqinFcTtsNumSinglecall;
Expand Down Expand Up @@ -76,10 +77,10 @@
// $req->setOutId('111111');

// 流量直充分省接口 ---
$req = new AlibabaAliqinFcFlowChargeProvince;
$req->setPhoneNum('13312311231')
->setGrade('50')
->setOutRechargeId('111111');
// $req = new AlibabaAliqinFcFlowChargeProvince;
// $req->setPhoneNum('13312311231')
// ->setGrade('50')
// ->setOutRechargeId('111111');

print_r($req->getParams());

Expand Down

0 comments on commit ac3282e

Please sign in to comment.