同步
This commit is contained in:
@@ -199,15 +199,17 @@ func GiftPayDetail(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 发起人昵称(脱敏)
|
||||
// 发起人昵称与头像(完整展示)
|
||||
var initiator model.User
|
||||
nickname := "好友"
|
||||
if err := db.Where("id = ?", gpr.InitiatorUserID).Select("nickname").First(&initiator).Error; err == nil && initiator.Nickname != nil {
|
||||
n := *initiator.Nickname
|
||||
if len(n) > 2 {
|
||||
n = string([]rune(n)[0]) + "**"
|
||||
initiatorAvatar := ""
|
||||
if err := db.Where("id = ?", gpr.InitiatorUserID).Select("nickname", "avatar").First(&initiator).Error; err == nil {
|
||||
if initiator.Nickname != nil && *initiator.Nickname != "" {
|
||||
nickname = *initiator.Nickname
|
||||
}
|
||||
if initiator.Avatar != nil && *initiator.Avatar != "" {
|
||||
initiatorAvatar = *initiator.Avatar
|
||||
}
|
||||
nickname = n
|
||||
}
|
||||
|
||||
// 营销:章节类型时返回标题和内容预览,吸引代付人
|
||||
@@ -224,17 +226,18 @@ func GiftPayDetail(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"requestSn": gpr.RequestSN,
|
||||
"productType": gpr.ProductType,
|
||||
"productId": gpr.ProductID,
|
||||
"amount": gpr.Amount,
|
||||
"description": gpr.Description,
|
||||
"sectionTitle": sectionTitle,
|
||||
"contentPreview": contentPreview,
|
||||
"initiatorNickname": nickname,
|
||||
"initiatorUserId": gpr.InitiatorUserID,
|
||||
"expireAt": gpr.ExpireAt.Format(time.RFC3339),
|
||||
"success": true,
|
||||
"requestSn": gpr.RequestSN,
|
||||
"productType": gpr.ProductType,
|
||||
"productId": gpr.ProductID,
|
||||
"amount": gpr.Amount,
|
||||
"description": gpr.Description,
|
||||
"sectionTitle": sectionTitle,
|
||||
"contentPreview": contentPreview,
|
||||
"initiatorNickname": nickname,
|
||||
"initiatorAvatar": initiatorAvatar,
|
||||
"initiatorUserId": gpr.InitiatorUserID,
|
||||
"expireAt": gpr.ExpireAt.Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -307,12 +310,23 @@ func GiftPayPay(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 唤起微信支付,attach 中 userId=发起人,giftPayRequestSn=请求号
|
||||
// 注意:必须使用代付人(payer)的 openId,微信会在代付人手机上唤起支付
|
||||
attach := fmt.Sprintf(`{"productType":"%s","productId":"%s","userId":"%s","giftPayRequestSn":"%s"}`,
|
||||
gpr.ProductType, gpr.ProductID, gpr.InitiatorUserID, gpr.RequestSN)
|
||||
totalFee := int(gpr.Amount * 100)
|
||||
if totalFee < 1 {
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "error": "金额异常,无法发起支付"})
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
prepayID, err := wechat.PayJSAPIOrder(ctx, req.OpenID, orderSn, totalFee, "代付-"+gpr.Description, attach)
|
||||
if err != nil {
|
||||
openIDMask := req.OpenID
|
||||
if len(openIDMask) > 8 {
|
||||
openIDMask = openIDMask[:4] + "***" + openIDMask[len(openIDMask)-4:]
|
||||
}
|
||||
fmt.Printf("[GiftPayPay] 微信统一下单失败: orderSn=%s openId=%s payerId=%s initiatorId=%s err=%v\n",
|
||||
orderSn, openIDMask, payer.ID, gpr.InitiatorUserID, err)
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "error": fmt.Sprintf("支付请求失败: %v", err)})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user