fix: 调整微信V3提现操作

This commit is contained in:
邹景立 2024-08-05 22:40:16 +08:00
parent 6592853773
commit 554da60286

View File

@ -55,20 +55,17 @@ class Trans extends Command
*/ */
protected function execute(Input $input, Output $output) 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')]; [$total, $count, $error, $changeNow] = [(clone $model)->count(), 0, 0, date('Y-m-d H:i:s')];
/** @var PluginWemallUserTransfer $item */ /** @var PluginWemallUserTransfer $item */
foreach ((clone $model)->cursor() as $model) try { foreach ((clone $model)->cursor() as $model) try {
$this->queue->message($total, ++$count, sprintf('开始处理订单 %s 提现', $model->getAttr('code'))); $this->queue->message($total, ++$count, sprintf('开始处理订单 %s 提现', $model->getAttr('code')));
if ($model->getAttr('status') === 3) { if ($model->getAttr('status') === 3) {
$this->queue->message($total, $count, sprintf('尝试处理订单 %s 打款', $model->getAttr('code')), 1); $this->queue->message($total, $count, sprintf('尝试处理订单 %s 打款', $model->getAttr('code')), 1);
if ($model->getAttr('type') === 'wechat_banks') {
$result = $this->createTransferBank($model); $result = $this->createTransferV3($model);
} else { p($result, false, 'transfer.params');
// $result = $this->createTransferWallet($model);
$result = $this->createTransferV3($model);
p($result, false, 'transfer.params');
}
if (isset($result['code']) && in_array($result['code'], ['PARM_ERROR', 'INVALID_REOUEST'])) { if (isset($result['code']) && in_array($result['code'], ['PARM_ERROR', 'INVALID_REOUEST'])) {
$model->save(['change_time' => $changeNow, 'change_desc' => $result['message'] ?? '发起提现参数错误!']); $model->save(['change_time' => $changeNow, 'change_desc' => $result['message'] ?? '发起提现参数错误!']);
} elseif (isset($result['batch_id'])) { } elseif (isset($result['batch_id'])) {
@ -79,14 +76,6 @@ class Trans extends Command
'change_time' => $changeNow, 'change_time' => $changeNow,
'change_desc' => '创建微信提现成功', '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 { } else {
$model->save([ $model->save([
'change_time' => $changeNow, 'change_time' => $changeNow,
@ -95,8 +84,7 @@ class Trans extends Command
} }
} elseif ($model->getAttr('status') === 4) { } elseif ($model->getAttr('status') === 4) {
$this->queue->message($total, $count, sprintf('刷新提现订单 %s 状态', $model->getAttr('code')), 1); $this->queue->message($total, $count, sprintf('刷新提现订单 %s 状态', $model->getAttr('code')), 1);
// $model->getAttr('type') === 'wechat_banks' ? $this->queryTransferBank($model) : $this->queryTransferWallet($model); $this->queryTransferV3($model);
$model->getAttr('type') === 'wechat_banks' ? $this->queryTransferBank($model) : $this->queryTransferV3($model);
} }
} catch (\Exception $exception) { } catch (\Exception $exception) {
$error++; $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接口提现打款状态 * 查询V3接口提现打款状态
* @param \plugin\wemall\model\PluginWemallUserTransfer $model * @param \plugin\wemall\model\PluginWemallUserTransfer $model
@ -189,10 +134,11 @@ class Trans extends Command
p($result, false, 'transfer.notify'); p($result, false, 'transfer.notify');
if (is_array($result) && isset($result['transfer_detail_list'])) { if (is_array($result) && isset($result['transfer_detail_list'])) {
foreach ($result['transfer_detail_list'] as $item) { foreach ($result['transfer_detail_list'] as $item) {
// 处理完成,直接完成操作
if ($item['detail_status'] === 'SUCCESS') { if ($item['detail_status'] === 'SUCCESS') {
$model->save([ $model->save([
'status' => 5, '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_time' => date('Y-m-d H:i:s'),
'change_desc' => '微信提现打款成功', 'change_desc' => '微信提现打款成功',
]); ]);
@ -205,7 +151,7 @@ class Trans extends Command
]; ];
$model->save([ $model->save([
'status' => 4, '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_time' => date('Y-m-d H:i:s'),
'change_desc' => $message[$item['detail_status']], '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 * @param PluginWemallUserTransfer $model
@ -296,14 +190,11 @@ class Trans extends Command
return [ return [
'appid' => $model->getAttr('appid'), 'appid' => $model->getAttr('appid'),
'mch_id' => $data['wechat_mch_id'], '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 证书配置 // V3 证书配置
'mch_v3_key' => $data['wechat_mch_key'],
'cert_private' => $local->path($file1, true), 'cert_private' => $local->path($file1, true),
'cert_public' => $local->path($file2, true), 'cert_public' => $local->path($file2, true),
// 设置缓存目录
'cache_path' => syspath('safefile/wechat'), 'cache_path' => syspath('safefile/wechat'),
]; ];
} }