支付猫个人支付官方 PHP SDK.
- PHP >= 7.0
- Composer
$ composer require cmzz/paycats-php-sdk -vvv
<?php
use Paycats\Sdk\Paycats;
use Paycats\Sdk\Requests\NativePayRequest;
$config = [
'mch_id' => 'you app id',
'key' => 'your api key'
];
$paycats = new Paycats($config);
$data = [
'mch_id' => '162934501',
'total_fee' => 1,
'out_trade_no' => 'test-order-18481',
'sign' => '',
'body' => '',
];
$request = new NativePayRequest($data);
try {
$result = $paycats->exec($request);
} catch (\Paycats\Sdk\Exceptions\Exception $exception) {
// 异常
echo $exception->getMessage();
}
if ($result['return_code'] === 0) {
// 已经验证签名
// 请求成功,业务逻辑
// your code
}
<?php
use Paycats\Sdk\Paycats;
use Paycats\Sdk\NotifyType;
$config = [
'mch_id' => 'you app id',
'key' => 'your api key'
];
$paycats = new Paycats($config);
$response = $paycats->serve(function ($notifyData) {
switch ($notifyData['notify_type']) {
case NotifyType::ORDER_SUCCEEDED:
// 订单支付成功通知
break;
case NotifyType::REFUND_SUCCEEDED:
// 订单退款成功
break;
}
// 处理成功返回 true, 失败返回 false
return true;
});
// 在 laravel 中,直接 return $response;
return $response->send();
MIT