|
|
|
@ -12,6 +12,7 @@ import (
|
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/app"
|
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/convert"
|
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/errcode"
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
"github.com/smartwalle/alipay/v3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -21,21 +22,21 @@ func Login(c *gin.Context) {
|
|
|
|
|
response := app.NewResponse(c)
|
|
|
|
|
valid, errs := app.BindAndValid(c, ¶m)
|
|
|
|
|
if !valid {
|
|
|
|
|
conf.Logger.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
logrus.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user, err := service.DoLogin(c, ¶m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.DoLogin err: %v", err)
|
|
|
|
|
logrus.Errorf("service.DoLogin err: %v", err)
|
|
|
|
|
response.ToErrorResponse(err.(*errcode.Error))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
token, err := app.GenerateToken(user)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("app.GenerateToken err: %v", err)
|
|
|
|
|
logrus.Errorf("app.GenerateToken err: %v", err)
|
|
|
|
|
response.ToErrorResponse(errcode.UnauthorizedTokenGenerate)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -52,7 +53,7 @@ func Register(c *gin.Context) {
|
|
|
|
|
response := app.NewResponse(c)
|
|
|
|
|
valid, errs := app.BindAndValid(c, ¶m)
|
|
|
|
|
if !valid {
|
|
|
|
|
conf.Logger.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
logrus.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -60,7 +61,7 @@ func Register(c *gin.Context) {
|
|
|
|
|
// 用户名检查
|
|
|
|
|
err := service.ValidUsername(param.Username)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.Register err: %v", err)
|
|
|
|
|
logrus.Errorf("service.Register err: %v", err)
|
|
|
|
|
response.ToErrorResponse(err.(*errcode.Error))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -68,7 +69,7 @@ func Register(c *gin.Context) {
|
|
|
|
|
// 密码检查
|
|
|
|
|
err = service.CheckPassword(param.Password)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.Register err: %v", err)
|
|
|
|
|
logrus.Errorf("service.Register err: %v", err)
|
|
|
|
|
response.ToErrorResponse(err.(*errcode.Error))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -79,7 +80,7 @@ func Register(c *gin.Context) {
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.Register err: %v", err)
|
|
|
|
|
logrus.Errorf("service.Register err: %v", err)
|
|
|
|
|
response.ToErrorResponse(errcode.UserRegisterFailed)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -128,7 +129,7 @@ func ChangeUserPassword(c *gin.Context) {
|
|
|
|
|
response := app.NewResponse(c)
|
|
|
|
|
valid, errs := app.BindAndValid(c, ¶m)
|
|
|
|
|
if !valid {
|
|
|
|
|
conf.Logger.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
logrus.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -141,7 +142,7 @@ func ChangeUserPassword(c *gin.Context) {
|
|
|
|
|
// 密码检查
|
|
|
|
|
err := service.CheckPassword(param.Password)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.Register err: %v", err)
|
|
|
|
|
logrus.Errorf("service.Register err: %v", err)
|
|
|
|
|
response.ToErrorResponse(err.(*errcode.Error))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -165,7 +166,7 @@ func ChangeNickname(c *gin.Context) {
|
|
|
|
|
response := app.NewResponse(c)
|
|
|
|
|
valid, errs := app.BindAndValid(c, ¶m)
|
|
|
|
|
if !valid {
|
|
|
|
|
conf.Logger.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
logrus.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -193,7 +194,7 @@ func ChangeAvatar(c *gin.Context) {
|
|
|
|
|
response := app.NewResponse(c)
|
|
|
|
|
valid, errs := app.BindAndValid(c, ¶m)
|
|
|
|
|
if !valid {
|
|
|
|
|
conf.Logger.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
logrus.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -221,7 +222,7 @@ func BindUserPhone(c *gin.Context) {
|
|
|
|
|
response := app.NewResponse(c)
|
|
|
|
|
valid, errs := app.BindAndValid(c, ¶m)
|
|
|
|
|
if !valid {
|
|
|
|
|
conf.Logger.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
logrus.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -238,7 +239,7 @@ func BindUserPhone(c *gin.Context) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := service.CheckPhoneCaptcha(param.Phone, param.Captcha); err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.CheckPhoneCaptcha err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.CheckPhoneCaptcha err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -256,7 +257,7 @@ func GetUserProfile(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
user, err := service.GetUserByUsername(username)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetUserByUsername err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetUserByUsername err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.NoExistUsername)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -277,7 +278,7 @@ func GetUserPosts(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
user, err := service.GetUserByUsername(username)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetUserByUsername err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetUserByUsername err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.NoExistUsername)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -293,7 +294,7 @@ func GetUserPosts(c *gin.Context) {
|
|
|
|
|
Limit: app.GetPageSize(c),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetPostList err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetPostList err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.GetPostsFailed)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -309,7 +310,7 @@ func GetUserCollections(c *gin.Context) {
|
|
|
|
|
posts, totalRows, err := service.GetUserCollections(userID.(int64), (app.GetPage(c)-1)*app.GetPageSize(c), app.GetPageSize(c))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetUserCollections err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetUserCollections err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.GetCollectionsFailed)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -323,7 +324,7 @@ func GetUserStars(c *gin.Context) {
|
|
|
|
|
userID, _ := c.Get("UID")
|
|
|
|
|
posts, totalRows, err := service.GetUserStars(userID.(int64), (app.GetPage(c)-1)*app.GetPageSize(c), app.GetPageSize(c))
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetUserStars err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetUserStars err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.GetCollectionsFailed)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -337,7 +338,7 @@ func GetSuggestUsers(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
usernames, err := service.GetSuggestUsers(keyword)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetSuggestUsers err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetSuggestUsers err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.GetCollectionsFailed)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -351,7 +352,7 @@ func GetSuggestTags(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
tags, err := service.GetSuggestTags(keyword)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetSuggestTags err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetSuggestTags err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.GetCollectionsFailed)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -364,7 +365,7 @@ func GetUserRechargeLink(c *gin.Context) {
|
|
|
|
|
response := app.NewResponse(c)
|
|
|
|
|
valid, errs := app.BindAndValid(c, ¶m)
|
|
|
|
|
if !valid {
|
|
|
|
|
conf.Logger.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
logrus.Errorf("app.BindAndValid errs: %v", errs)
|
|
|
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -373,7 +374,7 @@ func GetUserRechargeLink(c *gin.Context) {
|
|
|
|
|
userID, _ := c.Get("UID")
|
|
|
|
|
recharge, err := service.CreateRecharge(userID.(int64), param.Amount)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.CreateRecharge err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.CreateRecharge err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
@ -382,28 +383,28 @@ func GetUserRechargeLink(c *gin.Context) {
|
|
|
|
|
client, err := alipay.New(conf.AlipaySetting.AppID, conf.AlipaySetting.PrivateKey, true)
|
|
|
|
|
// 将 key 的验证调整到初始化阶段
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("alipay.New err: %v\n", err)
|
|
|
|
|
logrus.Errorf("alipay.New err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = client.LoadAppPublicCertFromFile("configs/alipayAppCertPublicKey.crt") // 加载应用公钥证书
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("client.LoadAppPublicCertFromFile err: %v\n", err)
|
|
|
|
|
logrus.Errorf("client.LoadAppPublicCertFromFile err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = client.LoadAliPayRootCertFromFile("configs/alipayRootCert.crt") // 加载支付宝根证书
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("client.LoadAliPayRootCertFromFile err: %v\n", err)
|
|
|
|
|
logrus.Errorf("client.LoadAliPayRootCertFromFile err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = client.LoadAliPayPublicCertFromFile("configs/alipayCertPublicKey_RSA2.crt") // 加载支付宝公钥证书
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("client.LoadAliPayPublicCertFromFile err: %v\n", err)
|
|
|
|
|
logrus.Errorf("client.LoadAliPayPublicCertFromFile err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -416,7 +417,7 @@ func GetUserRechargeLink(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
rsp, err := client.TradePreCreate(p)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("client.TradePreCreate err: %v\n", err)
|
|
|
|
|
logrus.Errorf("client.TradePreCreate err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -461,35 +462,35 @@ func AlipayNotify(c *gin.Context) {
|
|
|
|
|
aliClient, err := alipay.New(conf.AlipaySetting.AppID, conf.AlipaySetting.PrivateKey, true)
|
|
|
|
|
// 将 key 的验证调整到初始化阶段
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("alipay.New err: %v\n", err)
|
|
|
|
|
logrus.Errorf("alipay.New err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
err = aliClient.LoadAppPublicCertFromFile("configs/alipayAppCertPublicKey.crt") // 加载应用公钥证书
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("client.LoadAppPublicCertFromFile err: %v\n", err)
|
|
|
|
|
logrus.Errorf("client.LoadAppPublicCertFromFile err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = aliClient.LoadAliPayRootCertFromFile("configs/alipayRootCert.crt") // 加载支付宝根证书
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("client.LoadAliPayRootCertFromFile err: %v\n", err)
|
|
|
|
|
logrus.Errorf("client.LoadAliPayRootCertFromFile err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = aliClient.LoadAliPayPublicCertFromFile("configs/alipayCertPublicKey_RSA2.crt") // 加载支付宝公钥证书
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("client.LoadAliPayPublicCertFromFile err: %v\n", err)
|
|
|
|
|
logrus.Errorf("client.LoadAliPayPublicCertFromFile err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeReqFail)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = aliClient.GetTradeNotification(c.Request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("aliClient.GetTradeNotification err: %v\n", err)
|
|
|
|
|
conf.Logger.Infoln(c.Request.Form)
|
|
|
|
|
logrus.Errorf("aliClient.GetTradeNotification err: %v\n", err)
|
|
|
|
|
logrus.Infoln(c.Request.Form)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeNotifyError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -501,7 +502,7 @@ func AlipayNotify(c *gin.Context) {
|
|
|
|
|
// 交易支付成功
|
|
|
|
|
err = service.FinishRecharge(c, convert.StrTo(id).MustInt64(), tradeNo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.FinishRecharge err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.FinishRecharge err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.RechargeNotifyError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -516,7 +517,7 @@ func GetUserWalletBills(c *gin.Context) {
|
|
|
|
|
bills, totalRows, err := service.GetUserWalletBills(userID.(int64), (app.GetPage(c)-1)*app.GetPageSize(c), app.GetPageSize(c))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
conf.Logger.Errorf("service.GetUserWalletBills err: %v\n", err)
|
|
|
|
|
logrus.Errorf("service.GetUserWalletBills err: %v\n", err)
|
|
|
|
|
response.ToErrorResponse(errcode.GetCollectionsFailed)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|