阶段更新

This commit is contained in:
2020-09-29 14:17:56 +08:00
parent 996ed300f5
commit abfcfab3ba
26 changed files with 936 additions and 946 deletions

View File

@@ -69,20 +69,20 @@ class LogController extends AdminController
$grid->column('id', '#ID#'); $grid->column('id', '#ID#');
$grid->column('code', '卡券编号'); $grid->column('code', '卡券编号');
$grid->column('type', '分类') $grid->column('type', '分类')
->using(ActivityCouponLog::TYPES) ->using(ActivityCouponLog::TYPES)
->label([ ->label([
1 => 'default', 1 => 'default',
2 => 'warning', 2 => 'warning',
3 => 'info', 3 => 'info',
]); ]);
$grid->column('status', '状态') $grid->column('status', '状态')
->using(ActivityCouponLog::STATUS) ->using(ActivityCouponLog::STATUS)
->label([ ->label([
1 => 'default', 1 => 'default',
2 => 'warning', 2 => 'warning',
3 => 'info', 3 => 'info',
]); ]);
$grid->column('remark', '处理结果'); $grid->column('remark', '处理结果');

View 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());
}
}
}

View File

@@ -4,7 +4,7 @@ namespace App\Api\Controllers;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use XuanChen\Coupon\UnionPay; use XuanChen\Coupon\Coupon;
class UserController extends Controller class UserController extends Controller
{ {
@@ -63,7 +63,7 @@ class UserController extends Controller
return $this->error($validator->errors()->first(), $log); 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)) { if (is_string($res)) {
return $this->error($res, $log); return $this->error($res, $log);
@@ -106,7 +106,7 @@ class UserController extends Controller
$redemptionCode = $res['redemptionCode']; $redemptionCode = $res['redemptionCode'];
$outletId = $res['outletId']; $outletId = $res['outletId'];
$res = UnionPay::Query($redemptionCode, $outletId); $res = Coupon::Query($redemptionCode, $outletId);
if (is_string($res)) { if (is_string($res)) {
return $this->error($res, $log); return $this->error($res, $log);
@@ -141,7 +141,7 @@ class UserController extends Controller
$redemptionCode = $res['redemptionCode']; $redemptionCode = $res['redemptionCode'];
$outletId = $res['outletId']; $outletId = $res['outletId'];
$res = UnionPay::Destroy($redemptionCode, $outletId); $res = Coupon::Destroy($redemptionCode, $outletId);
if ($res !== true) { if ($res !== true) {
return $this->error($res, $log); return $this->error($res, $log);
@@ -188,7 +188,7 @@ class UserController extends Controller
$redemptionCode = trim($redemptionCode); $redemptionCode = trim($redemptionCode);
$outletId = trim($outletId); $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)) { if (is_string($coupon)) {
return $this->error($coupon, $log); return $this->error($coupon, $log);
} }

View File

@@ -18,4 +18,9 @@ Route::group(['prefix' => 'V1'], function () {
Route::post('ticket/cancel', 'WoController@cancel'); //退业务 Route::post('ticket/cancel', 'WoController@cancel'); //退业务
Route::post('ticket/query', 'WoController@query'); //退业务 Route::post('ticket/query', 'WoController@query'); //退业务
//银联相关
Route::post('unionpay/index', 'UnionPayController@index');
Route::post('unionpay/query', 'UnionPayController@query');
}); });

View File

@@ -1,251 +1,235 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Api\Controllers\ApiResponse; use App\Api\Controllers\ApiResponse;
use SelfCoupon; use App\Models\User;
use App\Models\User; use GuzzleHttp\Client;
use GuzzleHttp\Client; use Illuminate\Http\Request;
use Illuminate\Http\Request; use XuanChen\Coupon\Coupon;
use XuanChen\Coupon\UnionPay;
class TestController
// use Wo; {
class TestController use ApiResponse;
{
public $baseUrl = 'http://pac.ysd-bs.com/api/V1/';
use ApiResponse;
public function index(Request $request)
public $baseUrl = 'http://pa.ysd-bs.com/api/V1/'; {
$user_id = $request->user_id;
public function index(Request $request) $data = $request->data;
{ $this->user = User::find(3);
// $user_id = $request->user_id;
// $data = $request->data; $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';
// $this->user = User::find(3); $iv = substr($this->user->des3key, 0, 8);
// $ret = openssl_decrypt($data, 'DES-EDE3-CBC', $this->user->des3key, 0, $iv);
// $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'; if (false === $ret) {
// $iv = substr($this->user->des3key, 0, 8); return openssl_error_string();
// $ret = openssl_decrypt($data, 'DES-EDE3-CBC', $this->user->des3key, 0, $iv); }
// if (false === $ret) { dd($ret);
// return openssl_error_string(); dd();
// } $this->user = User::find(215);
// dd($ret); $ret = [
// dd(); 'redemptionCode' => '951951858070',
$this->user = User::find(4); 'total' => 5,
$ret = [ 'outletId' => '2006151433887',
'variable' => 100, ];
'mobile' => 15663876870,
'type' => 'silver', return $this->success($ret);
'remark' => '测试', dd(phpinfo());
]; dd();
$res['server_id'] = $this->user->server_id; $num = 100;
$res['des'] = $this->user->des3key;
$res['key'] = $this->user->server_key; for ($i = 1; $i <= $num; $i++) {
$data = [
return $this->success($ret); 'outletId' => '2004020935777',
dd(); 'activityId' => 'ysd20200740',
$this->user = User::find(4); 'mobile' => '15663876870',
$ret = [ ];
'redemptionCode' => '951951858070',
'total' => 5, $this->user = User::find(3);
'outletId' => '2008241014458',
]; $data = $this->jiami($data);
return $this->success($ret); $url = $this->baseUrl . 'user/grant';
dd(phpinfo()); $res = $this->http($data, $url);
dd();
$num = 100; // if (isset($res['data'])) {
// $jiemi = $this->jiemi($res['data']);
for ($i = 1; $i <= $num; $i++) { // dump($jiemi);
$data = [ // }
'outletId' => '2004020935777',
'activityId' => 'ysd20200740', }
'mobile' => '15663876870',
]; dump($this->getElapsedTime());
dump($this->getMemoryUsage());
$this->user = User::find(3);
}
$data = $this->jiami($data);
/**
$url = $this->baseUrl . 'user/grant'; * Notes: 发券
$res = $this->http($data, $url); * @Author: 玄尘
* @Date : 2020/6/29 13:57
// if (isset($res['data'])) { */
// $jiemi = $this->jiemi($res['data']); public function grant(Request $request)
// dump($jiemi); {
// } $this->user = User::find(3);
} $data = $this->jiami($request->all());
dump($this->getElapsedTime()); $url = $this->baseUrl . 'user/grant';
dump($this->getMemoryUsage()); $res = $this->http($data, $url);
} return $res;
/** // dump($this->getElapsedTime());
* Notes: 发券 // dump($this->getMemoryUsage());
* @Author: 玄尘 //
* @Date : 2020/6/29 13:57 // dd($res);
*/ }
public function grant(Request $request)
{ //查询
$this->user = User::find(3); public function query(Request $request)
{
$data = $this->jiami($request->all()); $this->user = User::find(3);
$url = $this->baseUrl . 'user/grant'; $redemptionCode = $request->redemptionCode;
$res = $this->http($data, $url); $outletId = $request->outletId;
return $res; $data = $this->jiami($request->all());
// dump($this->getElapsedTime()); $url = $this->baseUrl . 'user/query';
// dump($this->getMemoryUsage()); $res = $this->http($data, $url);
//
// dd($res); return $res;
} if (isset($res['data'])) {
$jiemi = $this->jiemi($res['data']);
//查询 dump($jiemi);
public function query(Request $request) }
{
$this->user = User::find(3); dump($this->getElapsedTime());
dump($this->getMemoryUsage());
$redemptionCode = $request->redemptionCode;
$outletId = $request->outletId; dump($res);
$data = $this->jiami($request->all()); }
$url = $this->baseUrl . 'user/query'; //卡券作废
$res = $this->http($data, $url); public function destroy(Request $request)
{
return $res; $this->user = User::find(3);
if (isset($res['data'])) {
$jiemi = $this->jiemi($res['data']); $redemptionCode = $request->redemptionCode;
dump($jiemi); $data = $this->jiami($request->all());
}
$url = $this->baseUrl . 'user/destroy';
dump($this->getElapsedTime()); $res = $this->http($data, $url);
dump($this->getMemoryUsage());
dump($this->getElapsedTime());
dump($res); dump($this->getMemoryUsage());
if (isset($res['data'])) {
} $jiemi = $this->jiemi($res['data']);
dump($jiemi);
//卡券作废 }
public function destroy(Request $request) dump($res);
{
$this->user = User::find(3); }
$redemptionCode = $request->redemptionCode; /**
$data = $this->jiami($request->all()); * Notes: 核销
* @Author: 玄尘
$url = $this->baseUrl . 'user/destroy'; * @Date : 2020/6/29 14:01
$res = $this->http($data, $url); */
public function checkcoupon(Request $request)
dump($this->getElapsedTime()); {
dump($this->getMemoryUsage()); $user_id = $request->user_id;
if (isset($res['data'])) {
$jiemi = $this->jiemi($res['data']); $this->user = User::find($user_id);
dump($jiemi);
} $data = $this->jiami([
dump($res); 'redemptionCode' => $request->redemptionCode,
'total' => $request->total,
} 'outletId' => $request->outletId,
'orderid' => $request->orderid,
/** ]);
* Notes: 核销
* @Author: 玄尘 $url = $this->baseUrl . 'user/freezecoupon';
* @Date : 2020/6/29 14:01 $res = $this->http($data, $url);
*/
public function checkcoupon(Request $request) return $res;
{
$user_id = $request->user_id; $redemptionCode = $request->redemptionCode;
$total = $request->total;
$this->user = User::find($user_id); $outletId = $request->outletId;
$orderid = $request->orderid ?? '';
$data = $this->jiami([ $res = Coupon::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid);
'redemptionCode' => $request->redemptionCode,
'total' => $request->total, if (is_string($res)) {
'outletId' => $request->outletId, return $this->error($res);
'orderid' => $request->orderid, }
]);
return $this->success('核销成功');
$url = $this->baseUrl . 'user/freezecoupon'; }
$res = $this->http($data, $url);
public function http($data, $url)
return $res; {
$client = new Client();
$redemptionCode = $request->redemptionCode; $response = $client->request('POST', $url, ['form_params' => $data, 'http_errors' => false]);
$total = $request->total;
$outletId = $request->outletId; $body = $response->getBody();
$orderid = $request->orderid ?? ''; $content = $body->getContents();
$res = UnionPay::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid); $result = json_decode($content, true);
if (is_string($res)) { return $result;
return $this->error($res); }
}
public function jiami($ret)
return $this->success('核销成功'); {
} $jsonData = json_encode($ret); //数据JSON化
$ascdata = $this->keyasc($jsonData); //加密
public function http($data, $url) $addcode = sprintf("%08d", mt_rand(0, 99999999)); //随机code 验证签名用
{ $sign = $this->keysign($ascdata, $addcode);
$client = new Client();
$response = $client->request('POST', $url, ['form_params' => $data, 'http_errors' => false]); $data = [
'server_id' => $this->user->server_id,
$body = $response->getBody(); 'key' => $this->user->server_key,
$content = $body->getContents(); 'addcode' => $addcode,
$result = json_decode($content, true); 'sign' => $sign,
'data' => $ascdata,
return $result; ];
}
return $data;
public function jiami($ret) }
{
$jsonData = json_encode($ret); //数据JSON化 /**
$ascdata = $this->keyasc($jsonData); //加 * 解
$addcode = sprintf("%08d", mt_rand(0, 99999999)); //随机code 验证签名用 * @param <type> $value
$sign = $this->keysign($ascdata, $addcode); * @return <type>
*/
$data = [ public function jiemi($value)
'server_id' => $this->user->server_id, {
'key' => $this->user->server_key, $iv = substr($this->user->des3key, 0, 8);
'addcode' => $addcode, $ret = openssl_decrypt($value, 'DES - EDE3 - CBC', $this->user->des3key, 0, $iv);
'sign' => $sign, if (false === $ret) {
'data' => $ascdata, return openssl_error_string();
]; }
return $data; return $ret;
} }
/** public function getMemoryUsage($precision = 2)
* 解密 {
* @param <type> $value $size = memory_get_usage(true);
* @return <type>
*/ $unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
public function jiemi($value)
{ return round($size / pow(1024, ($i = floor(log($size, 1024)))), $precision) . ' ' . $unit[$i];
$iv = substr($this->user->des3key, 0, 8); }
$ret = openssl_decrypt($value, 'DES - EDE3 - CBC', $this->user->des3key, 0, $iv);
if (false === $ret) { public function getElapsedTime(int $decimals = 2)
return openssl_error_string(); {
} return number_format(microtime(true) - request()->server('REQUEST_TIME_FLOAT'), $decimals) . ' s';
}
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';
}
}

