转账功能优化
This commit is contained in:
@@ -161,13 +161,8 @@ class EasyWeChatService
|
||||
'transfer_remark' => mb_substr($desc, 0, 32), // 最多 32 字符
|
||||
//授权转账:以授权单定位收款人,不再传 openid
|
||||
'out_authorization_no' => $out_authorization_no,
|
||||
//必须传转账场景报备信息,需按商户平台申请的场景准确填写
|
||||
'transfer_scene_report_infos' => [
|
||||
[
|
||||
'info_type' => '活动名称',
|
||||
'info_content' => mb_substr($desc ?: '佣金报酬', 0, 32),
|
||||
],
|
||||
],
|
||||
//转账场景报备信息:必须与 transfer_scene_id 对应(1005=佣金报酬 需传「岗位类型」「报酬说明」两条)
|
||||
'transfer_scene_report_infos' => $this->buildTransferSceneReportInfos($desc),
|
||||
];
|
||||
//规则:转账金额 >= 2,000 元时必须传入收款人姓名(加密)
|
||||
if ($amount >= 2000 && $name !== '') {
|
||||
@@ -256,6 +251,72 @@ class EasyWeChatService
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造转账场景报备信息
|
||||
* 报备信息必须与 transfer_scene_id 一一对应,且 info_type 不可重复,否则接口会报
|
||||
* 「未传入完整且对应的转账场景报备信息」:
|
||||
* 1000 现金营销 -> 活动名称 + 奖励说明
|
||||
* 1005 佣金报酬 -> 岗位类型 + 报酬说明
|
||||
* 可通过 extra/common.php 的 transfer_scene_report_infos 覆盖
|
||||
* @param string $desc 转账备注,用于 info_content 缺省时兜底
|
||||
* @return array
|
||||
*/
|
||||
private function buildTransferSceneReportInfos(string $desc = ''): array
|
||||
{
|
||||
$reportInfos = $this->config['transfer_scene_report_infos'] ?? [];
|
||||
if (!$reportInfos) {
|
||||
$sceneId = (string)($this->config['transfer_scene_id'] ?? '1005');
|
||||
$reportInfos = $sceneId === '1000'
|
||||
? [
|
||||
['info_type' => '活动名称', 'info_content' => $desc ?: '平台活动'],
|
||||
['info_type' => '奖励说明', 'info_content' => $desc ?: '活动奖励'],
|
||||
]
|
||||
: [
|
||||
['info_type' => '岗位类型', 'info_content' => '平台接单用户'],
|
||||
['info_type' => '报酬说明', 'info_content' => $desc ?: '用户提现'],
|
||||
];
|
||||
}
|
||||
|
||||
//info_type ≤15 字符、info_content ≤32 字符
|
||||
return array_map(function ($item) use ($desc) {
|
||||
$infoType = mb_substr((string)($item['info_type'] ?? ''), 0, 15);
|
||||
$infoContent = mb_substr((string)($item['info_content'] ?? ''), 0, 32);
|
||||
if ($infoContent === '') {
|
||||
$infoContent = mb_substr($desc ?: '佣金报酬', 0, 32);
|
||||
}
|
||||
|
||||
return [
|
||||
'info_type' => $infoType,
|
||||
'info_content' => $infoContent,
|
||||
];
|
||||
}, $reportInfos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询免确认收款授权单(用于同步授权状态:授权回调丢失时以微信侧状态为准)
|
||||
* 接口:GET /v3/fund-app/mch-transfer/user-confirm-authorization/out-authorization-no/{no}
|
||||
* 文档:https://pay.weixin.qq.com/doc/v3/merchant/4015901167
|
||||
* @param string $out_authorization_no 商户侧授权单号
|
||||
* @return array {out_authorization_no, authorization_id, state, ...};失败时含 message
|
||||
*/
|
||||
public function queryTransferAuthorization($out_authorization_no)
|
||||
{
|
||||
try {
|
||||
$response = $this->payApp->getClient()->get(
|
||||
'v3/fund-app/mch-transfer/user-confirm-authorization/out-authorization-no/' . $out_authorization_no
|
||||
);
|
||||
$res = $response->toArray(false);
|
||||
Log::info('查询免确认收款授权-res' . json_encode($res, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('查询免确认收款授权异常:' . $e->getMessage());
|
||||
return [
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询新版商家转账单状态
|
||||
* @param string $out_bill_no 商户单号
|
||||
|
||||
Reference in New Issue
Block a user