修复微信订阅消息时间字段格式
生成结果订阅消息 time4 改为北京时间 YYYY-MM-DD HH:mm 补充成功和失败生成结果模板时间格式测试 记录 dev 订阅消息 time4 被微信拒收的排障口径
This commit is contained in:
@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use platform_wechat::WechatSubscribeMessageRequest;
|
||||
use shared_kernel::format_timestamp_micros;
|
||||
use time::{OffsetDateTime, UtcOffset};
|
||||
use tracing::{info, warn};
|
||||
|
||||
use crate::{http_error::AppError, platform_errors::map_wechat_error, state::AppState};
|
||||
@@ -160,12 +160,20 @@ fn truncate_template_value(value: &str, max_chars: usize) -> String {
|
||||
}
|
||||
|
||||
fn format_generation_completed_time(completed_at_micros: i64) -> String {
|
||||
format_timestamp_micros(completed_at_micros)
|
||||
.replace('T', " ")
|
||||
.split('.')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.to_string()
|
||||
let seconds = completed_at_micros.div_euclid(1_000_000);
|
||||
let Ok(utc_time) = OffsetDateTime::from_unix_timestamp(seconds) else {
|
||||
return "1970-01-01 08:00".to_string();
|
||||
};
|
||||
let beijing_offset = UtcOffset::from_hms(8, 0, 0).unwrap_or(UtcOffset::UTC);
|
||||
let local_time = utc_time.to_offset(beijing_offset);
|
||||
format!(
|
||||
"{:04}-{:02}-{:02} {:02}:{:02}",
|
||||
local_time.year(),
|
||||
u8::from(local_time.month()),
|
||||
local_time.day(),
|
||||
local_time.hour(),
|
||||
local_time.minute()
|
||||
)
|
||||
}
|
||||
|
||||
fn normalize_miniprogram_state(value: &str) -> &'static str {
|
||||
@@ -194,4 +202,21 @@ mod tests {
|
||||
assert_eq!(data.get("phrase2").map(String::as_str), Some("生成失败"));
|
||||
assert_eq!(data.get("number6").map(String::as_str), Some("0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generation_result_template_time_uses_wechat_time_format() {
|
||||
let data = build_generation_result_template_data(&GenerationResultSubscribeMessage {
|
||||
owner_user_id: "user-1".to_string(),
|
||||
work_name: Some("首关拼图".to_string()),
|
||||
status: GenerationResultSubscribeMessageStatus::Succeeded,
|
||||
consumed_points: 15,
|
||||
completed_at_micros: 0,
|
||||
page: None,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
data.get("time4").map(String::as_str),
|
||||
Some("1970-01-01 08:00")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user