阶段更新
This commit is contained in:
@@ -69,20 +69,20 @@ class LogController extends AdminController
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('code', '卡券编号');
|
||||
$grid->column('type', '分类')
|
||||
->using(ActivityCouponLog::TYPES)
|
||||
->label([
|
||||
1 => 'default',
|
||||
2 => 'warning',
|
||||
3 => 'info',
|
||||
]);
|
||||
->using(ActivityCouponLog::TYPES)
|
||||
->label([
|
||||
1 => 'default',
|
||||
2 => 'warning',
|
||||
3 => 'info',
|
||||
]);
|
||||
|
||||
$grid->column('status', '状态')
|
||||
->using(ActivityCouponLog::STATUS)
|
||||
->label([
|
||||
1 => 'default',
|
||||
2 => 'warning',
|
||||
3 => 'info',
|
||||
]);
|
||||
->using(ActivityCouponLog::STATUS)
|
||||
->label([
|
||||
1 => 'default',
|
||||
2 => 'warning',
|
||||
3 => 'info',
|
||||
]);
|
||||
|
||||
$grid->column('remark', '处理结果');
|
||||
|
||||
|
||||
56
app/Api/Controllers/UnionPayController.php
Normal file
56
app/Api/Controllers/UnionPayController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use XuanChen\UnionPay\UnionPay;
|
||||
|
||||
class UnionPayController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$str = 'msg_type=00&msg_txn_code=002100&msg_crrltn_id=12345678901234567890123456789000&msg_flg=0&msg_sender=01&msg_time=20130318162412&msg_sys_sn=12345678900987654321&msg_ver=0.1&mchnt_no=8981231234567890&term_no=12345678&shop_no=086123456123456789&req_serial_no=12345678900987654321&orig_req_serial_no=12345678900987654321&enc_card_no=123123123123123123123sdfadqerqr&acq_term_sn=123456&refer_no=123456789012&sett_date=20130318&txn_date=20130318&txn_time=162850&orig_amt=10000&discount_amt=2000&pay_amt=8000&pay_mode=1';
|
||||
parse_str($str, $arr_str);
|
||||
|
||||
$action = new UnionPay($arr_str);
|
||||
$sign = $action->getSign();
|
||||
$action->sign = $sign;
|
||||
$res = $action->checkSign(true);
|
||||
dump($sign);
|
||||
dump($res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 银联接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/28 16:31
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function query(Request $request)
|
||||
{
|
||||
$inputs = $request->all();
|
||||
|
||||
if (!isset($inputs['msg_txn_code'])) {
|
||||
|
||||
}
|
||||
|
||||
$validator = \Validator::make($inputs, [
|
||||
'activityId' => 'required',
|
||||
'outletId' => 'required',
|
||||
'mobile' => 'required',
|
||||
], [
|
||||
'activityId.required' => '缺少活动编码',
|
||||
'outletId.required' => '缺少网点id',
|
||||
'mobile.required' => '缺少手机号',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace App\Api\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use XuanChen\Coupon\UnionPay;
|
||||
use XuanChen\Coupon\Coupon;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
@@ -63,7 +63,7 @@ class UserController extends Controller
|
||||
return $this->error($validator->errors()->first(), $log);
|
||||
}
|
||||
|
||||
$res = UnionPay::Grant($res['activityId'], $res['outletId'], $res['mobile']);
|
||||
$res = Coupon::Grant($res['activityId'], $res['outletId'], $res['mobile']);
|
||||
|
||||
if (is_string($res)) {
|
||||
return $this->error($res, $log);
|
||||
@@ -106,7 +106,7 @@ class UserController extends Controller
|
||||
$redemptionCode = $res['redemptionCode'];
|
||||
$outletId = $res['outletId'];
|
||||
|
||||
$res = UnionPay::Query($redemptionCode, $outletId);
|
||||
$res = Coupon::Query($redemptionCode, $outletId);
|
||||
|
||||
if (is_string($res)) {
|
||||
return $this->error($res, $log);
|
||||
@@ -141,7 +141,7 @@ class UserController extends Controller
|
||||
|
||||
$redemptionCode = $res['redemptionCode'];
|
||||
$outletId = $res['outletId'];
|
||||
$res = UnionPay::Destroy($redemptionCode, $outletId);
|
||||
$res = Coupon::Destroy($redemptionCode, $outletId);
|
||||
|
||||
if ($res !== true) {
|
||||
return $this->error($res, $log);
|
||||
@@ -188,7 +188,7 @@ class UserController extends Controller
|
||||
$redemptionCode = trim($redemptionCode);
|
||||
$outletId = trim($outletId);
|
||||
|
||||
$coupon = UnionPay::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid);
|
||||
$coupon = Coupon::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid);
|
||||
if (is_string($coupon)) {
|
||||
return $this->error($coupon, $log);
|
||||
}
|
||||
|
||||
@@ -18,4 +18,9 @@ Route::group(['prefix' => 'V1'], function () {
|
||||
Route::post('ticket/cancel', 'WoController@cancel'); //退业务
|
||||
Route::post('ticket/query', 'WoController@query'); //退业务
|
||||
|
||||
//银联相关
|
||||
Route::post('unionpay/index', 'UnionPayController@index');
|
||||
Route::post('unionpay/query', 'UnionPayController@query');
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -1,251 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Api\Controllers\ApiResponse;
|
||||
use SelfCoupon;
|
||||
use App\Models\User;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use XuanChen\Coupon\UnionPay;
|
||||
|
||||
// use Wo;
|
||||
|
||||
class TestController
|
||||
{
|
||||
|
||||
use ApiResponse;
|
||||
|
||||
public $baseUrl = 'http://pa.ysd-bs.com/api/V1/';
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
// $user_id = $request->user_id;
|
||||
// $data = $request->data;
|
||||
// $this->user = User::find(3);
|
||||
//
|
||||
// $data = '5VehIrHTZsS1BY8V5VcKlhTN9hbutq4j+HIT2zRCbSqgPWvClQSxYSP7mn7PmHuiYQpj55NRC6w4397FfdVTq23wd4BOQ964giie/JForTjt0l7UaY23XzKnNjDSKiGqr7DAbd8P3SzJ75ZjKaqUu7UWu3PVylAeesGRbZgpQEF/XKwOW4XMaJGV2tIsowILZCtF+moqHg7yA6hI4vT7iYU3rTq9vk7kpcnfArLKPQ5dxH9FFIegdr7E1S8NVwpTZrxeQEmjDUsGrBcWe/Q9dRWXSlKF1Hdz2qCUCK94fu3gqvEVSYRllTCa5mwQhlYJLs2UTmWMSism7nsivySseSl1/JOvNH0lyvWaV1XDUMKG8oTC+kOPQKxFA3qp2xO9ohRhN0dkpML4JVgkMF1r6rv+rThYQuOL/rnsuY5Jdh4QdPWCItQ05lqI46s2yPyKROrLx7jQ3/+BOyEmP+Cj5W8/trEAVS1HczMj4Jnl3vrcY879ubokUcEatalAuKGM0uLNAqQF5XfHzgXam4coEMek8MjdbxW+Z9+eZFQp/P1ts7yN5qzpac6Y8CrqSMFJZf1vwowp+1peiEC5tCsXlHCsDLPS8Uh1LNnC3sag0XZu7jX5uVR9nxR2c/ibBJOAHcUO+NcjmzoN+dQOeBkb/aWj9B+9mW5RUQmfUk6O+Vwkb5ruZZbXsoJJULj4tHJv87+mVo30e0mBbaPD47+fTp1+qSJtLOOlLO2nEj1NNDBSBGLM4RxTDQ4ju2r6HY9YyMXsbNC2YB8zrXrDsUoB1WSuu5XcaWx8rzA0NpckzNbEIuv0+6fA69gXOhC9xcGGPyEBbko73XHr7W8MIDtWhGOG8kHf1cAMdjwVGS2OUJ6XKZnBMwIzY8cJn4Fi+jXRMFnt+7BxWLToNQsyOoHbYWypeM8FrAb4VQeaxGhBQUXUmHhmAp00jcGEe/ngxn1oVjq6G+pEq8CxBntvQ+GZ975sPaCqkYOjbuHa9Myd2tT6GWbczL/YcR4RRV96ByYYCEOBy01LsBNeo6SSpWYcK4eoLhc70v8s';
|
||||
// $iv = substr($this->user->des3key, 0, 8);
|
||||
// $ret = openssl_decrypt($data, 'DES-EDE3-CBC', $this->user->des3key, 0, $iv);
|
||||
// if (false === $ret) {
|
||||
// return openssl_error_string();
|
||||
// }
|
||||
// dd($ret);
|
||||
// dd();
|
||||
$this->user = User::find(4);
|
||||
$ret = [
|
||||
'variable' => 100,
|
||||
'mobile' => 15663876870,
|
||||
'type' => 'silver',
|
||||
'remark' => '测试',
|
||||
];
|
||||
$res['server_id'] = $this->user->server_id;
|
||||
$res['des'] = $this->user->des3key;
|
||||
$res['key'] = $this->user->server_key;
|
||||
|
||||
return $this->success($ret);
|
||||
dd();
|
||||
$this->user = User::find(4);
|
||||
$ret = [
|
||||
'redemptionCode' => '951951858070',
|
||||
'total' => 5,
|
||||
'outletId' => '2008241014458',
|
||||
];
|
||||
|
||||
return $this->success($ret);
|
||||
dd(phpinfo());
|
||||
dd();
|
||||
$num = 100;
|
||||
|
||||
for ($i = 1; $i <= $num; $i++) {
|
||||
$data = [
|
||||
'outletId' => '2004020935777',
|
||||
'activityId' => 'ysd20200740',
|
||||
'mobile' => '15663876870',
|
||||
];
|
||||
|
||||
$this->user = User::find(3);
|
||||
|
||||
$data = $this->jiami($data);
|
||||
|
||||
$url = $this->baseUrl . 'user/grant';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
// if (isset($res['data'])) {
|
||||
// $jiemi = $this->jiemi($res['data']);
|
||||
// dump($jiemi);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
dump($this->getElapsedTime());
|
||||
dump($this->getMemoryUsage());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 发券
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/29 13:57
|
||||
*/
|
||||
public function grant(Request $request)
|
||||
{
|
||||
$this->user = User::find(3);
|
||||
|
||||
$data = $this->jiami($request->all());
|
||||
|
||||
$url = $this->baseUrl . 'user/grant';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
return $res;
|
||||
|
||||
// dump($this->getElapsedTime());
|
||||
// dump($this->getMemoryUsage());
|
||||
//
|
||||
// dd($res);
|
||||
}
|
||||
|
||||
//查询
|
||||
public function query(Request $request)
|
||||
{
|
||||
$this->user = User::find(3);
|
||||
|
||||
$redemptionCode = $request->redemptionCode;
|
||||
$outletId = $request->outletId;
|
||||
|
||||
$data = $this->jiami($request->all());
|
||||
|
||||
$url = $this->baseUrl . 'user/query';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
return $res;
|
||||
if (isset($res['data'])) {
|
||||
$jiemi = $this->jiemi($res['data']);
|
||||
dump($jiemi);
|
||||
}
|
||||
|
||||
dump($this->getElapsedTime());
|
||||
dump($this->getMemoryUsage());
|
||||
|
||||
dump($res);
|
||||
|
||||
}
|
||||
|
||||
//卡券作废
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
$this->user = User::find(3);
|
||||
|
||||
$redemptionCode = $request->redemptionCode;
|
||||
$data = $this->jiami($request->all());
|
||||
|
||||
$url = $this->baseUrl . 'user/destroy';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
dump($this->getElapsedTime());
|
||||
dump($this->getMemoryUsage());
|
||||
if (isset($res['data'])) {
|
||||
$jiemi = $this->jiemi($res['data']);
|
||||
dump($jiemi);
|
||||
}
|
||||
dump($res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 核销
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/29 14:01
|
||||
*/
|
||||
public function checkcoupon(Request $request)
|
||||
{
|
||||
$user_id = $request->user_id;
|
||||
|
||||
$this->user = User::find($user_id);
|
||||
|
||||
$data = $this->jiami([
|
||||
'redemptionCode' => $request->redemptionCode,
|
||||
'total' => $request->total,
|
||||
'outletId' => $request->outletId,
|
||||
'orderid' => $request->orderid,
|
||||
]);
|
||||
|
||||
$url = $this->baseUrl . 'user/freezecoupon';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
return $res;
|
||||
|
||||
$redemptionCode = $request->redemptionCode;
|
||||
$total = $request->total;
|
||||
$outletId = $request->outletId;
|
||||
$orderid = $request->orderid ?? '';
|
||||
$res = UnionPay::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid);
|
||||
|
||||
if (is_string($res)) {
|
||||
return $this->error($res);
|
||||
}
|
||||
|
||||
return $this->success('核销成功');
|
||||
}
|
||||
|
||||
public function http($data, $url)
|
||||
{
|
||||
$client = new Client();
|
||||
$response = $client->request('POST', $url, ['form_params' => $data, 'http_errors' => false]);
|
||||
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function jiami($ret)
|
||||
{
|
||||
$jsonData = json_encode($ret); //数据JSON化
|
||||
$ascdata = $this->keyasc($jsonData); //加密
|
||||
$addcode = sprintf("%08d", mt_rand(0, 99999999)); //随机code 验证签名用
|
||||
$sign = $this->keysign($ascdata, $addcode);
|
||||
|
||||
$data = [
|
||||
'server_id' => $this->user->server_id,
|
||||
'key' => $this->user->server_key,
|
||||
'addcode' => $addcode,
|
||||
'sign' => $sign,
|
||||
'data' => $ascdata,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param <type> $value
|
||||
* @return <type>
|
||||
*/
|
||||
public function jiemi($value)
|
||||
{
|
||||
$iv = substr($this->user->des3key, 0, 8);
|
||||
$ret = openssl_decrypt($value, 'DES - EDE3 - CBC', $this->user->des3key, 0, $iv);
|
||||
if (false === $ret) {
|
||||
return openssl_error_string();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getMemoryUsage($precision = 2)
|
||||
{
|
||||
$size = memory_get_usage(true);
|
||||
|
||||
$unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
|
||||
|
||||
return round($size / pow(1024, ($i = floor(log($size, 1024)))), $precision) . ' ' . $unit[$i];
|
||||
}
|
||||
|
||||
function getElapsedTime(int $decimals = 2)
|
||||
{
|
||||
return number_format(microtime(true) - request()->server('REQUEST_TIME_FLOAT'), $decimals) . ' s';
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Api\Controllers\ApiResponse;
|
||||
use App\Models\User;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use XuanChen\Coupon\Coupon;
|
||||
|
||||
class TestController
|
||||
{
|
||||
|
||||
use ApiResponse;
|
||||
|
||||
public $baseUrl = 'http://pac.ysd-bs.com/api/V1/';
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user_id = $request->user_id;
|
||||
$data = $request->data;
|
||||
$this->user = User::find(3);
|
||||
|
||||
$data = '5VehIrHTZsS1BY8V5VcKlhTN9hbutq4j+HIT2zRCbSqgPWvClQSxYSP7mn7PmHuiYQpj55NRC6w4397FfdVTq23wd4BOQ964giie/JForTjt0l7UaY23XzKnNjDSKiGqr7DAbd8P3SzJ75ZjKaqUu7UWu3PVylAeesGRbZgpQEF/XKwOW4XMaJGV2tIsowILZCtF+moqHg7yA6hI4vT7iYU3rTq9vk7kpcnfArLKPQ5dxH9FFIegdr7E1S8NVwpTZrxeQEmjDUsGrBcWe/Q9dRWXSlKF1Hdz2qCUCK94fu3gqvEVSYRllTCa5mwQhlYJLs2UTmWMSism7nsivySseSl1/JOvNH0lyvWaV1XDUMKG8oTC+kOPQKxFA3qp2xO9ohRhN0dkpML4JVgkMF1r6rv+rThYQuOL/rnsuY5Jdh4QdPWCItQ05lqI46s2yPyKROrLx7jQ3/+BOyEmP+Cj5W8/trEAVS1HczMj4Jnl3vrcY879ubokUcEatalAuKGM0uLNAqQF5XfHzgXam4coEMek8MjdbxW+Z9+eZFQp/P1ts7yN5qzpac6Y8CrqSMFJZf1vwowp+1peiEC5tCsXlHCsDLPS8Uh1LNnC3sag0XZu7jX5uVR9nxR2c/ibBJOAHcUO+NcjmzoN+dQOeBkb/aWj9B+9mW5RUQmfUk6O+Vwkb5ruZZbXsoJJULj4tHJv87+mVo30e0mBbaPD47+fTp1+qSJtLOOlLO2nEj1NNDBSBGLM4RxTDQ4ju2r6HY9YyMXsbNC2YB8zrXrDsUoB1WSuu5XcaWx8rzA0NpckzNbEIuv0+6fA69gXOhC9xcGGPyEBbko73XHr7W8MIDtWhGOG8kHf1cAMdjwVGS2OUJ6XKZnBMwIzY8cJn4Fi+jXRMFnt+7BxWLToNQsyOoHbYWypeM8FrAb4VQeaxGhBQUXUmHhmAp00jcGEe/ngxn1oVjq6G+pEq8CxBntvQ+GZ975sPaCqkYOjbuHa9Myd2tT6GWbczL/YcR4RRV96ByYYCEOBy01LsBNeo6SSpWYcK4eoLhc70v8s';
|
||||
$iv = substr($this->user->des3key, 0, 8);
|
||||
$ret = openssl_decrypt($data, 'DES-EDE3-CBC', $this->user->des3key, 0, $iv);
|
||||
if (false === $ret) {
|
||||
return openssl_error_string();
|
||||
}
|
||||
dd($ret);
|
||||
dd();
|
||||
$this->user = User::find(215);
|
||||
$ret = [
|
||||
'redemptionCode' => '951951858070',
|
||||
'total' => 5,
|
||||
'outletId' => '2006151433887',
|
||||
];
|
||||
|
||||
return $this->success($ret);
|
||||
dd(phpinfo());
|
||||
dd();
|
||||
$num = 100;
|
||||
|
||||
for ($i = 1; $i <= $num; $i++) {
|
||||
$data = [
|
||||
'outletId' => '2004020935777',
|
||||
'activityId' => 'ysd20200740',
|
||||
'mobile' => '15663876870',
|
||||
];
|
||||
|
||||
$this->user = User::find(3);
|
||||
|
||||
$data = $this->jiami($data);
|
||||
|
||||
$url = $this->baseUrl . 'user/grant';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
// if (isset($res['data'])) {
|
||||
// $jiemi = $this->jiemi($res['data']);
|
||||
// dump($jiemi);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
dump($this->getElapsedTime());
|
||||
dump($this->getMemoryUsage());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 发券
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/29 13:57
|
||||
*/
|
||||
public function grant(Request $request)
|
||||
{
|
||||
$this->user = User::find(3);
|
||||
|
||||
$data = $this->jiami($request->all());
|
||||
|
||||
$url = $this->baseUrl . 'user/grant';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
return $res;
|
||||
|
||||
// dump($this->getElapsedTime());
|
||||
// dump($this->getMemoryUsage());
|
||||
//
|
||||
// dd($res);
|
||||
}
|
||||
|
||||
//查询
|
||||
public function query(Request $request)
|
||||
{
|
||||
$this->user = User::find(3);
|
||||
|
||||
$redemptionCode = $request->redemptionCode;
|
||||
$outletId = $request->outletId;
|
||||
|
||||
$data = $this->jiami($request->all());
|
||||
|
||||
$url = $this->baseUrl . 'user/query';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
return $res;
|
||||
if (isset($res['data'])) {
|
||||
$jiemi = $this->jiemi($res['data']);
|
||||
dump($jiemi);
|
||||
}
|
||||
|
||||
dump($this->getElapsedTime());
|
||||
dump($this->getMemoryUsage());
|
||||
|
||||
dump($res);
|
||||
|
||||
}
|
||||
|
||||
//卡券作废
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
$this->user = User::find(3);
|
||||
|
||||
$redemptionCode = $request->redemptionCode;
|
||||
$data = $this->jiami($request->all());
|
||||
|
||||
$url = $this->baseUrl . 'user/destroy';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
dump($this->getElapsedTime());
|
||||
dump($this->getMemoryUsage());
|
||||
if (isset($res['data'])) {
|
||||
$jiemi = $this->jiemi($res['data']);
|
||||
dump($jiemi);
|
||||
}
|
||||
dump($res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 核销
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/29 14:01
|
||||
*/
|
||||
public function checkcoupon(Request $request)
|
||||
{
|
||||
$user_id = $request->user_id;
|
||||
|
||||
$this->user = User::find($user_id);
|
||||
|
||||
$data = $this->jiami([
|
||||
'redemptionCode' => $request->redemptionCode,
|
||||
'total' => $request->total,
|
||||
'outletId' => $request->outletId,
|
||||
'orderid' => $request->orderid,
|
||||
]);
|
||||
|
||||
$url = $this->baseUrl . 'user/freezecoupon';
|
||||
$res = $this->http($data, $url);
|
||||
|
||||
return $res;
|
||||
|
||||
$redemptionCode = $request->redemptionCode;
|
||||
$total = $request->total;
|
||||
$outletId = $request->outletId;
|
||||
$orderid = $request->orderid ?? '';
|
||||
$res = Coupon::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid);
|
||||
|
||||
if (is_string($res)) {
|
||||
return $this->error($res);
|
||||
}
|
||||
|
||||
return $this->success('核销成功');
|
||||
}
|
||||
|
||||
public function http($data, $url)
|
||||
{
|
||||
$client = new Client();
|
||||
$response = $client->request('POST', $url, ['form_params' => $data, 'http_errors' => false]);
|
||||
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function jiami($ret)
|
||||
{
|
||||
$jsonData = json_encode($ret); //数据JSON化
|
||||
$ascdata = $this->keyasc($jsonData); //加密
|
||||
$addcode = sprintf("%08d", mt_rand(0, 99999999)); //随机code 验证签名用
|
||||
$sign = $this->keysign($ascdata, $addcode);
|
||||
|
||||
$data = [
|
||||
'server_id' => $this->user->server_id,
|
||||
'key' => $this->user->server_key,
|
||||
'addcode' => $addcode,
|
||||
'sign' => $sign,
|
||||
'data' => $ascdata,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param <type> $value
|
||||
* @return <type>
|
||||
*/
|
||||
public function jiemi($value)
|
||||
{
|
||||
$iv = substr($this->user->des3key, 0, 8);
|
||||
$ret = openssl_decrypt($value, 'DES - EDE3 - CBC', $this->user->des3key, 0, $iv);
|
||||
if (false === $ret) {
|
||||
return openssl_error_string();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getMemoryUsage($precision = 2)
|
||||
{
|
||||
$size = memory_get_usage(true);
|
||||
|
||||
$unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
|
||||
|
||||
return round($size / pow(1024, ($i = floor(log($size, 1024)))), $precision) . ' ' . $unit[$i];
|
||||
}
|
||||
|
||||
public function getElapsedTime(int $decimals = 2)
|
||||
{
|
||||
return number_format(microtime(true) - request()->server('REQUEST_TIME_FLOAT'), $decimals) . ' s';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ class Log extends Model
|
||||
Schema::create($this->table, function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('path', 255);
|
||||
$table->string('method', 15)->index();
|
||||
$table->string('method', 15);
|
||||
$table->text('in_source');
|
||||
$table->string('type', 20)->index();
|
||||
$table->string('type', 20);
|
||||
$table->text('out_source')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class PinganToken extends Model
|
||||
{
|
||||
|
||||
protected $dates = [
|
||||
'get_token_time',
|
||||
];
|
||||
|
||||
13
app/Models/UnionPayLog.php
Normal file
13
app/Models/UnionPayLog.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UnionPayLog extends Model
|
||||
{
|
||||
|
||||
protected $casts = [
|
||||
'in_source' => 'array',
|
||||
'out_source' => 'array',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -4,8 +4,10 @@ namespace App\Models;
|
||||
|
||||
class UserCode extends Model
|
||||
{
|
||||
|
||||
protected $casts = [
|
||||
'codes' => 'array',
|
||||
'profit' => 'array',
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class UserInfo extends Model
|
||||
/**
|
||||
* Notes: 获取性别的文字显示
|
||||
* @Author: <C.Jason>
|
||||
* @Date: 2019/9/12 09:46
|
||||
* @Date : 2019/9/12 09:46
|
||||
* @return string
|
||||
*/
|
||||
protected function getSexTextAttribute()
|
||||
@@ -35,7 +35,7 @@ class UserInfo extends Model
|
||||
/**
|
||||
* Notes: 处理默认头像
|
||||
* @Author: <C.Jason>
|
||||
* @Date: 2019/9/12 13:44
|
||||
* @Date : 2019/9/12 13:44
|
||||
* @param $avatar
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,6 @@ use App\Models\Traits\BelongsToUser;
|
||||
|
||||
class UserPingan extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
use BelongsToUser;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ namespace App\Models;
|
||||
|
||||
class WoCouponLog extends Model
|
||||
{
|
||||
|
||||
public function coupon()
|
||||
{
|
||||
return $this->belongsTo(WoCoupon::class, 'wo_coupon_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^7.2",
|
||||
"barryvdh/laravel-debugbar": "^3.4",
|
||||
"encore/laravel-admin": "^1.8",
|
||||
"fideloper/proxy": "^4.0",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
@@ -44,10 +45,12 @@
|
||||
"App\\": "app/",
|
||||
"RuLong\\Bonus\\": "packages/bonus/src/",
|
||||
"RuLong\\Identity\\": "packages/identity/src/",
|
||||
"XuanChen\\Coupon\\": "packages/coupon/src/"
|
||||
"XuanChen\\Coupon\\": "packages/coupon/src/",
|
||||
"XuanChen\\UnionPay\\": "packages/unionpay/src/"
|
||||
},
|
||||
"classmap": [
|
||||
"database/seeds",
|
||||
"database/migrations",
|
||||
"database/factories"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,17 +1,59 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'check' => [
|
||||
'check' => [
|
||||
'self' => [
|
||||
'private' => storage_path('cert/self/private_rsa.pem'),
|
||||
'public' => storage_path('cert/self/public_rsa.pem'),
|
||||
'private' => storage_path('cert/unionpay/self/private_rsa.pem'),
|
||||
'public' => storage_path('cert/unionpay/self/public_rsa.pem'),
|
||||
],
|
||||
'unionpay' => [
|
||||
'public' => storage_path('cert/unionpay/public_rsa.pem'),
|
||||
],
|
||||
],
|
||||
'fields' => [
|
||||
'query' => [
|
||||
'regular' => [
|
||||
'002025' => [
|
||||
"msg_type",
|
||||
"msg_txn_code",
|
||||
"msg_crrltn_id",
|
||||
"msg_flg",
|
||||
"msg_sender",
|
||||
"msg_time",
|
||||
"msg_ver",
|
||||
],
|
||||
'002100' => [
|
||||
"msg_type",
|
||||
"msg_txn_code",
|
||||
"msg_crrltn_id",
|
||||
"msg_flg",
|
||||
"msg_sender",
|
||||
"msg_time",
|
||||
"msg_sys_sn",
|
||||
"msg_ver",
|
||||
],
|
||||
'002101' => [
|
||||
"msg_type",
|
||||
"msg_txn_code",
|
||||
"msg_crrltn_id",
|
||||
"msg_flg",
|
||||
"msg_sender",
|
||||
"msg_time",
|
||||
"msg_sys_sn",
|
||||
"msg_ver",
|
||||
],
|
||||
'002102' => [
|
||||
"msg_type",
|
||||
"msg_txn_code",
|
||||
"msg_crrltn_id",
|
||||
"msg_flg",
|
||||
"msg_sender",
|
||||
"msg_time",
|
||||
"msg_sys_sn",
|
||||
"msg_ver",
|
||||
],
|
||||
],
|
||||
'fields' => [
|
||||
//聚合营销优惠查询接口
|
||||
'002025' => [
|
||||
'in' => [
|
||||
"msg_type" => "报文类型",
|
||||
"msg_txn_code" => "交易代码",
|
||||
@@ -61,9 +103,10 @@ return [
|
||||
"pos_ad" => "POS广告",
|
||||
"pos_mkt_ad" => "Pos_营销联盟广告",
|
||||
"sign" => "签名域",
|
||||
]
|
||||
],
|
||||
],
|
||||
'freezecoupon' => [
|
||||
//销账交易接口
|
||||
'002100' => [
|
||||
'in' => [
|
||||
"msg_type" => "报文类型",
|
||||
"msg_txn_code" => "交易代码",
|
||||
@@ -125,7 +168,73 @@ return [
|
||||
"mkt_sp_chnl_no" => "营销渠道号",
|
||||
"point_amt" => "积分抵扣金额",
|
||||
"sign" => "签名数据",
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
//销账冲正通知接口
|
||||
'002101' => [
|
||||
'in' => [
|
||||
"msg_type" => "报文类型",
|
||||
"msg_txn_code" => "交易代码",
|
||||
"msg_crrltn_id" => "消息关联号",
|
||||
"msg_flg" => "报文请求应答标志",
|
||||
"msg_sender" => "报文发送方",
|
||||
"msg_time" => "报文日期",
|
||||
"msg_sys_sn" => "平台流水号",
|
||||
"msg_ver" => "报文版本号",
|
||||
"shop_no" => "门店号",
|
||||
"term_no" => "终端号",
|
||||
"req_serial_no" => "冲正流水号",
|
||||
"orig_req_serial_no" => "原始销账流水号",
|
||||
"trans_crrltn_no" => "交易关联流水号",
|
||||
"sign" => "签名数据",
|
||||
],
|
||||
'out' => [
|
||||
"msg_type" => "报文类型",
|
||||
"msg_txn_code" => "交易代码",
|
||||
"msg_crrltn_id" => "消息关联号",
|
||||
"msg_flg" => "报文请求应答标志",
|
||||
"msg_sender" => "报文发送方",
|
||||
"msg_time" => "报文日期",
|
||||
"msg_sys_sn" => "平台流水号",
|
||||
"msg_ver" => "报文版本号",
|
||||
"msg_rsp_code" => "响应码",
|
||||
"msg_rsp_desc" => "响应码描述",
|
||||
"sign" => "签名数据",
|
||||
],
|
||||
],
|
||||
'002102' => [
|
||||
'in' => [
|
||||
"msg_type" => "报文类型",
|
||||
"msg_txn_code" => "交易代码",
|
||||
"msg_crrltn_id" => "消息关联号",
|
||||
"msg_flg" => "报文请求应答标志",
|
||||
"msg_sender" => "报文发送方",
|
||||
"msg_time" => "报文日期",
|
||||
"msg_sys_sn" => "平台流水号",
|
||||
"msg_ver" => "报文版本号",
|
||||
"shop_no" => "门店号",
|
||||
"term_no" => "终端号",
|
||||
"req_serial_no" => "撤销流水号",
|
||||
"orig_req_serial_no" => "原始销账流水号",
|
||||
"trans_crrltn_no" => "交易关联流水号",
|
||||
"sign" => "签名数据",
|
||||
],
|
||||
'out' => [
|
||||
"msg_type" => "报文类型",
|
||||
"msg_txn_code" => "交易代码",
|
||||
"msg_crrltn_id" => "消息关联号",
|
||||
"msg_flg" => "报文请求应答标志",
|
||||
"msg_sender" => "报文发送方",
|
||||
"msg_time" => "报文日期",
|
||||
"msg_sys_sn" => "平台流水号",
|
||||
"msg_ver" => "报文版本号",
|
||||
"msg_rsp_code" => "响应码",
|
||||
"msg_rsp_desc" => "响应码描述",
|
||||
"ad" => "广告",
|
||||
"td_code" => "二维码",
|
||||
"sign" => "签名数据",
|
||||
],
|
||||
],
|
||||
|
||||
],
|
||||
];
|
||||
|
||||
@@ -6,7 +6,7 @@ return [
|
||||
'ysd' => [
|
||||
// 'pattern' => '/^YSD\d{12}/',
|
||||
'pattern' => '/^YSD/',
|
||||
'model' => \XuanChen\Coupon\Action\UnionPayAction::class,
|
||||
'model' => \XuanChen\Coupon\Action\YsdAction::class,
|
||||
],
|
||||
'pingan' => [
|
||||
'pattern' => '/^\d{12}$/',
|
||||
|
||||
@@ -9,7 +9,7 @@ return [
|
||||
],
|
||||
'ysd' => [
|
||||
'pattern' => '/^YSD/',
|
||||
'model' => \XuanChen\Coupon\Action\UnionPayAction::class,
|
||||
'model' => \XuanChen\Coupon\Action\YsdAction::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action;
|
||||
|
||||
use XuanChen\Coupon\Action\sinopec\ZhyCreate;
|
||||
use XuanChen\Coupon\Contracts\CouponContracts;
|
||||
|
||||
/**
|
||||
* Class SinopecAction 中石化控制器
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:14
|
||||
* @package XuanChen\Coupon\Action
|
||||
*/
|
||||
class SinopecAction extends Init implements CouponContracts
|
||||
{
|
||||
/**
|
||||
* Notes: 创建营销活动
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 16:01
|
||||
* @param array $data
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$action = new ZhyCreate();
|
||||
$action->data = $data;
|
||||
|
||||
return $action->start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 发券接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:58
|
||||
*/
|
||||
function grant()
|
||||
{
|
||||
// TODO: Implement grant() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:58
|
||||
* @return mixed|void
|
||||
*/
|
||||
function detail()
|
||||
{
|
||||
// TODO: Implement detail() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 作废接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:59
|
||||
*/
|
||||
function destroy()
|
||||
{
|
||||
// TODO: Implement destroy() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 核销接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 16:00
|
||||
* @return mixed|void
|
||||
*/
|
||||
function start()
|
||||
{
|
||||
// TODO: Implement start() method.
|
||||
}
|
||||
}
|
||||
@@ -1,205 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\pingan;
|
||||
|
||||
use App\Models\PinganToken;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use XuanChen\Coupon\Action\Init;
|
||||
|
||||
/**
|
||||
* 超市购物券
|
||||
*/
|
||||
class PingAnInit extends Init
|
||||
{
|
||||
|
||||
protected $this_type;
|
||||
|
||||
protected $baseUri;
|
||||
|
||||
protected $tokenUri;
|
||||
|
||||
protected $client_id;
|
||||
|
||||
protected $grant_type;
|
||||
|
||||
protected $client_secret;
|
||||
|
||||
protected $access_token;
|
||||
|
||||
protected $userName;
|
||||
|
||||
protected $error;
|
||||
|
||||
protected $aes_code; //aes 密钥
|
||||
|
||||
protected $log;//日志
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->this_type = config('pingan.this_type');
|
||||
$pingan = config('pingan.' . $this->this_type);
|
||||
|
||||
$this->baseUri = $pingan['Uri'];
|
||||
$this->tokenUri = $pingan['tokenUri'];
|
||||
$this->client_id = $pingan['client_id'];
|
||||
$this->grant_type = $pingan['grant_type'];
|
||||
$this->userName = $pingan['userName'];
|
||||
$this->client_secret = $pingan['client_secret'];
|
||||
$this->aes_code = $pingan['AES_CODE'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
//从数据库里找token
|
||||
$token = PinganToken::where('type', $this->this_type)->orderBy('id', 'desc')->first();
|
||||
|
||||
if ($token) {
|
||||
$access_token = $token->access_token;
|
||||
$expires_in = $token->expires_in;
|
||||
$get_token_time = $token->get_token_time;
|
||||
$diffMinutes = $get_token_time->diffInMinutes(now(), false);
|
||||
if ($diffMinutes < $expires_in) {
|
||||
$this->access_token = $access_token;
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取毫秒级别的时间戳
|
||||
*/
|
||||
public function getMsecTime()
|
||||
{
|
||||
[$msec, $sec] = explode(' ', microtime());
|
||||
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
||||
$msectime = explode('.', $msectime);
|
||||
|
||||
return $msectime[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求平台 access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getAjaxToken()
|
||||
{
|
||||
$params = [
|
||||
'client_id' => $this->client_id,
|
||||
'grant_type' => $this->grant_type,
|
||||
'client_secret' => $this->client_secret,
|
||||
];
|
||||
|
||||
try {
|
||||
$log = $this->createLog($this->tokenUri, 'POST', $params, 'pingan');
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->request('POST', $this->tokenUri, [
|
||||
'form_params' => $params,
|
||||
]);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
$this->updateLog($log, $result); //更新日志
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$this->error = $result['msg'];
|
||||
} else {
|
||||
$data = $result['data'];
|
||||
PinganToken::create([
|
||||
'type' => $this->this_type,
|
||||
'access_token' => $data['access_token'],
|
||||
'expires_in' => $data['expires_in'],
|
||||
'get_token_time' => now(),
|
||||
]);
|
||||
$this->access_token = $data['access_token'];
|
||||
$this->error = '';
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->updateLog($log, [$this->error]); //更新日志
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用获取数据接口
|
||||
* @param [type] $url 请求地址
|
||||
* @param array $query 传递参数
|
||||
* @param array $json 需要传的json数据
|
||||
* @param string $method 方式
|
||||
* @return array|mixed [type] [description]
|
||||
*/
|
||||
public function getPingAnData($url, $query = [], $json = [], $method = 'POST')
|
||||
{
|
||||
$this->getToken();
|
||||
|
||||
if ($this->error) {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
$postData = [
|
||||
'query' => array_merge([
|
||||
'access_token' => $this->access_token,
|
||||
'request_id' => $this->getMsecTime(),
|
||||
'userName' => $this->userName,
|
||||
], $query),
|
||||
'json' => $json,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json;charset=utf-8',
|
||||
'accept' => 'application/json;charset=utf-8',
|
||||
],
|
||||
];
|
||||
|
||||
$log = $this->createLog($url, $method, $postData, 'pingan'); //日志
|
||||
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->request($method, $url, $postData);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$retData = $result['msg'];
|
||||
} else {
|
||||
$retData = $result['data'];
|
||||
}
|
||||
$this->updateLog($log, $retData);//更新日志
|
||||
|
||||
return $retData;
|
||||
} catch (RequestException $e) {
|
||||
$this->updateLog($log, [$e->getMessage()]);//更新日志
|
||||
|
||||
return ['ret' => '99999', $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//加密
|
||||
public function encrypt($str)
|
||||
{
|
||||
if (is_array($str)) {
|
||||
$str = json_encode($str);
|
||||
}
|
||||
$data = openssl_encrypt($str, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
|
||||
return base64_encode($data);
|
||||
}
|
||||
|
||||
//解密
|
||||
public function decrypt($str)
|
||||
{
|
||||
$encrypted = base64_decode($str);
|
||||
|
||||
return openssl_decrypt($encrypted, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\pingan;
|
||||
|
||||
use App\Models\PinganToken;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use XuanChen\Coupon\Action\Init;
|
||||
|
||||
/**
|
||||
* 超市购物券
|
||||
*/
|
||||
class PingAnInit extends Init
|
||||
{
|
||||
|
||||
protected $this_type;
|
||||
|
||||
protected $baseUri;
|
||||
|
||||
protected $tokenUri;
|
||||
|
||||
protected $client_id;
|
||||
|
||||
protected $grant_type;
|
||||
|
||||
protected $client_secret;
|
||||
|
||||
protected $access_token;
|
||||
|
||||
protected $userName;
|
||||
|
||||
protected $error;
|
||||
|
||||
protected $aes_code; //aes 密钥
|
||||
|
||||
protected $log;//日志
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->this_type = config('pingan.this_type');
|
||||
$pingan = config('pingan.' . $this->this_type);
|
||||
|
||||
$this->baseUri = $pingan['Uri'];
|
||||
$this->tokenUri = $pingan['tokenUri'];
|
||||
$this->client_id = $pingan['client_id'];
|
||||
$this->grant_type = $pingan['grant_type'];
|
||||
$this->userName = $pingan['userName'];
|
||||
$this->client_secret = $pingan['client_secret'];
|
||||
$this->aes_code = $pingan['AES_CODE'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
//从数据库里找token
|
||||
$token = PinganToken::where('type', $this->this_type)->orderBy('id', 'desc')->first();
|
||||
|
||||
if ($token) {
|
||||
$access_token = $token->access_token;
|
||||
$expires_in = $token->expires_in;
|
||||
$get_token_time = $token->get_token_time;
|
||||
$diffMinutes = $get_token_time->diffInMinutes(now(), false);
|
||||
if ($diffMinutes < $expires_in) {
|
||||
$this->access_token = $access_token;
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取毫秒级别的时间戳
|
||||
*/
|
||||
public function getMsecTime()
|
||||
{
|
||||
[$msec, $sec] = explode(' ', microtime());
|
||||
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
||||
$msectime = explode('.', $msectime);
|
||||
|
||||
return $msectime[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求平台 access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getAjaxToken()
|
||||
{
|
||||
$params = [
|
||||
'client_id' => $this->client_id,
|
||||
'grant_type' => $this->grant_type,
|
||||
'client_secret' => $this->client_secret,
|
||||
];
|
||||
|
||||
try {
|
||||
$log = $this->createLog($this->tokenUri, 'POST', $params, 'pingan');
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->request('POST', $this->tokenUri, [
|
||||
'form_params' => $params,
|
||||
]);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
$this->updateLog($log, $result); //更新日志
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$this->error = $result['msg'];
|
||||
} else {
|
||||
$data = $result['data'];
|
||||
PinganToken::create([
|
||||
'type' => $this->this_type,
|
||||
'access_token' => $data['access_token'],
|
||||
'expires_in' => $data['expires_in'],
|
||||
'get_token_time' => now(),
|
||||
]);
|
||||
$this->access_token = $data['access_token'];
|
||||
$this->error = '';
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->updateLog($log, [$this->error]); //更新日志
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用获取数据接口
|
||||
* @param [type] $url 请求地址
|
||||
* @param array $query 传递参数
|
||||
* @param array $json 需要传的json数据
|
||||
* @param string $method 方式
|
||||
* @return array|mixed [type] [description]
|
||||
*/
|
||||
public function getPingAnData($url, $query = [], $json = [], $method = 'POST')
|
||||
{
|
||||
$this->getToken();
|
||||
|
||||
if ($this->error) {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
$postData = [
|
||||
'query' => array_merge([
|
||||
'access_token' => $this->access_token,
|
||||
'request_id' => $this->getMsecTime(),
|
||||
'userName' => $this->userName,
|
||||
], $query),
|
||||
'json' => $json,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json;charset=utf-8',
|
||||
'accept' => 'application/json;charset=utf-8',
|
||||
],
|
||||
];
|
||||
|
||||
$log = $this->createLog($url, $method, $postData, 'pingan'); //日志
|
||||
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->request($method, $url, $postData);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$retData = $result['msg'];
|
||||
} else {
|
||||
$retData = $result['data'];
|
||||
}
|
||||
$this->updateLog($log, $retData);//更新日志
|
||||
|
||||
return $retData;
|
||||
} catch (RequestException $e) {
|
||||
$this->updateLog($log, [$e->getMessage()]);//更新日志
|
||||
|
||||
return ['ret' => '99999', $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//加密
|
||||
public function encrypt($str)
|
||||
{
|
||||
if (is_array($str)) {
|
||||
$str = json_encode($str);
|
||||
}
|
||||
$data = openssl_encrypt($str, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
|
||||
return base64_encode($data);
|
||||
}
|
||||
|
||||
//解密
|
||||
public function decrypt($str)
|
||||
{
|
||||
$encrypted = base64_decode($str);
|
||||
|
||||
return openssl_decrypt($encrypted, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\sinopec;
|
||||
|
||||
use XuanChen\Coupon\Contracts\CheckCouponContracts;
|
||||
|
||||
class ZhyCreate implements CheckCouponContracts
|
||||
{
|
||||
public $data;
|
||||
|
||||
public function start()
|
||||
{
|
||||
|
||||
try {
|
||||
[
|
||||
"cooperativeMerchant" => "",
|
||||
"eletronAndRule" => [
|
||||
[
|
||||
"entryMethod" => "01",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleNumber" => "001",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"queryCreateTime" => "2019-11-11 18=> 39=> 49",
|
||||
"similarStack" => "Y",
|
||||
"voucherEndTime" => "2019-12-15",
|
||||
"voucher_ruleCode" => "$01-VC-1573468710381900",
|
||||
"voucherRuleName" => "ceshi2",
|
||||
"voucherSource" => "S01",
|
||||
"voucherStartTime" => "2019-12-13",
|
||||
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME"
|
||||
]
|
||||
],
|
||||
"limitFrequency" => "",
|
||||
"mabIsRefund" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketExEndTime" => "2019-12-15 00=> 00=> 00",
|
||||
"marketExStartTime" => "2019-12-13 00=> 00=> 00",
|
||||
"marketHierarchy" => "3311",
|
||||
"marketName" => "行为推送活动-3",
|
||||
"marketProvince" => "51",
|
||||
"marketReleaseSys" => "VOUCHER_PUBLISH_TYPE_APPLET",
|
||||
"marketStatus" => "MARKET_ACTIVITY_STATE_TAKE_EFFECT",
|
||||
"promotionCalculation" => "PROMOTION_TYPE_MEMBER_BEHAVIOR",
|
||||
"rule" => [
|
||||
[
|
||||
"cashValue" => "100",
|
||||
"channel" => "C01,C02,C03,C05",
|
||||
"fullType" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"ruleCode" => "$01-VC-1573468710381900",
|
||||
"ruleDetail" => "123123",
|
||||
"ruleName" => "ceshi2",
|
||||
"voucherType" => "C01"
|
||||
]
|
||||
],
|
||||
"tradLimit" => [
|
||||
[
|
||||
"endValue" => "",
|
||||
"fixed" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleName" => "001",
|
||||
"marketRuleNumber" => "001",
|
||||
"memLevel" => "",
|
||||
"operator" => "",
|
||||
"startValue" => "",
|
||||
"tradingUnit" => "",
|
||||
"transactionType" => ""
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\sinopec;
|
||||
|
||||
use XuanChen\Coupon\Contracts\CheckCouponContracts;
|
||||
|
||||
class ZhyQuery implements CheckCouponContracts
|
||||
{
|
||||
public $data;
|
||||
|
||||
public function start()
|
||||
{
|
||||
|
||||
try {
|
||||
[
|
||||
"cooperativeMerchant" => "",
|
||||
"eletronAndRule" => [
|
||||
[
|
||||
"entryMethod" => "01",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleNumber" => "001",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"queryCreateTime" => "2019-11-11 18=> 39=> 49",
|
||||
"similarStack" => "Y",
|
||||
"voucherEndTime" => "2019-12-15",
|
||||
"voucher_ruleCode" => "$01-VC-1573468710381900",
|
||||
"voucherRuleName" => "ceshi2",
|
||||
"voucherSource" => "S01",
|
||||
"voucherStartTime" => "2019-12-13",
|
||||
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME"
|
||||
]
|
||||
],
|
||||
"limitFrequency" => "",
|
||||
"mabIsRefund" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketExEndTime" => "2019-12-15 00=> 00=> 00",
|
||||
"marketExStartTime" => "2019-12-13 00=> 00=> 00",
|
||||
"marketHierarchy" => "3311",
|
||||
"marketName" => "行为推送活动-3",
|
||||
"marketProvince" => "51",
|
||||
"marketReleaseSys" => "VOUCHER_PUBLISH_TYPE_APPLET",
|
||||
"marketStatus" => "MARKET_ACTIVITY_STATE_TAKE_EFFECT",
|
||||
"promotionCalculation" => "PROMOTION_TYPE_MEMBER_BEHAVIOR",
|
||||
"rule" => [
|
||||
[
|
||||
"cashValue" => "100",
|
||||
"channel" => "C01,C02,C03,C05",
|
||||
"fullType" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"ruleCode" => "$01-VC-1573468710381900",
|
||||
"ruleDetail" => "123123",
|
||||
"ruleName" => "ceshi2",
|
||||
"voucherType" => "C01"
|
||||
]
|
||||
],
|
||||
"tradLimit" => [
|
||||
[
|
||||
"endValue" => "",
|
||||
"fixed" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleName" => "001",
|
||||
"marketRuleNumber" => "001",
|
||||
"memLevel" => "",
|
||||
"operator" => "",
|
||||
"startValue" => "",
|
||||
"tradingUnit" => "",
|
||||
"transactionType" => ""
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 自有卡券系统
|
||||
*/
|
||||
class Coupon
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 发券接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/28 15:07
|
||||
* @param $activityId 活动编号
|
||||
* @param $outletId 网点编号
|
||||
* @param $mobile 手机号
|
||||
*/
|
||||
public static function Grant($activityId, $outletId, $mobile)
|
||||
{
|
||||
$model = config('xuanchen_coupon.rules.ysd.model');
|
||||
|
||||
return (new $model)->setActivityId($activityId)
|
||||
->setOutletId($outletId)
|
||||
->setMobile($mobile)
|
||||
->grant();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 11:58
|
||||
* @param $redemptionCode
|
||||
*/
|
||||
public static function Query($redemptionCode, $outletId)
|
||||
{
|
||||
if (!$redemptionCode) {
|
||||
return '查询失败,未获取到券码';
|
||||
}
|
||||
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->detail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 卡券作废
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/2 16:54
|
||||
* @param $redemptionCode
|
||||
* @param $outletId
|
||||
* @return string
|
||||
*/
|
||||
public static function Destroy($redemptionCode, $outletId)
|
||||
{
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->destroy();
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据券码 获取class
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 12:00
|
||||
* @param $code
|
||||
* @return string
|
||||
*/
|
||||
public static function getModelByCode($code)
|
||||
{
|
||||
$rules = config('xuanchen_coupon.rules');
|
||||
if (!$rules) {
|
||||
return '系统出错,未找到配置文件';
|
||||
}
|
||||
|
||||
$model = '';
|
||||
foreach ($rules as $rule) {
|
||||
if (preg_match($rule['pattern'], $code, $matches)) {
|
||||
$model = $rule['model'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$model) {
|
||||
throw new \Exception('卡券核销失败。未查到卡券所属');
|
||||
}
|
||||
|
||||
return new $model;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/8/21 13:33
|
||||
* @param \App\Models\User $user 渠道
|
||||
* @param string $redemptionCode 要核销的券码
|
||||
* @param float $total 订单金额
|
||||
* @param string $outletId 网点id
|
||||
* @param string $orderid 订单id
|
||||
* @return string
|
||||
*/
|
||||
public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '')
|
||||
{
|
||||
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setUser($user)
|
||||
->setCode($redemptionCode)
|
||||
->setTotal($total)
|
||||
->setOutletId($outletId)
|
||||
->setOrderId($orderid)
|
||||
->start();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 自有卡券系统
|
||||
*/
|
||||
class Coupon
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 发券接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/28 15:07
|
||||
* @param $activityId 活动编号
|
||||
* @param $outletId 网点编号
|
||||
* @param $mobile 手机号
|
||||
*/
|
||||
public static function Grant($activityId, $outletId, $mobile)
|
||||
{
|
||||
$model = config('xuanchen_coupon.rules.ysd.model');
|
||||
|
||||
return (new $model)->setActivityId($activityId)
|
||||
->setOutletId($outletId)
|
||||
->setMobile($mobile)
|
||||
->grant();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 11:58
|
||||
* @param $redemptionCode
|
||||
*/
|
||||
public static function Query($redemptionCode, $outletId)
|
||||
{
|
||||
if (!$redemptionCode) {
|
||||
return '查询失败,未获取到券码';
|
||||
}
|
||||
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->detail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 卡券作废
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/2 16:54
|
||||
* @param $redemptionCode
|
||||
* @param $outletId
|
||||
* @return string
|
||||
*/
|
||||
public static function Destroy($redemptionCode, $outletId)
|
||||
{
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->destroy();
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据券码 获取class
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 12:00
|
||||
* @param $code
|
||||
* @return string
|
||||
*/
|
||||
public static function getModelByCode($code)
|
||||
{
|
||||
$rules = config('xuanchen_coupon.rules');
|
||||
if (!$rules) {
|
||||
return '系统出错,未找到配置文件';
|
||||
}
|
||||
|
||||
$model = '';
|
||||
foreach ($rules as $rule) {
|
||||
if (preg_match($rule['pattern'], $code, $matches)) {
|
||||
$model = $rule['model'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$model) {
|
||||
throw new \Exception('卡券核销失败。未查到卡券所属');
|
||||
}
|
||||
|
||||
return new $model;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/8/21 13:33
|
||||
* @param \App\Models\User $user 渠道
|
||||
* @param string $redemptionCode 要核销的券码
|
||||
* @param float $total 订单金额
|
||||
* @param string $outletId 网点id
|
||||
* @param string $orderid 订单id
|
||||
* @return string
|
||||
*/
|
||||
public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '')
|
||||
{
|
||||
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setUser($user)
|
||||
->setCode($redemptionCode)
|
||||
->setTotal($total)
|
||||
->setOutletId($outletId)
|
||||
->setOrderId($orderid)
|
||||
->start();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
packages/coupon/src/CouponServiceProvider.php
Normal file
32
packages/coupon/src/CouponServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class CouponServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Register services.
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
dd(1);
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([__DIR__ . '/../config/xuanchen_coupon.php' => config_path('xuanchen_coupon.php')]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__ . '/../config/xuanchen_coupon.php', 'xuanchen_coupon');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Traits;
|
||||
|
||||
use App\Models\Log as LogModel;
|
||||
|
||||
trait Log
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 插入日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $url
|
||||
* @param $method
|
||||
* @param $params
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function createLog($url, $method, $params, $type = 'pingan')
|
||||
{
|
||||
$data = [
|
||||
'path' => $url,
|
||||
'method' => $method,
|
||||
'type' => $type,
|
||||
'in_source' => $params,
|
||||
];
|
||||
|
||||
$info = LogModel::create($data);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 更新日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $log
|
||||
* @param $params
|
||||
*/
|
||||
public static function updateLog($log, $params)
|
||||
{
|
||||
$log->out_source = $params;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Traits;
|
||||
|
||||
use App\Models\Log as LogModel;
|
||||
|
||||
trait Log
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 插入日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $url
|
||||
* @param $method
|
||||
* @param $params
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function createLog($url, $method, $params, $type = 'pingan')
|
||||
{
|
||||
$data = [
|
||||
'path' => $url,
|
||||
'method' => $method,
|
||||
'type' => $type,
|
||||
'in_source' => $params,
|
||||
];
|
||||
|
||||
$info = LogModel::create($data);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 更新日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $log
|
||||
* @param $params
|
||||
*/
|
||||
public static function updateLog($log, $params)
|
||||
{
|
||||
$log->out_source = $params;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ return [
|
||||
],
|
||||
'ysd' => [
|
||||
'pattern' => '/^YSD/',
|
||||
'model' => \XuanChen\Coupon\Action\UnionPayAction::class,
|
||||
'model' => \XuanChen\Coupon\Action\SinopecAction::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace XuanChen\UnionPay\Action;
|
||||
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Init
|
||||
{
|
||||
public $params;
|
||||
public $sign;
|
||||
|
||||
/**
|
||||
* RSA验签
|
||||
@@ -14,15 +17,16 @@ class Init
|
||||
* @param $sign 要校对的的签名结果
|
||||
* return 验证结果
|
||||
*/
|
||||
public function rsaSign($params, $self = false)
|
||||
public function checkSign($self = false)
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
|
||||
$sign = $this->sign;
|
||||
$sign = base64_decode($sign);
|
||||
|
||||
$public_key = $this->getPublic($self);
|
||||
|
||||
$pub_key_id = openssl_get_publickey($public_key);
|
||||
|
||||
$signStr = $this->getSignString($params);
|
||||
$signStr = $this->getSignString($this->params);
|
||||
|
||||
if ($pub_key_id) {
|
||||
$result = (bool)openssl_verify($signStr, $sign, $pub_key_id);
|
||||
@@ -34,14 +38,36 @@ class Init
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 签名
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/29 9:56
|
||||
* @return string
|
||||
*/
|
||||
public function getSign()
|
||||
{
|
||||
$signStr = $this->getSignString();
|
||||
$private_key = $this->getPrivate();
|
||||
|
||||
$privKeyId = openssl_pkey_get_private($private_key);
|
||||
if (!$privKeyId) {
|
||||
return '私钥格式有误';
|
||||
}
|
||||
|
||||
openssl_sign($signStr, $signature, $privKeyId);
|
||||
openssl_free_key($privKeyId);
|
||||
|
||||
return base64_encode($signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取待签名字符串
|
||||
* @param array $params 参数数组
|
||||
* @return string
|
||||
*/
|
||||
public function getSignString($params)
|
||||
public function getSignString()
|
||||
{
|
||||
$params = array_filter($params);
|
||||
$params = array_filter($this->params);
|
||||
ksort($params);
|
||||
$signStr = http_build_query($params);
|
||||
return $signStr;
|
||||
@@ -51,6 +77,11 @@ class Init
|
||||
public function getPrivate()
|
||||
{
|
||||
$private = config('unionpay.check.self.private');
|
||||
|
||||
if (!file_exists($private)) {
|
||||
throw new \Exception('缺少私钥文件');
|
||||
}
|
||||
|
||||
return file_get_contents($private);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,20 @@
|
||||
namespace XuanChen\UnionPay;
|
||||
|
||||
use App\Models\User;
|
||||
use http\Env\Request;
|
||||
use XuanChen\UnionPay\Action\Init;
|
||||
|
||||
/**
|
||||
* 银联入口
|
||||
*/
|
||||
class UnionPay
|
||||
class UnionPay extends Init
|
||||
{
|
||||
|
||||
public function __construct($params, $sign = '')
|
||||
{
|
||||
$this->params = $params;
|
||||
$this->sign = $sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
@@ -126,24 +132,4 @@ class UnionPay
|
||||
|
||||
}
|
||||
|
||||
//验证签名
|
||||
public function checkSign($params)
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
|
||||
$signStr = $this->getSignString($params);
|
||||
|
||||
$private_key = $this->getPrivate();
|
||||
$privKeyId = openssl_pkey_get_private($private_key);
|
||||
if (!$privKeyId) {
|
||||
return '私钥格式有误';
|
||||
}
|
||||
|
||||
openssl_sign($signStr, $signature, $privKeyId, OPENSSL_ALGO_SHA1);
|
||||
openssl_free_key($privKeyId);
|
||||
|
||||
return bin2hex($signature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user