View File

@@ -40,9 +40,9 @@ class Log extends Model
Schema::create($this->table, function (Blueprint $table) { Schema::create($this->table, function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('path', 255); $table->string('path', 255);
$table->string('method', 15)->index(); $table->string('method', 15);
$table->text('in_source'); $table->text('in_source');
$table->string('type', 20)->index(); $table->string('type', 20);
$table->text('out_source')->nullable(); $table->text('out_source')->nullable();
$table->timestamps(); $table->timestamps();
}); });

View File

@@ -1,8 +1,10 @@
<?php <?php
namespace App\Models; namespace App\Models;
class PinganToken extends Model class PinganToken extends Model
{ {
protected $dates = [ protected $dates = [
'get_token_time', 'get_token_time',
]; ];

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Models;
class UnionPayLog extends Model
{
protected $casts = [
'in_source' => 'array',
'out_source' => 'array',
];
}

View File

@@ -4,8 +4,10 @@ namespace App\Models;
class UserCode extends Model class UserCode extends Model
{ {
protected $casts = [ protected $casts = [
'codes' => 'array', 'codes' => 'array',
'profit' => 'array', 'profit' => 'array',
]; ];
} }

View File

@@ -14,7 +14,7 @@ class UserInfo extends Model
/** /**
* Notes: 获取性别的文字显示 * Notes: 获取性别的文字显示
* @Author: <C.Jason> * @Author: <C.Jason>
* @Date: 2019/9/12 09:46 * @Date : 2019/9/12 09:46
* @return string * @return string
*/ */
protected function getSexTextAttribute() protected function getSexTextAttribute()
@@ -35,7 +35,7 @@ class UserInfo extends Model
/** /**
* Notes: 处理默认头像 * Notes: 处理默认头像
* @Author: <C.Jason> * @Author: <C.Jason>
* @Date: 2019/9/12 13:44 * @Date : 2019/9/12 13:44
* @param $avatar * @param $avatar
* @return string * @return string
*/ */

View File

@@ -6,6 +6,6 @@ use App\Models\Traits\BelongsToUser;
class UserPingan extends Model class UserPingan extends Model
{ {
use BelongsToUser;
use BelongsToUser;
} }

View File

@@ -4,8 +4,10 @@ namespace App\Models;
class WoCouponLog extends Model class WoCouponLog extends Model
{ {
public function coupon() public function coupon()
{ {
return $this->belongsTo(WoCoupon::class, 'wo_coupon_id', 'id'); return $this->belongsTo(WoCoupon::class, 'wo_coupon_id', 'id');
} }
} }

View File

@@ -9,6 +9,7 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^7.2", "php": "^7.2",
"barryvdh/laravel-debugbar": "^3.4",
"encore/laravel-admin": "^1.8", "encore/laravel-admin": "^1.8",
"fideloper/proxy": "^4.0", "fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^7.0", "guzzlehttp/guzzle": "^7.0",
@@ -44,10 +45,12 @@
"App\\": "app/", "App\\": "app/",
"RuLong\\Bonus\\": "packages/bonus/src/", "RuLong\\Bonus\\": "packages/bonus/src/",
"RuLong\\Identity\\": "packages/identity/src/", "RuLong\\Identity\\": "packages/identity/src/",
"XuanChen\\Coupon\\": "packages/coupon/src/" "XuanChen\\Coupon\\": "packages/coupon/src/",
"XuanChen\\UnionPay\\": "packages/unionpay/src/"
}, },
"classmap": [ "classmap": [
"database/seeds", "database/seeds",
"database/migrations",
"database/factories" "database/factories"
] ]
}, },

