$wxTransactionId, 'wx_sub_mch_id' => trim((string) ($wxResp['sub_mch_id'] ?? '')), 'wx_sub_openid' => $wxSubOpenid, 'hf_seq_id' => trim((string) ($data['hf_seq_id'] ?? '')), ]; } public static function encodeExtra(array $wxFields) { return json_encode([ 'wx_transaction_id' => $wxFields['wx_transaction_id'] ?? '', 'wx_sub_mch_id' => $wxFields['wx_sub_mch_id'] ?? '', 'wx_sub_openid' => $wxFields['wx_sub_openid'] ?? '', ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } public static function decodeExtra($extra) { if (!$extra) { return []; } if (is_array($extra)) { return $extra; } $decoded = json_decode($extra, true); return is_array($decoded) ? $decoded : []; } public static function resolveTransactionId(array $wxFields) { $wxTxn = trim((string) ($wxFields['wx_transaction_id'] ?? '')); if ($wxTxn !== '') { return $wxTxn; } return trim((string) ($wxFields['hf_seq_id'] ?? '')); } /** * Shopro 订单 payment_json 列为 varchar(2500),汇付完整 notify 会超长 */ public static function buildPaymentJson(array $data, array $wxFields = null) { $wxFields = $wxFields ?: self::extract($data); $snapshot = [ 'req_seq_id' => trim((string) ($data['req_seq_id'] ?? '')), 'hf_seq_id' => trim((string) ($data['hf_seq_id'] ?? '')), 'trans_stat' => trim((string) ($data['trans_stat'] ?? '')), 'trans_amt' => trim((string) ($data['trans_amt'] ?? '')), 'resp_code' => trim((string) ($data['resp_code'] ?? '')), 'out_trans_id' => trim((string) ($data['out_trans_id'] ?? '')), 'transaction_id' => trim((string) ($wxFields['wx_transaction_id'] ?? '')), 'sub_openid' => trim((string) ($wxFields['wx_sub_openid'] ?? '')), 'huifu_id' => trim((string) ($data['huifu_id'] ?? '')), 'pay_type' => 'huifu_wechat', 'wx_response' => array_filter([ 'transaction_id' => trim((string) ($wxFields['wx_transaction_id'] ?? '')), 'sub_mch_id' => trim((string) ($wxFields['wx_sub_mch_id'] ?? '')), 'sub_openid' => trim((string) ($wxFields['wx_sub_openid'] ?? '')), ]), ]; $json = json_encode($snapshot, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); if (strlen($json) <= 2400) { return $json; } unset($snapshot['wx_response']); return json_encode($snapshot, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } }