完善文档

This commit is contained in:
yansongda 2017-08-22 16:18:55 +08:00
parent dec1bc5e24
commit 375c521e63

105
README.md
View File

@ -114,9 +114,16 @@ composer require yansongda/pay
### 0、一个完整的例子:
```php
use Yansongda\Pay\Pay;
<?php
$config = [
namespace App\Http\Controllers;
use Yansongda\Pay\Pay;
use Illuminate\Http\Request;
class PayController extends Controller
{
protected $config = [
'alipay' => [
'app_id' => '2016082000295641',
'notify_url' => 'http://yansongda.cn/alipay_notify.php',
@ -124,16 +131,98 @@ $config = [
'ali_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWJKrQ6SWvS6niI+4vEVZiYfjkCfLQfoFI2nCp9ZLDS42QtiL4Ccyx8scgc3nhVwmVRte8f57TFvGhvJD0upT4O5O/lRxmTjechXAorirVdAODpOu0mFfQV9y/T9o9hHnU+VmO5spoVb3umqpq6D/Pt8p25Yk852/w01VTIczrXC4QlrbOEe3sr1E9auoC7rgYjjCO6lZUIDjX/oBmNXZxhRDrYx4Yf5X7y8FRBFvygIE2FgxV4Yw+SL3QAa2m5MLcbusJpxOml9YVQfP8iSurx41PvvXUMo49JG3BDVernaCYXQCoUJv9fJwbnfZd7J5YByC+5KM4sblJTq7bXZWQIDAQAB',
'private_key' => 'MIIEpAIBAAKCAQEAs6+F2leOgOrvj9jTeDhb5q46GewOjqLBlGSs/bVL4Z3fMr3p+Q1Tux/6uogeVi/eHd84xvQdfpZ87A1SfoWnEGH5z15yorccxSOwWUI+q8gz51IWqjgZxhWKe31BxNZ+prnQpyeMBtE25fXp5nQZ/pftgePyUUvUZRcAUisswntobDQKbwx28VCXw5XB2A+lvYEvxmMv/QexYjwKK4M54j435TuC3UctZbnuynSPpOmCu45ZhEYXd4YMsGMdZE5/077ZU1aU7wx/gk07PiHImEOCDkzqsFo0Buc/knGcdOiUDvm2hn2y1XvwjyFOThsqCsQYi4JmwZdRa8kvOf57nwIDAQABAoIBAQCw5QCqln4VTrTvcW+msB1ReX57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slzNa1bK+klGgJNYDbQqohKNn1HeFX3mYNfCUpuSnD2Yag53Dd/1DLO+NxzwvTu4D6DCUnMMMBVaF42ig31Bs0jI3JQZVqeeFzSET8fkoFopJf3G6UXlrIEAQ==',
],
];
];
$config_biz = [
'out_trade_no' => '1',
public function index()
{
$config_biz = [
'out_trade_no' => time(),
'total_amount' => '1',
'subject' => 'test subject',
];
];
$pay = new Pay($this->config);
return $pay->driver('alipay')->gateway()->pay($config_biz);
}
public function return(Request $request)
{
$pay = new Pay($this->config);
return $pay->driver('alipay')->gateway()->verify($request->all());
}
public function notify(Request $request)
{
$pay = new Pay($this->config);
if ($pay->driver('alipay')->gateway()->verify($request->all())) {
file_put_contents(storage_path('notify.txt'), "收到来自支付宝的异步通知\r\n", FILE_APPEND);
file_put_contents(storage_path('notify.txt'), '订单号:' . $request->out_trade_no . "\r\n", FILE_APPEND);
file_put_contents(storage_path('notify.txt'), '订单金额:' . $request->total_amount . "\r\n\r\n", FILE_APPEND);
} else {
file_put_contents(storage_path('notify.txt'), "收到异步通知\r\n", FILE_APPEND);
}
echo "success";
}
}
```
```php
<?php
namespace App\Http\Controllers;
use Yansongda\Pay\Pay;
use Illuminate\Http\Request;
class PayController extends Controller
{
protected $config = [
'wechat' => [
'app_id' => 'wxb3f6d068e382c63d',
'mch_id' => '1457768302',
'notify_url' => 'http://yansongda.cn/wechat_notify.php',
'key' => 'mF2suE9sU6Mk1C7GXnT5H12315645645',
'cert_client' => './apiclient_cert.pem',
'cert_key' => './apiclient_key.pem',
],
];
public function index()
{
$config_biz = [
'out_trade_no' => 'e2',
'total_fee' => '0.01',
'body' => 'test body',
'spbill_create_ip' => '14.213.156.207',
'openid' => 'onkVf1FjWS5SBIihS-123456_abc',
];
$pay = new Pay($this->config);
return $pay->driver('wechat')->gateway('mp')->pay($config_biz);
}
public function notify(Request $request)
{
$pay = new Pay($this->config);
$verify = $p->driver('wechat')->gateway('mp')->verify($request->getContent());
if ($verify) {
file_put_contents('notify.txt', "收到来自微信的异步通知\r\n", FILE_APPEND);
file_put_contents('notify.txt', '订单号:' . $verify['out_trade_no'] . "\r\n", FILE_APPEND);
file_put_contents('notify.txt', '订单金额:' . $verify['total_fee'] . "\r\n\r\n", FILE_APPEND);
} else {
file_put_contents(storage_path('notify.txt'), "收到异步通知\r\n", FILE_APPEND);
}
echo "success";
}
}
$pay = new Pay($config);
return $pay->driver('alipay')->gateway('web')->pay($config_biz);
```
### 1、准备配置参数