z-perfe / common-service
There is no license information available for the latest version (1.1.3) of this package.
CommonService
1.1.3
2023-01-16 08:53 UTC
Requires
- php: >=7.4
- laravel/framework: ~5.6|~6.0|~7.0|~8.0|~9.0
README
安装
适用于 laravel PHP 7.4+
composer require z-perfe/common-service
发布配置文件
php artisan vendor:publish --tag=common_service
config/common_service.php文件中,配置APP_ID等参数
短信服务
use Zperfe\Common\Service\Sms;
$sms = new Sms();
// 发送短信
$sms->send(string $action, string $mobile, array $params = []);
// 获得可用的动作列表
$sms->getAction();
$sms->send 参数说明
支付服务
use Zperfe\Common\Service\OrderPay;
$pay = new OrderPay();
// 订单支付
$pay->pay(int|string $channel_id, string $app_trade_no, string $description, int $amount_total, array $params = [], string $amount_currency = 'THB', array $attach = []);
// 获得可用的支付渠道
$pay->getChannels();
$pay->pay 参数说明
成功的响应
{
"status": 1,
"message": "SUCCESS",
"data": []
}
失败的响应
{
"status": 400,
"message": "错误的params, 缺乏必须的键:code",
"code": "BadRequest"
}
支付结果下发通知
{
"result_code": "SUCCESS",
"ordersn": "",
"app_trade_no": "",
"notify_type": "PAY",
"amount_total": '',
"timestamp": '',
"sign": ""
}
支付结果下发通知的参数说明
支付通知的校验方法
use Zperfe\Common\Service\OrderPay;
$input = $request->all();
$pay = new OrderPay();
// 校验签名
if ($pay->verifySign($input)) {
// 签名通过
if ($input['timestamp'] - time() > 60 * 60 * 24) {
// 可以对下发的时间戳进行判断...
}
}
文件服务
文件会重新命名
use Zperfe\Common\Service\UploadFile;
$upload = new UploadFile();
$file = $request->file('file');
$response = $upload->putFile($file, $path='');
$upload->putFile 参数说明
成功的响应
{
"status": 1,
"message": "SUCCESS",
"data": {
"file": "20230116154453_41591.jpg",
"full_file": "https://img1.ortmg.com/20230116154453_41591.jpg"
}
}