View File

@@ -1,17 +1,59 @@
<?php <?php
return [ return [
'check' => [ 'check' => [
'self' => [ 'self' => [
'private' => storage_path('cert/self/private_rsa.pem'), 'private' => storage_path('cert/unionpay/self/private_rsa.pem'),
'public' => storage_path('cert/self/public_rsa.pem'), 'public' => storage_path('cert/unionpay/self/public_rsa.pem'),
], ],
'unionpay' => [ 'unionpay' => [
'public' => storage_path('cert/unionpay/public_rsa.pem'), 'public' => storage_path('cert/unionpay/public_rsa.pem'),
], ],
], ],
'fields' => [ 'regular' => [
'query' => [ '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' => [ 'in' => [
"msg_type" => "报文类型", "msg_type" => "报文类型",
"msg_txn_code" => "交易代码", "msg_txn_code" => "交易代码",
@@ -61,9 +103,10 @@ return [
"pos_ad" => "POS广告", "pos_ad" => "POS广告",
"pos_mkt_ad" => "Pos_营销联盟广告", "pos_mkt_ad" => "Pos_营销联盟广告",
"sign" => "签名域", "sign" => "签名域",
] ],
], ],
'freezecoupon' => [ //销账交易接口
'002100' => [
'in' => [ 'in' => [
"msg_type" => "报文类型", "msg_type" => "报文类型",
"msg_txn_code" => "交易代码", "msg_txn_code" => "交易代码",
@@ -125,7 +168,73 @@ return [
"mkt_sp_chnl_no" => "营销渠道号", "mkt_sp_chnl_no" => "营销渠道号",
"point_amt" => "积分抵扣金额", "point_amt" => "积分抵扣金额",
"sign" => "签名数据", "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" => "签名数据",
],
],
],
]; ];

View File

@@ -6,7 +6,7 @@ return [
'ysd' => [ 'ysd' => [
// 'pattern' => '/^YSD\d{12}/', // 'pattern' => '/^YSD\d{12}/',
'pattern' => '/^YSD/', 'pattern' => '/^YSD/',
'model' => \XuanChen\Coupon\Action\UnionPayAction::class, 'model' => \XuanChen\Coupon\Action\YsdAction::class,
], ],
'pingan' => [ 'pingan' => [
'pattern' => '/^\d{12}$/', 'pattern' => '/^\d{12}$/',

View File

@@ -9,7 +9,7 @@ return [
], ],
'ysd' => [ 'ysd' => [
'pattern' => '/^YSD/', 'pattern' => '/^YSD/',
'model' => \XuanChen\Coupon\Action\UnionPayAction::class, 'model' => \XuanChen\Coupon\Action\YsdAction::class,
], ],
], ],
]; ];

View File

@@ -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.
}
}

