diff --git a/app/Command/MineCommand.php b/app/Command/MineCommand.php index deda981..4a7f386 100644 --- a/app/Command/MineCommand.php +++ b/app/Command/MineCommand.php @@ -49,7 +49,7 @@ class MineCommand extends HyperfCommand */ $paymentService = $this->container->make(PaymentService::class); - $params = $this->pay(); + $params = $this->payNew(); $data = $paymentService->payment($params); var_dump($data); return; @@ -268,4 +268,23 @@ class MineCommand extends HyperfCommand // echo json_encode($params); return $params; } + + public function payNew() + { + $params = [ + 'app_id' => '202304270000004', + 'timestamp' => time(), + 'nonce_str' => StringHelper::getRandomString(32), + 'data' => json_encode([ + 'outOrderNo' => time().rand(1000, 9999), + 'outMemberId' => 'T00001', + 'amount' => 100, + 'notifyUrl' => 'https://www.baidu.com', + ]), + ]; + $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); + $params['sign'] = $sign; + // echo json_encode($params); + return $params; + } } diff --git a/app/Controller/Payment/NotifyController.php b/app/Controller/Payment/NotifyController.php index d07d076..65e2082 100644 --- a/app/Controller/Payment/NotifyController.php +++ b/app/Controller/Payment/NotifyController.php @@ -57,7 +57,7 @@ class NotifyController extends AbstractController 'returnMsg' => '处理成功' ]; } - if ($order->status != Order::STATUS_WAIT_PAY) { + if ($order->status != Order::STATUS_WAIT_PAY && $order->status != Order::STATUS_FAILED) { return [ 'returnCode' => '0000', 'returnMsg' => '处理成功' diff --git a/app/Controller/Recharge/RechargeController.php b/app/Controller/Recharge/RechargeController.php index 244bebd..ca5e130 100644 --- a/app/Controller/Recharge/RechargeController.php +++ b/app/Controller/Recharge/RechargeController.php @@ -27,11 +27,12 @@ class RechargeController extends AbstractController public function getMemberInfo(RequestInterface $request) { [$app, $prePayLog] = $this->checkToken($request->input('stoken', '')); - $user = User::where('out_member_id', $prePayLog->out_member_id)->first(); + $outMemberId = $prePayLog->out_member_id; + $user = User::where('app_id', $app->app_id)->where('out_member_id', $outMemberId)->first(); $bankCard = null; $userInfo = null; if ($user) { - $bankCard = BankCard::where('member_id', $user->member_id)->where('status', BankCard::STATUS_ACTIVE)->first(); + $bankCard = BankCard::where('app_id', $app->app_id)->where('out_member_id', $outMemberId)->where('status', BankCard::STATUS_ACTIVE)->first(); $userInfo = [ 'name' => $user->real_name ?? '', 'cardNo' => $user->card_no ?? '', @@ -77,32 +78,35 @@ class RechargeController extends AbstractController if (empty($bankCardNo)) { throw new BusinessException('请输入银行卡号'); } - $memberId = $this->paymentService->generateMemberId($app->app_key, $cardNo); - $user = User::where('member_id', $memberId)->first(); + + $outMemberId = $prePayLog->out_member_id; + $user = User::where('app_id', $app->app_id)->where('out_member_id', $outMemberId)->first(); $bankCard = null; if ($user) { - if (empty($user->out_member_id)) { - $user->out_member_id = $prePayLog->out_member_id; - $user->save(); - } - $bankCard = BankCard::where('member_id', $user->member_id)->where('bank_card_no', $bankCardNo)->where('status', BankCard::STATUS_ACTIVE)->first(); + $bankCard = BankCard::where('app_id', $app->app_id) + ->where('out_member_id', $outMemberId) + ->where('bank_card_no', $bankCardNo) + ->where('status', BankCard::STATUS_ACTIVE)->first(); + $mobile = $user->mobile; + $cardNo = $user->cardNo; + $name = $user->real_name; } if ($bankCard) { $outOrderNo = $prePayLog->out_order_no; $nextStep = 'confirm-pay'; $amount = $prePayLog->amount > 0 ? $prePayLog->amount : intval($amount * 100); - $bizData = $this->paymentService->protocolPayPreRequest($this->buildPrepayParams($prePayLog->out_member_id, $outOrderNo, $bankCard->protocol, $amount, $prePayLog->notify_url, $app)); + $bizData = $this->paymentService->protocolPayPreRequest($this->buildPrepayParams($outMemberId, $outOrderNo, $bankCard->protocol, $amount, $prePayLog->notify_url, $app)); } else { $mchOrderNo = StringHelper::generateBankCardOrderNo(); $nextStep = 'confirm-bind'; $bizData = $this->paymentService->bindCard($this->buildBindCardParams( - $mchOrderNo, $prePayLog->out_member_id, $name, $cardNo, $mobile, $bankCardNo, $app + $mchOrderNo, $outMemberId, $name, $cardNo, $mobile, $bankCardNo, $app )); } return $this->success([ 'nextStep' => $nextStep, - 'outMemberId' => $prePayLog->out_member_id, + 'outMemberId' => $outMemberId, 'bizData' => $bizData ]); } @@ -313,6 +317,7 @@ class RechargeController extends AbstractController 'owx0tlx' => ['password' => 'lSoLW28NxtMlxUazC8p', 'app_id' => '202304270000004'], 'ioexlp2' => ['password' => 'wwU8Ir3Xp0rxXssA9NV', 'app_id' => '202305270000001'], 'lix73nxIN' => ['password' => 'a01@lWl3dfNmT', 'app_id' => '202306140000001'], + 'xtIxt2x3L' => ['password' => 'sd3@xxgNtxxJipOmT', 'app_id' => '202306200000001'], ]; return $users[$username] ?? null; } diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index 92c5a03..fd0d929 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -31,6 +31,10 @@ class PaymentService extends AbstractService return md5($appKey . '-' . $cardNo); } + public function generateMemberIdNew($appId, $outMemberId) { + return md5($appId . '-' . $outMemberId); + } + public function createOrder(App $app, array $params, $user) { $order = new Order(); $order->app_id = $app->app_id; @@ -145,11 +149,11 @@ class PaymentService extends AbstractService $app = $req->getApp(); $reqData = $req->getData(); - $memberId = $this->generateMemberId($app->app_key, $reqData['certificatesNo']); + $memberId = $this->generateMemberIdNew($app->app_id, $reqData['outMemberId']); $reqData['memberId'] = $memberId; $bankCard = BankCard::where('app_id', $app->app_id) - ->where('member_id', $memberId) + ->where('out_member_id', $reqData['outMemberId']) ->where('bank_card_no', $reqData['bankCardNo']) ->where('status', BankCard::STATUS_ACTIVE) ->first(); @@ -163,7 +167,7 @@ class PaymentService extends AbstractService throw new BusinessException($message == '支付渠道未配置' ? '暂不支持该银行卡' : $message); } - $user = User::where('member_id', $memberId)->first(); + $user = User::where('out_member_id', $reqData['outMemberId'])->where('app_id', $app->app_id)->first(); if (!$user) { $user = new User(); $user->member_id = $memberId; @@ -178,9 +182,6 @@ class PaymentService extends AbstractService $user->out_member_id = $reqData['outMemberId']; $user->save(); } - if ($user && $user->out_member_id && $user->out_member_id != $reqData['outMemberId']) { - throw new BusinessException('身份证号重复!'); - } $bankCard = new BankCard(); $bankCard->member_id = $memberId; $bankCard->out_member_id = $reqData['outMemberId']; @@ -282,7 +283,7 @@ class PaymentService extends AbstractService $app = $req->getApp(); $reqData = $req->getData(); $bankCard = BankCard::where('app_id', $app->app_id) - ->where('member_id', $reqData['memberId']) + ->where('out_member_id', $reqData['outMemberId']) ->where('protocol', $reqData['protocol']) ->where('status', BankCard::STATUS_ACTIVE) ->first(); diff --git a/public/payment.html b/public/payment.html index 86bc380..1d20723 100644 --- a/public/payment.html +++ b/public/payment.html @@ -15,13 +15,13 @@ - + - + - + @@ -99,6 +99,7 @@ outMemberId: '' }, payConfirmVisible: false, + hasUser: false, payConfirmForm: { stoken: '', smsCode: '', @@ -245,6 +246,7 @@ this.form.cardNo = data.user.cardNo; this.form.mobile = data.user.mobile; this.form.bankCardNo = data.user.bankCardNo; + this.hasUser = true; } console.log(data)