From 846611cc9b641cbcb789a2e394d94b83c78985e0 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 6 Mar 2024 19:27:46 +0800 Subject: [PATCH] update --- app/customer/hdl/hdl_call_back.go | 9 ++++++--- app/utils/time.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/customer/hdl/hdl_call_back.go b/app/customer/hdl/hdl_call_back.go index a292952..0ba2bf8 100644 --- a/app/customer/hdl/hdl_call_back.go +++ b/app/customer/hdl/hdl_call_back.go @@ -12,7 +12,6 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/wechatpay-apiv3/wechatpay-go/utils" - "time" ) func AlipayJsApiCallBack(c *gin.Context) { @@ -72,8 +71,12 @@ func WxJsApiCallBack(c *gin.Context) { } utils2.FilePutContents("WxJsApiCallBack", utils2.SerializeStr(resp)) - successTime, _ := time.ParseInLocation("2006-01-02 15:04:05", resp.SuccessTime, time.Local) - _, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState, successTime.Format("2006-01-02 15:04:05")) + successTime, err := utils2.ConvertWechatTime(resp.SuccessTime) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + _, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState, successTime) if err != nil { e.OutErr(c, e.ERR, err.Error()) return diff --git a/app/utils/time.go b/app/utils/time.go index bc76fa7..e5863b3 100644 --- a/app/utils/time.go +++ b/app/utils/time.go @@ -223,3 +223,19 @@ func GetLastDateOfMonth(d time.Time) time.Time { func GetZeroTime(d time.Time) time.Time { return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location()) } + +func ConvertWechatTime(wechatTime string) (string, error) { + const layout = time.RFC3339 + parsedTime, err := time.Parse(layout, wechatTime) + if err != nil { + return "", err + } + // 转换到本地时区 + localTime := parsedTime.In(time.Local) + // 格式化本地时间为指定的格式,例如:"2006-01-02 15:04:05" + + formattedLocalTime := localTime.Format("2006-01-02 15:04:05") + + // 返回转换后的时间字符串 + return formattedLocalTime, nil +}