kefu/tmpl/pay.go

48 lines
1.1 KiB
Go
Raw Normal View History

2024-12-10 02:50:12 +00:00
package tmpl
import (
"github.com/gin-gonic/gin"
"kefu/lib"
"kefu/models"
"log"
"net/http"
)
func PayHtml(c *gin.Context) {
kefuName := c.Param("kefuName")
entId := c.Param("entId")
wechatConfig, _ := lib.NewWechatLib(models.FindConfig("SystemBussinesId"))
appId := wechatConfig.AppId
host := wechatConfig.WechatHost
entInfo := models.FindUserById(entId)
openId := c.Query("open_id")
nickname := ""
avatar := ""
weixinCode := c.Query("code")
product := c.Query("product")
if openId == "" && weixinCode != "" {
userInfo, err := GetWechatUserInfo(weixinCode, entId)
if err == nil {
openId = userInfo.OpenID
nickname = userInfo.Nickname
avatar = userInfo.HeadImgURL
} else {
log.Println("微信公众号网页授权错误:", err)
}
}
virtProduct := models.FindVirtualProduct("ent_id = ? and id = ?", entId, product)
c.HTML(http.StatusOK, "pay.html", gin.H{
"Title": entInfo.Nickname,
"kefuName": kefuName,
"EntId": entId,
"AppId": appId,
"Host": host,
"OpenID": openId,
"NickName": nickname,
"Avatar": avatar,
"Product": product,
"Payment": virtProduct.Payment,
})
}