diff --git a/app/Api/Controllers/UnionPayController.php b/app/Api/Controllers/UnionPayController.php index d6c9393..dba84d2 100644 --- a/app/Api/Controllers/UnionPayController.php +++ b/app/Api/Controllers/UnionPayController.php @@ -37,16 +37,15 @@ class UnionPayController extends Controller { $inputs = $request->all(); - $sign = $inputs['sign']; - unset($inputs['sign']); - $action = new UnionPay($inputs, $sign); - $action->addLog(); - $action->start(); + $app = app('xuanchen.unionpay'); + $app->setParams($inputs); - $action->updateLog(); + $app->addLog(); + $app->start(); + $app->updateLog(); - return $action->respond(); + return $app->respond(); } diff --git a/composer.json b/composer.json index 5e45612..9ed1b52 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "php-parallel-lint/php-console-color": "^0.3.0", "php-parallel-lint/php-console-highlighter": "^0.5.0", "predis/predis": "^1.1", - "simplesoftwareio/simple-qrcode": "^2.0" + "simplesoftwareio/simple-qrcode": "^2.0", + "xuanchen/unionpay": "^1.0" }, "require-dev": { "facade/ignition": "^1.4", @@ -47,7 +48,6 @@ "RuLong\\Bonus\\": "packages/bonus/src/", "RuLong\\Identity\\": "packages/identity/src/", "XuanChen\\Coupon\\": "packages/xuanchen/coupon/src/", - "XuanChen\\UnionPay\\": "packages/xuanchen/unionpay/src/", "XuanChen\\Sinopec\\": "packages/xuanchen/sinopec/src/" }, "classmap": [ diff --git a/config/unionpay.php b/config/unionpay.php deleted file mode 100644 index 9b60a02..0000000 --- a/config/unionpay.php +++ /dev/null @@ -1,339 +0,0 @@ - '660134', - //打印在小票上,由活动标题、优惠金额、原始金额组合而成 - 'pos_receipt' => '本时生活,优惠生活', - //广告,用于打印在小票上 - 'pos_ad' => '', - //营销联盟广告,用于打印在小票上 - 'pos_mkt_ad' => '本时生活,优惠生活', - //银联渠道id - 'agent_id' => '299', - //银联网点id - 'outlet_id' => '2009300919918', - //用于银商与sp分润的金额(是佣金的一部分), 以分为单位 - 'serv_chg' => 0, - //佣金 - 'commission' => 0, - //证书 - 'check' => [ - 'self' => [ - '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'), - ], - ], - 'type' => [ - '002025' => '查询', - '002100' => '交易', - '002101' => '冲正', - '002102' => '撤销', - ], - 'log_type' => [ - '002025' => 'query', - '002100' => 'freezecoupon', - '002101' => 'reversal', - '002102' => 'annul', - ], - //需要校验的数据 - 'validator' => [ - '002025' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - "msg_flg", - "msg_sender", - "msg_time", - "msg_ver", - "msg_sys_sn", - "req_serial_no", - "mkt_code", - "amount", - "avl_amt", - ], - '002100' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - "msg_flg", - "msg_sender", - "msg_time", - "msg_sys_sn", - "msg_ver", - "req_serial_no", - "orig_req_serial_no", - "sett_date", - "txn_date", - "txn_time", - "orig_amt", - "discount_amt", - ], - '002101' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - "msg_flg", - "msg_sender", - "msg_time", - "msg_sys_sn", - "msg_ver", - "req_serial_no", - "orig_req_serial_no", - ], - '002102' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - "msg_flg", - "msg_sender", - "msg_time", - "msg_sys_sn", - "msg_ver", - "req_serial_no", - "orig_req_serial_no", - ], - ], - //入库基础数据 - 'regular' => [ - '002025' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - // "msg_flg", - "msg_sender", - "msg_time", - "msg_ver", - "msg_sys_sn",//自己添加的基础数据 - "req_serial_no",//自己添加的基础数据 - "mkt_code",//自己添加的基础数据 - ], - '002100' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - // "msg_flg", - "msg_sender", - "msg_time", - "msg_sys_sn", - "msg_ver", - "req_serial_no",//自己添加的基础数据 - "orig_req_serial_no",//自己添加的基础数据 - "sett_date",//自己添加的基础数据 - ], - '002101' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - // "msg_flg", - "msg_sender", - "msg_time", - "msg_sys_sn", - "msg_ver", - "req_serial_no",//自己添加的基础数据 - "orig_req_serial_no",//自己添加的基础数据 - ], - '002102' => [ - "msg_type", - "msg_txn_code", - "msg_crrltn_id", - // "msg_flg", - "msg_sender", - "msg_time", - "msg_sys_sn", - "msg_ver", - "req_serial_no",//自己添加的基础数据 - "orig_req_serial_no",//自己添加的基础数据 - ], - ], - 'fields' => [ - //聚合营销优惠查询接口 - '002025' => [ - 'in' => [ - "msg_type" => "报文类型", - "msg_txn_code" => "交易代码", - "msg_crrltn_id" => "报文流水号", - "msg_flg" => "报文请求应答标志", - "msg_sender" => "报文发送方", - "msg_time" => "报文日期", - "msg_sys_sn" => "平台流水号", - "msg_ver" => "报文版本号", - "req_serial_no" => "查询流水号", - "shop_no" => "门店号", - "term_no" => "受理终端号", - "service_code" => "受理方式", - "voucher_no" => "受理凭证号", - "mkt_code" => "聚合营销码", - "mkt_mode" => "聚合营销类型", - "embedded_mchnt_no" => "发起渠道商户号", - "currency_code" => "货币代码", - "amount" => "消费金额", - "avl_amt" => "可优惠金额", - "term_sp_chnl_no" => "终端指定SP渠道号", - "func_code" => "功能码", - "times" => "次数", - "pay_mode" => "支付方式", - //用户附加信息 - "user_ext_info" => [ - "mobile_no" => "手机号", - "user_code" => "用户号", - "user_code_type" => "用户号类型", - "dev_id" => "设备id", - ], - "sign" => "签名域", - ], - 'out' => [ - "msg_type" => "报文类型", - "msg_txn_code" => "交易代码", - "msg_crrltn_id" => "报文流水号", - "msg_flg" => "报文请求应答标志", - "msg_sender" => "报文发送方", - "msg_time" => "报文日期", - "msg_sys_sn" => "平台流水号", - "msg_rsp_code" => "响应码", - "msg_rsp_desc" => "响应码描述", - "discount" => "折扣金额", - "actual_amt" => "折后应收金额", - "pos_display" => "POS显示", - "pos_receipt" => "POS小票", - "pos_ad" => "POS广告", - "pos_mkt_ad" => "Pos_营销联盟广告", - "sign" => "签名域", - ], - ], - //销账交易接口 - '002100' => [ - '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" => "原查询流水号", - "enc_card_no" => "加密卡号", - "part_card_no" => "部分卡号", - "acq_term_sn" => "受理终端流水号", - "refer_no" => "检索参考号", - "sett_date" => "清算日期", - "txn_date" => "交易日期", - "txn_time" => "交易时间", - "orig_amt" => "原始金额", - "discount_amt" => "优惠的金额", - "pay_amt" => "支付金额", - "pay_mode" => "支付方式", - "order_no" => "订单号", - "trans_crrltn_no" => "交易关联流水号", - "equity_no" => "权益号", - "card_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" => "响应码描述", - "orig_amt" => "原始金额", - "discount_amt" => "折扣金额", - "pay_amt" => "支付金额", - "serv_chg" => "服务费", - "commission" => "佣金", - "ad" => "广告", - "pos_receipt" => "POS优惠", - "coupon_no" => "凭证号", - "coupon_type" => "凭证类型", - "sp_biz_code" => "SP统计码", - "charge_code" => "计费码", - "pos_event_title" => "SP活动主题", - "sp_contact" => "SP联系电话", - "sp_name" => "SP名称", - "event_no" => "活动号", - "td_code" => "二维码", - "memo" => "附言", - "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/packages/xuanchen/coupon/composer.json b/packages/xuanchen/coupon/composer.json index fb4ce19..7338fa5 100644 --- a/packages/xuanchen/coupon/composer.json +++ b/packages/xuanchen/coupon/composer.json @@ -11,11 +11,11 @@ ], "require": { "php": ">=7.1.3", - "../../../vendor/laravel/framework": "*" + "laravel/framework": "*" }, "autoload": { "psr-0": { - "XuanChen\\Coupon": "src/" + "XuanChen\\Coupon\\": "src/" } }, "extra": { diff --git a/packages/xuanchen/coupon/src/Action/ysd/YsdGrant.php b/packages/xuanchen/coupon/src/Action/ysd/YsdGrant.php index c414d2d..509eefb 100644 --- a/packages/xuanchen/coupon/src/Action/ysd/YsdGrant.php +++ b/packages/xuanchen/coupon/src/Action/ysd/YsdGrant.php @@ -22,7 +22,7 @@ class YsdGrant extends Init if (!$activity->status) { return '发券失败,活动已经关闭。'; } - + if ($activity->type == Activity::TYPE_SCOPE && Carbon::now()->gt($activity->end_at)) { return '发券失败,此活动已经结束。'; } diff --git a/packages/xuanchen/unionpay/.gitignore b/packages/xuanchen/unionpay/.gitignore new file mode 100644 index 0000000..c73cdc8 --- /dev/null +++ b/packages/xuanchen/unionpay/.gitignore @@ -0,0 +1,3 @@ +/.idea/ +/.git/ +/vendor diff --git a/packages/xuanchen/unionpay/README.md b/packages/xuanchen/unionpay/README.md index 7b0c93f..f8db1cb 100644 --- a/packages/xuanchen/unionpay/README.md +++ b/packages/xuanchen/unionpay/README.md @@ -8,4 +8,3 @@ 002102 销账撤销通知接口 -接口地址:http://pac.ysd-bs.com/api/V1/unionpay/query \ No newline at end of file diff --git a/packages/xuanchen/unionpay/composer.json b/packages/xuanchen/unionpay/composer.json index 6a49a84..fd48e91 100644 --- a/packages/xuanchen/unionpay/composer.json +++ b/packages/xuanchen/unionpay/composer.json @@ -1,6 +1,6 @@ { "name": "xuanchen/unionpay", - "description": "银联对接", + "description": "第三方银联对接", "license": "MIT", "authors": [ { @@ -13,8 +13,8 @@ "laravel/framework": "*" }, "autoload": { - "psr-0": { - "XuanChen\\UnionPay": "src/" + "psr-4": { + "XuanChen\\UnionPay\\": "src/" } }, "extra": { diff --git a/packages/xuanchen/unionpay/src/Action/Init.php b/packages/xuanchen/unionpay/src/Action/Init.php index ab32a85..ec8af27 100644 --- a/packages/xuanchen/unionpay/src/Action/Init.php +++ b/packages/xuanchen/unionpay/src/Action/Init.php @@ -2,7 +2,10 @@ namespace XuanChen\UnionPay\Action; +use App\Exceptions\ApiException; +use App\Exceptions\ApiUnionpayException; use App\Models\Log as LogModel; +use Illuminate\Http\Request; class Init { diff --git a/packages/xuanchen/unionpay/src/ServiceProvider.php b/packages/xuanchen/unionpay/src/ServiceProvider.php index 5828510..4dd4b93 100644 --- a/packages/xuanchen/unionpay/src/ServiceProvider.php +++ b/packages/xuanchen/unionpay/src/ServiceProvider.php @@ -13,10 +13,12 @@ class ServiceProvider extends LaravelServiceProvider */ public function register() { - info('323'); - if ($this->app->runningInConsole()) { - $this->publishes([__DIR__ . '/../config/unionpay.php' => config_path('unionpay.php')]); - } + $this->app->bind('xuanchen.unionpay', function ($app) { + $unionpay = new UnionPay(); + $unionpay->setConfig(); + + return $unionpay; + }); } /** @@ -25,7 +27,21 @@ class ServiceProvider extends LaravelServiceProvider */ public function boot() { - $this->mergeConfigFrom(__DIR__ . '/../config/unionpay.php', 'unionpay'); + $this->setConfig(); + } + + public function setConfig() + { + $path = __DIR__ . '/../config/unionpay.php'; + if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { + $this->publishes([ + $path => config_path('unionpay.php'), + ]); + } elseif ($this->app instanceof LumenApplication) { + $this->app->configure('unionpay'); + } + + $this->mergeConfigFrom($path, 'unionpay'); } diff --git a/packages/xuanchen/unionpay/src/UnionPay.php b/packages/xuanchen/unionpay/src/UnionPay.php index 79d9a0c..7b26031 100644 --- a/packages/xuanchen/unionpay/src/UnionPay.php +++ b/packages/xuanchen/unionpay/src/UnionPay.php @@ -3,10 +3,13 @@ namespace XuanChen\UnionPay; use App\Models\UnionpayLog; +use App\Models\User; use XuanChen\UnionPay\Action\Init; +use XuanChen\Coupon\Coupon; use XuanChen\UnionPay\Action\Query; use XuanChen\UnionPay\Action\Redemption; use XuanChen\UnionPay\Action\Reversal; +use XuanChen\UnionPay\Action\Skyxu; /** * 银联入口 @@ -15,20 +18,29 @@ class UnionPay extends Init { /** - * UnionPay constructor. - * @param $params - * @param string $sign + * Notes: 设置参数 + * @Author: 玄尘 + * @Date : 2020/11/10 10:45 + * @param $params */ - public function __construct($params, $sign = '') + public function setParams($params) { $this->params = $params; - $this->sign = $sign; + $this->sign = $params['sign']; $this->msg_txn_code = $params['msg_txn_code'] ?? ''; - $this->msg_sender = config('unionpay.msg_sender'); - $this->agent_id = config('unionpay.agent_id'); - $this->outlet_id = config('unionpay.outlet_id'); - $this->startMemory = round(memory_get_usage() / 1024 / 1024, 2); + } + /** + * Notes: 设置基础参数 + * @Author: 玄尘 + * @Date : 2020/11/10 10:46 + */ + public function setConfig() + { + $this->msg_sender = config('unionpay.msg_sender'); + $this->agent_id = config('unionpay.agent_id'); + $this->outlet_id = config('unionpay.outlet_id'); + $this->startMemory = round(memory_get_usage() / 1024 / 1024, 2); } /**