MCPcopy Index your code
hub / github.com/53AI/53AIHub / WechatPayNotify

Function WechatPayNotify

api/controller/pay.go:459–659  ·  view source on GitHub ↗

WechatPayNotify handles WeChat payment notification callbacks It processes payment result notifications sent by WeChat Pay after a payment is completed The function verifies the notification, decrypts the data, and updates the order status accordingly @Summary Process WeChat payment notification @De

(c *gin.Context)

Source from the content-addressed store, hash-verified

457// @Failure 500 {string} string "Internal Server Error"
458// @Router /api/payment/wechat/notify/{id} [post]
459func WechatPayNotify(c *gin.Context) {
460 // Log request basic information
461 xlog.Info("Received WeChat payment notification - Time:", time.Now().Format("2006-01-02 15:04:05"))
462 xlog.Info("Request IP:", c.ClientIP())
463
464 // Log request headers
465 headers := make(map[string]string)
466 for k, v := range c.Request.Header {
467 if len(v) > 0 {
468 headers[k] = v[0]
469 xlog.Info("Request header:", k, "=", v[0])
470 }
471 }
472
473 // Read and log request body - Ensure safe reading of request body
474 var bodyBytes []byte
475 if c.Request.Body != nil {
476 // Save original request body
477 bodyBytes, _ = io.ReadAll(c.Request.Body)
478 // Reset request body for subsequent processing
479 c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
480
481 // Log original request body
482 xlog.Info("Request raw body:", string(bodyBytes))
483 }
484
485 // Reset request body again for subsequent parsing
486 if len(bodyBytes) > 0 {
487 c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
488 }
489
490 // Get enterprise ID
491 notifyID := c.Param("id")
492 eid, err := strconv.ParseInt(notifyID, 10, 64)
493 if err != nil {
494 xlog.Error("Invalid notification ID:", err)
495 c.String(http.StatusBadRequest, "Invalid notification ID")
496 return
497 }
498
499 // Get WeChat payment settings
500 paySetting, err := model.GetPaySettingByType(eid, model.PayTypeWechat)
501 if err != nil {
502 xlog.Error("Payment setting not found:", err)
503 c.String(http.StatusBadRequest, "Payment setting not found")
504 return
505 }
506
507 // Parse WeChat configuration
508 var wechatConfig model.WechatPayConfig
509 if err = json.Unmarshal([]byte(paySetting.PayConfig), &wechatConfig); err != nil {
510 xlog.Error("Parse payment config error:", err)
511 c.String(http.StatusInternalServerError, "Failed to parse payment configuration")
512 return
513 }
514
515 // 添加详细的配置信息日志(隐藏敏感信息)
516 xlog.Info("WeChat Pay Config Debug Info:")

Callers

nothing calls this directly

Calls 8

getCachedOrderFunction · 0.85
removeCachedOrderFunction · 0.85
InfoMethod · 0.80
ErrorfMethod · 0.80
UnlockMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected