diff --git a/app/Admin/Controllers/Activity/LogController.php b/app/Admin/Controllers/Activity/LogController.php index 1aa1883..e3bcaf7 100644 --- a/app/Admin/Controllers/Activity/LogController.php +++ b/app/Admin/Controllers/Activity/LogController.php @@ -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', '处理结果'); diff --git a/app/Api/Controllers/UnionPayController.php b/app/Api/Controllers/UnionPayController.php new file mode 100644 index 0000000..e328336 --- /dev/null +++ b/app/Api/Controllers/UnionPayController.php @@ -0,0 +1,56 @@ +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()); + } + + } + +} diff --git a/app/Api/Controllers/UserController.php b/app/Api/Controllers/UserController.php index dcc4981..0a2b73c 100644 --- a/app/Api/Controllers/UserController.php +++ b/app/Api/Controllers/UserController.php @@ -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); } diff --git a/app/Api/routes.php b/app/Api/routes.php index d3eee4e..1abd7f3 100644 --- a/app/Api/routes.php +++ b/app/Api/routes.php @@ -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'); + + }); diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php index 94eb6f9..d2c0292 100644 --- a/app/Http/Controllers/TestController.php +++ b/app/Http/Controllers/TestController.php @@ -1,251 +1,235 @@ -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 $value - * @return - */ - 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'; - } - -} +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 $value + * @return + */ + 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'; + } + +} diff --git a/app/Models/Log.php b/app/Models/Log.php index 7c11b33..761fff7 100644 --- a/app/Models/Log.php +++ b/app/Models/Log.php @@ -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(); }); diff --git a/app/Models/PinganToken.php b/app/Models/PinganToken.php index 8242885..37bafa9 100644 --- a/app/Models/PinganToken.php +++ b/app/Models/PinganToken.php @@ -1,8 +1,10 @@ 'array', + 'out_source' => 'array', + ]; + +} diff --git a/app/Models/UserCode.php b/app/Models/UserCode.php index eb16966..85c416e 100644 --- a/app/Models/UserCode.php +++ b/app/Models/UserCode.php @@ -4,8 +4,10 @@ namespace App\Models; class UserCode extends Model { + protected $casts = [ 'codes' => 'array', 'profit' => 'array', ]; + } diff --git a/app/Models/UserInfo.php b/app/Models/UserInfo.php index 9e201dd..f214054 100644 --- a/app/Models/UserInfo.php +++ b/app/Models/UserInfo.php @@ -14,7 +14,7 @@ class UserInfo extends Model /** * Notes: 获取性别的文字显示 * @Author: - * @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: - * @Date: 2019/9/12 13:44 + * @Date : 2019/9/12 13:44 * @param $avatar * @return string */ diff --git a/app/Models/UserPingan.php b/app/Models/UserPingan.php index 174974d..4fc3271 100644 --- a/app/Models/UserPingan.php +++ b/app/Models/UserPingan.php @@ -6,6 +6,6 @@ use App\Models\Traits\BelongsToUser; class UserPingan extends Model { - use BelongsToUser; + use BelongsToUser; } diff --git a/app/Models/WoCouponLog.php b/app/Models/WoCouponLog.php index f0962c9..688080d 100644 --- a/app/Models/WoCouponLog.php +++ b/app/Models/WoCouponLog.php @@ -4,8 +4,10 @@ namespace App\Models; class WoCouponLog extends Model { + public function coupon() { return $this->belongsTo(WoCoupon::class, 'wo_coupon_id', 'id'); } + } diff --git a/composer.json b/composer.json index 6b160ab..73523b4 100644 --- a/composer.json +++ b/composer.json @@ -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" ] }, diff --git a/config/unionpay.php b/config/unionpay.php index 2398cd9..09ff420 100644 --- a/config/unionpay.php +++ b/config/unionpay.php @@ -1,17 +1,59 @@ [ + '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" => "签名数据", + ], + ], + + ], ]; diff --git a/config/xuanchen_coupon.php b/config/xuanchen_coupon.php index 1538da7..ed94d03 100644 --- a/config/xuanchen_coupon.php +++ b/config/xuanchen_coupon.php @@ -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}$/', diff --git a/packages/coupon/config/xuanchen_coupon.php b/packages/coupon/config/xuanchen_coupon.php index 16895ae..ee27158 100644 --- a/packages/coupon/config/xuanchen_coupon.php +++ b/packages/coupon/config/xuanchen_coupon.php @@ -9,7 +9,7 @@ return [ ], 'ysd' => [ 'pattern' => '/^YSD/', - 'model' => \XuanChen\Coupon\Action\UnionPayAction::class, + 'model' => \XuanChen\Coupon\Action\YsdAction::class, ], ], ]; diff --git a/packages/coupon/src/Action/SinopecAction.php b/packages/coupon/src/Action/SinopecAction.php deleted file mode 100644 index 333b51b..0000000 --- a/packages/coupon/src/Action/SinopecAction.php +++ /dev/null @@ -1,73 +0,0 @@ -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. - } -} \ No newline at end of file diff --git a/packages/coupon/src/Action/pingan/PingAnInit.php b/packages/coupon/src/Action/pingan/PingAnInit.php index 1065ac0..2ed7be9 100644 --- a/packages/coupon/src/Action/pingan/PingAnInit.php +++ b/packages/coupon/src/Action/pingan/PingAnInit.php @@ -1,205 +1,205 @@ -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); - } - -} +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); + } + +} diff --git a/packages/coupon/src/Action/sinopec/ZhyCreate.php b/packages/coupon/src/Action/sinopec/ZhyCreate.php deleted file mode 100644 index c599f77..0000000 --- a/packages/coupon/src/Action/sinopec/ZhyCreate.php +++ /dev/null @@ -1,81 +0,0 @@ - "", - "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(); - } - - } - -} \ No newline at end of file diff --git a/packages/coupon/src/Action/sinopec/ZhyQuery.php b/packages/coupon/src/Action/sinopec/ZhyQuery.php deleted file mode 100644 index 2692f0d..0000000 --- a/packages/coupon/src/Action/sinopec/ZhyQuery.php +++ /dev/null @@ -1,81 +0,0 @@ - "", - "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(); - } - - } - -} \ No newline at end of file diff --git a/packages/coupon/src/Coupon.php b/packages/coupon/src/Coupon.php index 6e716b5..db5cc97 100644 --- a/packages/coupon/src/Coupon.php +++ b/packages/coupon/src/Coupon.php @@ -1,144 +1,144 @@ -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(); - } - - } - -} +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(); + } + + } + +} diff --git a/packages/coupon/src/CouponServiceProvider.php b/packages/coupon/src/CouponServiceProvider.php new file mode 100644 index 0000000..cc39a11 --- /dev/null +++ b/packages/coupon/src/CouponServiceProvider.php @@ -0,0 +1,32 @@ +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'); + + } + +} diff --git a/packages/coupon/src/Traits/Log.php b/packages/coupon/src/Traits/Log.php index 3de425c..c8f8445 100644 --- a/packages/coupon/src/Traits/Log.php +++ b/packages/coupon/src/Traits/Log.php @@ -1,47 +1,47 @@ - $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(); - } - -} + $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(); + } + +} diff --git a/packages/sinopec/config/xuanchen_coupon.php b/packages/sinopec/config/xuanchen_coupon.php index 16895ae..18e09ae 100644 --- a/packages/sinopec/config/xuanchen_coupon.php +++ b/packages/sinopec/config/xuanchen_coupon.php @@ -9,7 +9,7 @@ return [ ], 'ysd' => [ 'pattern' => '/^YSD/', - 'model' => \XuanChen\Coupon\Action\UnionPayAction::class, + 'model' => \XuanChen\Coupon\Action\SinopecAction::class, ], ], ]; diff --git a/packages/unionpay/src/Action/Init.php b/packages/unionpay/src/Action/Init.php index a0a2761..13a5e2b 100644 --- a/packages/unionpay/src/Action/Init.php +++ b/packages/unionpay/src/Action/Init.php @@ -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); } diff --git a/packages/unionpay/src/UnionPay.php b/packages/unionpay/src/UnionPay.php index bdaaff5..8048f9f 100644 --- a/packages/unionpay/src/UnionPay.php +++ b/packages/unionpay/src/UnionPay.php @@ -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); - } - }