View File

@@ -1,205 +1,205 @@
<?php <?php
namespace XuanChen\Coupon\Action\pingan; namespace XuanChen\Coupon\Action\pingan;
use App\Models\PinganToken; use App\Models\PinganToken;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use XuanChen\Coupon\Action\Init; use XuanChen\Coupon\Action\Init;
/** /**
* 超市购物券 * 超市购物券
*/ */
class PingAnInit extends Init class PingAnInit extends Init
{ {
protected $this_type; protected $this_type;
protected $baseUri; protected $baseUri;
protected $tokenUri; protected $tokenUri;
protected $client_id; protected $client_id;
protected $grant_type; protected $grant_type;
protected $client_secret; protected $client_secret;
protected $access_token; protected $access_token;
protected $userName; protected $userName;
protected $error; protected $error;
protected $aes_code; //aes 密钥 protected $aes_code; //aes 密钥
protected $log;//日志 protected $log;//日志
public function __construct() public function __construct()
{ {
$this->this_type = config('pingan.this_type'); $this->this_type = config('pingan.this_type');
$pingan = config('pingan.' . $this->this_type); $pingan = config('pingan.' . $this->this_type);
$this->baseUri = $pingan['Uri']; $this->baseUri = $pingan['Uri'];
$this->tokenUri = $pingan['tokenUri']; $this->tokenUri = $pingan['tokenUri'];
$this->client_id = $pingan['client_id']; $this->client_id = $pingan['client_id'];
$this->grant_type = $pingan['grant_type']; $this->grant_type = $pingan['grant_type'];
$this->userName = $pingan['userName']; $this->userName = $pingan['userName'];
$this->client_secret = $pingan['client_secret']; $this->client_secret = $pingan['client_secret'];
$this->aes_code = $pingan['AES_CODE']; $this->aes_code = $pingan['AES_CODE'];
} }
/** /**
* 获取access_token * 获取access_token
* @return void [type] [description] * @return void [type] [description]
*/ */
public function getToken() public function getToken()
{ {
//从数据库里找token //从数据库里找token
$token = PinganToken::where('type', $this->this_type)->orderBy('id', 'desc')->first(); $token = PinganToken::where('type', $this->this_type)->orderBy('id', 'desc')->first();
if ($token) { if ($token) {
$access_token = $token->access_token; $access_token = $token->access_token;
$expires_in = $token->expires_in; $expires_in = $token->expires_in;
$get_token_time = $token->get_token_time; $get_token_time = $token->get_token_time;
$diffMinutes = $get_token_time->diffInMinutes(now(), false); $diffMinutes = $get_token_time->diffInMinutes(now(), false);
if ($diffMinutes < $expires_in) { if ($diffMinutes < $expires_in) {
$this->access_token = $access_token; $this->access_token = $access_token;
} else { } else {
$this->getAjaxToken(); $this->getAjaxToken();
} }
} else { } else {
$this->getAjaxToken(); $this->getAjaxToken();
} }
} }
/** /**
* 获取毫秒级别的时间戳 * 获取毫秒级别的时间戳
*/ */
public function getMsecTime() public function getMsecTime()
{ {
[$msec, $sec] = explode(' ', microtime()); [$msec, $sec] = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
$msectime = explode('.', $msectime); $msectime = explode('.', $msectime);
return $msectime[0]; return $msectime[0];
} }
/** /**
* 请求平台 access_token * 请求平台 access_token
* @return void [type] [description] * @return void [type] [description]
*/ */
public function getAjaxToken() public function getAjaxToken()
{ {
$params = [ $params = [
'client_id' => $this->client_id, 'client_id' => $this->client_id,
'grant_type' => $this->grant_type, 'grant_type' => $this->grant_type,
'client_secret' => $this->client_secret, 'client_secret' => $this->client_secret,
]; ];
try { try {
$log = $this->createLog($this->tokenUri, 'POST', $params, 'pingan'); $log = $this->createLog($this->tokenUri, 'POST', $params, 'pingan');
$client = new Client(); $client = new Client();
$response = $client->request('POST', $this->tokenUri, [ $response = $client->request('POST', $this->tokenUri, [
'form_params' => $params, 'form_params' => $params,
]); ]);
$body = $response->getBody(); $body = $response->getBody();
$content = $body->getContents(); $content = $body->getContents();
$result = json_decode($content, true); $result = json_decode($content, true);
$this->updateLog($log, $result); //更新日志 $this->updateLog($log, $result); //更新日志
if ($result['ret'] > 0) { if ($result['ret'] > 0) {
$this->error = $result['msg']; $this->error = $result['msg'];
} else { } else {
$data = $result['data']; $data = $result['data'];
PinganToken::create([ PinganToken::create([
'type' => $this->this_type, 'type' => $this->this_type,
'access_token' => $data['access_token'], 'access_token' => $data['access_token'],
'expires_in' => $data['expires_in'], 'expires_in' => $data['expires_in'],
'get_token_time' => now(), 'get_token_time' => now(),
]); ]);
$this->access_token = $data['access_token']; $this->access_token = $data['access_token'];
$this->error = ''; $this->error = '';
} }
} catch (RequestException $e) { } catch (RequestException $e) {
$this->error = $e->getMessage(); $this->error = $e->getMessage();
$this->updateLog($log, [$this->error]); //更新日志 $this->updateLog($log, [$this->error]); //更新日志
} }
} }
/** /**
* 通用获取数据接口 * 通用获取数据接口
* @param [type] $url 请求地址 * @param [type] $url 请求地址
* @param array $query 传递参数 * @param array $query 传递参数
* @param array $json 需要传的json数据 * @param array $json 需要传的json数据
* @param string $method 方式 * @param string $method 方式
* @return array|mixed [type] [description] * @return array|mixed [type] [description]
*/ */
public function getPingAnData($url, $query = [], $json = [], $method = 'POST') public function getPingAnData($url, $query = [], $json = [], $method = 'POST')
{ {
$this->getToken(); $this->getToken();
if ($this->error) { if ($this->error) {
return $this->error; return $this->error;
} }
$postData = [ $postData = [
'query' => array_merge([ 'query' => array_merge([
'access_token' => $this->access_token, 'access_token' => $this->access_token,
'request_id' => $this->getMsecTime(), 'request_id' => $this->getMsecTime(),
'userName' => $this->userName, 'userName' => $this->userName,
], $query), ], $query),
'json' => $json, 'json' => $json,
'headers' => [ 'headers' => [
'Content-Type' => 'application/json;charset=utf-8', 'Content-Type' => 'application/json;charset=utf-8',
'accept' => 'application/json;charset=utf-8', 'accept' => 'application/json;charset=utf-8',
], ],
]; ];
$log = $this->createLog($url, $method, $postData, 'pingan'); //日志 $log = $this->createLog($url, $method, $postData, 'pingan'); //日志
try { try {
$client = new Client(); $client = new Client();
$response = $client->request($method, $url, $postData); $response = $client->request($method, $url, $postData);
$body = $response->getBody(); $body = $response->getBody();
$content = $body->getContents(); $content = $body->getContents();
$result = json_decode($content, true); $result = json_decode($content, true);
if ($result['ret'] > 0) { if ($result['ret'] > 0) {
$retData = $result['msg']; $retData = $result['msg'];
} else { } else {
$retData = $result['data']; $retData = $result['data'];
} }
$this->updateLog($log, $retData);//更新日志 $this->updateLog($log, $retData);//更新日志
return $retData; return $retData;
} catch (RequestException $e) { } catch (RequestException $e) {
$this->updateLog($log, [$e->getMessage()]);//更新日志 $this->updateLog($log, [$e->getMessage()]);//更新日志
return ['ret' => '99999', $e->getMessage()]; return ['ret' => '99999', $e->getMessage()];
} }
} }
//加密 //加密
public function encrypt($str) public function encrypt($str)
{ {
if (is_array($str)) { if (is_array($str)) {
$str = json_encode($str); $str = json_encode($str);
} }
$data = openssl_encrypt($str, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA); $data = openssl_encrypt($str, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
return base64_encode($data); return base64_encode($data);
} }
//解密 //解密
public function decrypt($str) public function decrypt($str)
{ {
$encrypted = base64_decode($str); $encrypted = base64_decode($str);
return openssl_decrypt($encrypted, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA); return openssl_decrypt($encrypted, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
} }
} }

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -1,144 +1,144 @@
<?php <?php
namespace XuanChen\Coupon; namespace XuanChen\Coupon;
use App\Models\Activity; use App\Models\Activity;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
/** /**
* 自有卡券系统 * 自有卡券系统
*/ */
class Coupon class Coupon
{ {
/** /**
* Notes: 发券接口 * Notes: 发券接口
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/6/28 15:07 * @Date : 2020/6/28 15:07
* @param $activityId 活动编号 * @param $activityId 活动编号
* @param $outletId 网点编号 * @param $outletId 网点编号
* @param $mobile 手机号 * @param $mobile 手机号
*/ */
public static function Grant($activityId, $outletId, $mobile) public static function Grant($activityId, $outletId, $mobile)
{ {
$model = config('xuanchen_coupon.rules.ysd.model'); $model = config('xuanchen_coupon.rules.ysd.model');
return (new $model)->setActivityId($activityId) return (new $model)->setActivityId($activityId)
->setOutletId($outletId) ->setOutletId($outletId)
->setMobile($mobile) ->setMobile($mobile)
->grant(); ->grant();
} }
/** /**
* Notes: 查询接口 * Notes: 查询接口
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/7/21 11:58 * @Date : 2020/7/21 11:58
* @param $redemptionCode * @param $redemptionCode
*/ */
public static function Query($redemptionCode, $outletId) public static function Query($redemptionCode, $outletId)
{ {
if (!$redemptionCode) { if (!$redemptionCode) {
return '查询失败,未获取到券码'; return '查询失败,未获取到券码';
} }
$model = self::getModelByCode($redemptionCode); $model = self::getModelByCode($redemptionCode);
if (is_string($model)) { if (is_string($model)) {
return $model; return $model;
} }
return $model->setCode($redemptionCode) return $model->setCode($redemptionCode)
->setOutletId($outletId) ->setOutletId($outletId)
->detail(); ->detail();
} }
/** /**
* Notes: 卡券作废 * Notes: 卡券作废
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/9/2 16:54 * @Date : 2020/9/2 16:54
* @param $redemptionCode * @param $redemptionCode
* @param $outletId * @param $outletId
* @return string * @return string
*/ */
public static function Destroy($redemptionCode, $outletId) public static function Destroy($redemptionCode, $outletId)
{ {
try { try {
$model = self::getModelByCode($redemptionCode); $model = self::getModelByCode($redemptionCode);
if (is_string($model)) { if (is_string($model)) {
return $model; return $model;
} }
return $model->setCode($redemptionCode) return $model->setCode($redemptionCode)
->setOutletId($outletId) ->setOutletId($outletId)
->destroy(); ->destroy();
} catch (\Exception $e) { } catch (\Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
} }
/** /**
* Notes: 根据券码 获取class * Notes: 根据券码 获取class
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/7/21 12:00 * @Date : 2020/7/21 12:00
* @param $code * @param $code
* @return string * @return string
*/ */
public static function getModelByCode($code) public static function getModelByCode($code)
{ {
$rules = config('xuanchen_coupon.rules'); $rules = config('xuanchen_coupon.rules');
if (!$rules) { if (!$rules) {
return '系统出错,未找到配置文件'; return '系统出错,未找到配置文件';
} }
$model = ''; $model = '';
foreach ($rules as $rule) { foreach ($rules as $rule) {
if (preg_match($rule['pattern'], $code, $matches)) { if (preg_match($rule['pattern'], $code, $matches)) {
$model = $rule['model']; $model = $rule['model'];
break; break;
} }
} }
if (!$model) { if (!$model) {
throw new \Exception('卡券核销失败。未查到卡券所属'); throw new \Exception('卡券核销失败。未查到卡券所属');
} }
return new $model; return new $model;
} }
/** /**
* Notes: description * Notes: description
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/8/21 13:33 * @Date : 2020/8/21 13:33
* @param \App\Models\User $user 渠道 * @param \App\Models\User $user 渠道
* @param string $redemptionCode 要核销的券码 * @param string $redemptionCode 要核销的券码
* @param float $total 订单金额 * @param float $total 订单金额
* @param string $outletId 网点id * @param string $outletId 网点id
* @param string $orderid 订单id * @param string $orderid 订单id
* @return string * @return string
*/ */
public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '') public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '')
{ {
try { try {
$model = self::getModelByCode($redemptionCode); $model = self::getModelByCode($redemptionCode);
if (is_string($model)) { if (is_string($model)) {
return $model; return $model;
} }
return $model->setUser($user) return $model->setUser($user)
->setCode($redemptionCode) ->setCode($redemptionCode)
->setTotal($total) ->setTotal($total)
->setOutletId($outletId) ->setOutletId($outletId)
->setOrderId($orderid) ->setOrderId($orderid)
->start(); ->start();
} catch (\Exception $e) { } catch (\Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
} }
} }

View 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');
}
}

View File

@@ -1,47 +1,47 @@
<?php <?php
namespace XuanChen\Coupon\Traits; namespace XuanChen\Coupon\Traits;
use App\Models\Log as LogModel; use App\Models\Log as LogModel;
trait Log trait Log
{ {
/** /**
* Notes: 插入日志 * Notes: 插入日志
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/6/30 10:29 * @Date : 2020/6/30 10:29
* @param $url * @param $url
* @param $method * @param $method
* @param $params * @param $params
* @param string $type * @param string $type
* @return mixed * @return mixed
*/ */
public function createLog($url, $method, $params, $type = 'pingan') public function createLog($url, $method, $params, $type = 'pingan')
{ {
$data = [ $data = [
'path' => $url, 'path' => $url,
'method' => $method, 'method' => $method,
'type' => $type, 'type' => $type,
'in_source' => $params, 'in_source' => $params,
]; ];
$info = LogModel::create($data); $info = LogModel::create($data);
return $info; return $info;
} }
/** /**
* Notes: 更新日志 * Notes: 更新日志
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/6/30 10:29 * @Date : 2020/6/30 10:29
* @param $log * @param $log
* @param $params * @param $params
*/ */
public static function updateLog($log, $params) public static function updateLog($log, $params)
{ {
$log->out_source = $params; $log->out_source = $params;
$log->save(); $log->save();
} }
} }

View File

@@ -9,7 +9,7 @@ return [
], ],
'ysd' => [ 'ysd' => [
'pattern' => '/^YSD/', 'pattern' => '/^YSD/',
'model' => \XuanChen\Coupon\Action\UnionPayAction::class, 'model' => \XuanChen\Coupon\Action\SinopecAction::class,
], ],
], ],
]; ];

