中石油简单接口

This commit is contained in:
2022-02-28 13:40:32 +08:00
parent f848c4fee5
commit 5dda512af6
5 changed files with 194 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Admin\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use XuanChen\Petro;
class PetroController
{
public function index(Request $request)
{
try {
// $res = Petro::Bill()->setParams([
// 'matchDate' => Carbon::now()->format('Ymd'),
// 'pageNo' => 1,
// 'dzmaxResult' => 1000,
// 'random' => Str::random(6),
// ])->start();
// dd($res);
// dd('作废');
// $res = Petro::Invalid()->setParams([
// 'cxcouponNo' => '61578832475977235',
// 'random' => Str::random(6),
// ])->start();
// dd($res);
// dd('查询');
$res = Petro::Detail()->setParams([
'couponNo' => '61578832475977235',
'random' => Str::random(6),
])->start();
//
dd($res);
// $grant = [
// 'requestCode' => 'Z591xRQ9fv1u',
// 'tradeId' => 111222,
// 'ticketSum' => 1,
// 'amount' => 10,
// 'random' => Str::random(6),
// ];
//
// $res = Petro::Grant()->setParams($grant)->start();
// dd($res);
} catch (\Exception $exception) {
dd('error'.$exception->getMessage());
}
}
}

View File

@@ -14,6 +14,7 @@ Route::group([
$router->get('test', 'TestController@index')->name('test.index');
$router->get('test/coupon', 'TestController@coupon');
$router->get('test/check_coupon_log', 'TestController@checkCouponLog');
$router->get('petro', 'PetroController@index');
$router->post('uploads/editor', 'UploadController@editor')->name('uploads.editor');

View File

@@ -0,0 +1,129 @@
<?php
namespace App\Api\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use XuanChen\Petro;
class PetroController extends Controller
{
public $log;
public function grant(Request $request)
{
try {
$inputdata = $request->all();
$res = $this->checkSign($request);
//获取解密后数据
$inputdata['jiemi'] = $res;
$this->log = $this->createLog($request->url(), 'POST', $inputdata, 'grant'); //添加日志
if (is_string($res)) {
return $this->error($res, $this->log);
}
$validator = \Validator::make($res, [
'activityId' => 'required',
'outletId' => 'required',
'mobile' => 'required',
], [
'activityId.required' => '缺少活动编码',
'outletId.required' => '缺少网点id',
'mobile.required' => '缺少手机号',
]);
if ($validator->fails()) {
return $this->error($validator->errors()->first(), $this->log);
}
$grant = [
'requestCode' => $res['activityId'],
'tradeId' => $res['tradeId'],
'ticketSum' => 1,
'amount' => $res['amount'],
'random' => Str::random(6),
];
$res = Petro::Grant()->setParams($grant)->start();
return $this->success($res, $this->log);
} catch (\Exception $exception) {
return $this->error($exception->getMessage(), $this->log);
}
}
public function query(Request $request)
{
try {
$inputdata = $request->all();
$res = $this->checkSign($request);
//获取解密后数据
$inputdata['jiemi'] = $res;
$this->log = $this->createLog($request->url(), 'POST', $inputdata, 'query'); //添加日志
if (is_string($res)) {
return $this->error($res, $this->log);
}
$validator = \Validator::make($res, [
'couponNo' => 'required',
], [
'couponNo.required' => '缺少券码',
]);
if ($validator->fails()) {
return $this->error($validator->errors()->first(), $this->log);
}
$res = Petro::Detail()->setParams([
'couponNo' => $res['couponNo'],
'random' => Str::random(6),
])->start();
return $this->success($res, $this->log);
} catch (\Exception $exception) {
return $this->error($exception->getMessage(), $this->log);
}
}
public function destroy(Request $request)
{
try {
$inputdata = $request->all();
$res = $this->checkSign($request);
//获取解密后数据
$inputdata['jiemi'] = $res;
$this->log = $this->createLog($request->url(), 'POST', $inputdata, 'query'); //添加日志
if (is_string($res)) {
return $this->error($res, $this->log);
}
$validator = \Validator::make($res, [
'couponNo' => 'required',
], [
'couponNo.required' => '缺少券码',
]);
if ($validator->fails()) {
return $this->error($validator->errors()->first(), $this->log);
}
$res = Petro::Invalid()->setParams([
'cxcouponNo' => $res['couponNo'],
'random' => Str::random(6),
])->start();
return $this->success($res, $this->log);
} catch (\Exception $exception) {
return $this->error($exception->getMessage(), $this->log);
}
}
}

View File

@@ -20,4 +20,8 @@ Route::group(['prefix' => 'V1'], function () {
Route::post('ticket/cancel', 'WoController@cancel'); //退业务
Route::post('ticket/query', 'WoController@query'); //退业务
//中石油
Route::post('petro/grant', 'PetroController@grant'); //发券
Route::post('petro/query', 'PetroController@query'); //查询
Route::post('petro/destroy', 'PetroController@destroy'); //作废
});

View File

@@ -17,7 +17,8 @@
"laravel/tinker": "^2.5",
"maatwebsite/excel": "^3.1",
"predis/predis": "^1.1",
"xuanchen/coupon": "^1.0",
"xuanchen/coupon": "^1.1",
"xuanchen/petro": "^0.0.1",
"xuanchen/unionpay": "^3.0.0"
},
"require-dev": {