阶段更新

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

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

View File

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

View File

@@ -3,53 +3,37 @@
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;
use XuanChen\Coupon\Coupon;
class TestController
{
use ApiResponse;
public $baseUrl = 'http://pa.ysd-bs.com/api/V1/';
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(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;
$user_id = $request->user_id;
$data = $request->data;
$this->user = User::find(3);
return $this->success($ret);
$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);
$this->user = User::find(215);
$ret = [
'redemptionCode' => '951951858070',
'total' => 5,
'outletId' => '2008241014458',
'outletId' => '2006151433887',
];
return $this->success($ret);
@@ -179,7 +163,7 @@ class TestController
$total = $request->total;
$outletId = $request->outletId;
$orderid = $request->orderid ?? '';
$res = UnionPay::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid);
$res = Coupon::Redemption($this->user, $redemptionCode, $total, $outletId, $orderid);
if (is_string($res)) {
return $this->error($res);
@@ -234,7 +218,7 @@ class TestController
return $ret;
}
function getMemoryUsage($precision = 2)
public function getMemoryUsage($precision = 2)
{
$size = memory_get_usage(true);
@@ -243,7 +227,7 @@ class TestController
return round($size / pow(1024, ($i = floor(log($size, 1024)))), $precision) . ' ' . $unit[$i];
}
function getElapsedTime(int $decimals = 2)
public 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) {
$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();
});

View File

@@ -1,8 +1,10 @@
<?php
namespace App\Models;
class PinganToken extends Model
{
protected $dates = [
'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
{
protected $casts = [
'codes' => 'array',
'profit' => 'array',
];
}

View File

@@ -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
*/

View File

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

View File

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

View File

@@ -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"
]
},

View File

@@ -3,15 +3,57 @@
return [
'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'),
],
],
'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' => [
'query' => [
//聚合营销优惠查询接口
'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" => "签名数据",
],
],
],
];

View File

@@ -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}$/',

View File

@@ -9,7 +9,7 @@ return [
],
'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,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

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

@@ -9,7 +9,7 @@ return [
],
'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;
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);
}

View File

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