View File

@@ -2,10 +2,13 @@
namespace XuanChen\UnionPay\Action; namespace XuanChen\UnionPay\Action;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class Init class Init
{ {
public $params;
public $sign;
/** /**
* RSA验签 * RSA验签
@@ -14,15 +17,16 @@ class Init
* @param $sign 要校对的的签名结果 * @param $sign 要校对的的签名结果
* return 验证结果 * return 验证结果
*/ */
public function rsaSign($params, $self = false) public function checkSign($self = false)
{ {
$sign = $params['sign']; $sign = $this->sign;
unset($params['sign']); $sign = base64_decode($sign);
$public_key = $this->getPublic($self); $public_key = $this->getPublic($self);
$pub_key_id = openssl_get_publickey($public_key); $pub_key_id = openssl_get_publickey($public_key);
$signStr = $this->getSignString($params); $signStr = $this->getSignString($this->params);
if ($pub_key_id) { if ($pub_key_id) {
$result = (bool)openssl_verify($signStr, $sign, $pub_key_id); $result = (bool)openssl_verify($signStr, $sign, $pub_key_id);
@@ -34,14 +38,36 @@ class Init
return $result; 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 参数数组 * @param array $params 参数数组
* @return string * @return string
*/ */
public function getSignString($params) public function getSignString()
{ {
$params = array_filter($params); $params = array_filter($this->params);
ksort($params); ksort($params);
$signStr = http_build_query($params); $signStr = http_build_query($params);
return $signStr; return $signStr;
@@ -51,6 +77,11 @@ class Init
public function getPrivate() public function getPrivate()
{ {
$private = config('unionpay.check.self.private'); $private = config('unionpay.check.self.private');
if (!file_exists($private)) {
throw new \Exception('缺少私钥文件');
}
return file_get_contents($private); return file_get_contents($private);
} }

View File

@@ -3,14 +3,20 @@
namespace XuanChen\UnionPay; namespace XuanChen\UnionPay;
use App\Models\User; 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: 查询接口 * Notes: 查询接口
* @Author: 玄尘 * @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);
}
} }