From 554da60286cefc4e842804746f0f2e81ad45f8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Mon, 5 Aug 2024 22:40:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=BE=AE=E4=BF=A1V3?= =?UTF-8?q?=E6=8F=90=E7=8E=B0=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think-plugs-wemall/src/command/Trans.php | 131 ++---------------- 1 file changed, 11 insertions(+), 120 deletions(-) diff --git a/plugin/think-plugs-wemall/src/command/Trans.php b/plugin/think-plugs-wemall/src/command/Trans.php index d2e4b97a5..80b51d138 100644 --- a/plugin/think-plugs-wemall/src/command/Trans.php +++ b/plugin/think-plugs-wemall/src/command/Trans.php @@ -55,20 +55,17 @@ class Trans extends Command */ protected function execute(Input $input, Output $output) { - $model = PluginWemallUserTransfer::mk()->where(['type' => ['wechat_banks', 'wechat_wallet'], 'status' => [3, 4]]); + $model = PluginWemallUserTransfer::mk()->where(['type' => 'wechat_wallet', 'status' => [3, 4]]); [$total, $count, $error, $changeNow] = [(clone $model)->count(), 0, 0, date('Y-m-d H:i:s')]; /** @var PluginWemallUserTransfer $item */ foreach ((clone $model)->cursor() as $model) try { $this->queue->message($total, ++$count, sprintf('开始处理订单 %s 提现', $model->getAttr('code'))); if ($model->getAttr('status') === 3) { $this->queue->message($total, $count, sprintf('尝试处理订单 %s 打款', $model->getAttr('code')), 1); - if ($model->getAttr('type') === 'wechat_banks') { - $result = $this->createTransferBank($model); - } else { - // $result = $this->createTransferWallet($model); - $result = $this->createTransferV3($model); - p($result, false, 'transfer.params'); - } + + $result = $this->createTransferV3($model); + p($result, false, 'transfer.params'); + if (isset($result['code']) && in_array($result['code'], ['PARM_ERROR', 'INVALID_REOUEST'])) { $model->save(['change_time' => $changeNow, 'change_desc' => $result['message'] ?? '发起提现参数错误!']); } elseif (isset($result['batch_id'])) { @@ -79,14 +76,6 @@ class Trans extends Command 'change_time' => $changeNow, 'change_desc' => '创建微信提现成功', ]); - } elseif ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { - $model->save([ - 'status' => 4, - 'trade_no' => $result['partner_trade_no'], - 'trade_time' => $result['payment_time'] ?? $changeNow, - 'change_time' => $changeNow, - 'change_desc' => '创建微信提现成功', - ]); } else { $model->save([ 'change_time' => $changeNow, @@ -95,8 +84,7 @@ class Trans extends Command } } elseif ($model->getAttr('status') === 4) { $this->queue->message($total, $count, sprintf('刷新提现订单 %s 状态', $model->getAttr('code')), 1); - // $model->getAttr('type') === 'wechat_banks' ? $this->queryTransferBank($model) : $this->queryTransferWallet($model); - $model->getAttr('type') === 'wechat_banks' ? $this->queryTransferBank($model) : $this->queryTransferV3($model); + $this->queryTransferV3($model); } } catch (\Exception $exception) { $error++; @@ -132,49 +120,6 @@ class Trans extends Command ]); } - /** - * 尝试提现转账到银行卡 - * @param PluginWemallUserTransfer $model - * @return array - * @throws \WeChat\Exceptions\InvalidDecryptException - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\admin\Exception - * @deprecated 微信已经不支持该接口 - */ - private function createTransferBank(PluginWemallUserTransfer $model): array - { - return TransfersBank::instance($this->getConfig($model))->create([ - 'partner_trade_no' => $model->getAttr('code'), - 'enc_bank_no' => $model->getAttr('bank_code'), - 'enc_true_name' => $model->getAttr('bank_user'), - 'bank_code' => $model->getAttr('bank_wseq'), - 'amount' => intval($model->getAttr('amount') - $model->getAttr('charge_amount')) * 100, - 'desc' => '微信银行卡提现', - ]); - } - - /** - * 尝试提现转账到微信钱包 - * @param PluginWemallUserTransfer $model - * @return array - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\admin\Exception - * @deprecated 微信已经不支持该接口 - */ - private function createTransferWallet(PluginWemallUserTransfer $model): array - { - return Transfers::instance($this->getConfig($model))->create([ - 'openid' => $model->getAttr('openid'), - 'amount' => intval($model->getAttr('amount') - $model->getAttr('charge_amount')) * 100, - 'partner_trade_no' => $model->getAttr('code'), - 'spbill_create_ip' => '127.0.0.1', - 'check_name' => 'NO_CHECK', - 'desc' => '微信余额提现!', - ]); - } - /** * 查询V3接口提现打款状态 * @param \plugin\wemall\model\PluginWemallUserTransfer $model @@ -189,10 +134,11 @@ class Trans extends Command p($result, false, 'transfer.notify'); if (is_array($result) && isset($result['transfer_detail_list'])) { foreach ($result['transfer_detail_list'] as $item) { + // 处理完成,直接完成操作 if ($item['detail_status'] === 'SUCCESS') { $model->save([ 'status' => 5, - 'trade_time' => date('Y-m-d H:i:s', strtotime($result['transfer_batch']['update_time'])), + 'trade_time' => date('Y-m-d H:i:s', strtotime($result['transfer_batch']['update_time'] ?? date('Y-m-d H:i:s'))), 'change_time' => date('Y-m-d H:i:s'), 'change_desc' => '微信提现打款成功', ]); @@ -205,7 +151,7 @@ class Trans extends Command ]; $model->save([ 'status' => 4, - 'trade_time' => date('Y-m-d H:i:s', strtotime($result['transfer_batch']['update_time'])), + 'trade_time' => date('Y-m-d H:i:s', strtotime($result['transfer_batch']['update_time'] ?? date('Y-m-d H:i:s'))), 'change_time' => date('Y-m-d H:i:s'), 'change_desc' => $message[$item['detail_status']], ]); @@ -222,58 +168,6 @@ class Trans extends Command } } - /** - * 查询更新提现打款状态 - * @param PluginWemallUserTransfer $model - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\admin\Exception - * @deprecated 微信已经不支持该接口 - */ - private function queryTransferBank(PluginWemallUserTransfer $model) - { - $result = TransfersBank::instance($this->getConfig($model))->query($model->getAttr('trade_no')); - if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { - if ($result['status'] === 'SUCCESS') { - $model->save([ - 'status' => 5, - 'trade_time' => $result['pay_succ_time'] ?: date('Y-m-d H:i:s'), - 'change_time' => date('Y-m-d H:i:s'), - 'change_desc' => '微信提现打款成功', - ]); - } elseif (in_array($result['status'], ['FAILED', 'BANK_FAIL'])) { - $model->save([ - 'status' => 0, - 'change_time' => date('Y-m-d H:i:s'), - 'change_desc' => '微信提现打款失败', - ]); - // 刷新用户可提现余额 - UserRebate::recount($model->getAttr('unid')); - } - } - } - - /** - * 查询更新提现打款状态 - * @param PluginWemallUserTransfer $model - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\admin\Exception - * @deprecated 微信已经不支持该接口 - */ - private function queryTransferWallet(PluginWemallUserTransfer $model) - { - $result = Transfers::instance($this->getConfig($model))->query($model->getAttr('trade_no')); - if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { - $model->save([ - 'status' => 5, - 'trade_time' => $result['payment_time'], - 'change_time' => date('Y-m-d H:i:s'), - 'change_desc' => '微信提现打款成功!', - ]); - } - } - /** * 获取微信提现参数 * @param PluginWemallUserTransfer $model @@ -296,14 +190,11 @@ class Trans extends Command return [ 'appid' => $model->getAttr('appid'), 'mch_id' => $data['wechat_mch_id'], - 'mch_key' => $data['wechat_mch_key'], - 'mch_v3_key' => $data['wechat_mch_key'], - // V2 证书配置 - 'ssl_key' => $local->path($file1, true), - 'ssl_cer' => $local->path($file2, true), // V3 证书配置 + 'mch_v3_key' => $data['wechat_mch_key'], 'cert_private' => $local->path($file1, true), 'cert_public' => $local->path($file2, true), + // 设置缓存目录 'cache_path' => syspath('safefile/wechat'), ]; }