modify files.
This commit is contained in:
@ -21,7 +21,9 @@ gpt35_model = "gpt35"
|
||||
|
||||
|
||||
[database]
|
||||
mysql_conn = "172.18.0.3:3306"
|
||||
#mysql_conn = "172.18.0.3:3306"
|
||||
mysql_conn = "testdb:3306"
|
||||
mysql_user = "root"
|
||||
mysql_pass = "mysqlpw"
|
||||
redis_conn = "172.18.0.2:6379"
|
||||
#redis_conn = "172.18.0.4:6379"
|
||||
redis_conn = "redis:6379"
|
||||
|
||||
22
logs/app.log
22
logs/app.log
@ -226,3 +226,25 @@
|
||||
{"level":"debug","time":"2024-08-01T18:56:35.139+0800","caller":"aigrammar/main.go:133","func":"main.parseToken","msg":"into func"}
|
||||
{"level":"info","time":"2024-08-01T18:56:35.139+0800","caller":"aigrammar/main.go:148","func":"main.parseToken","msg":"claims: ","claims":{"deviceID":"12345ABC","gid":10001,"exp1":1727974853}}
|
||||
{"level":"info","time":"2024-08-01T18:56:35.140+0800","caller":"aigrammar/translate.go:153","func":"main.TranslateFeedBackHandler","msg":"feedback","ID":10001,"feedback":{"product":"trans","input":"This is a demo text with more complex grammar checking algorithm of the pro version. ","output":"","res":"good"}}
|
||||
{"level":"info","time":"2025-01-18T19:42:46.477+0800","caller":"aigrammar/main.go:48","func":"main.main","msg":"DBManager init successfully. Mysql ","mysql_conn":"172.18.0.3:3306"}
|
||||
{"level":"debug","time":"2025-01-18T19:43:20.350+0800","caller":"aigrammar/main.go:140","func":"main.parseToken","msg":"into func"}
|
||||
{"level":"fatal","time":"2025-01-18T19:43:20.355+0800","caller":"aigrammar/main.go:150","func":"main.parseToken","msg":"ParaseToken Error.","error":"signature is invalid","stacktrace":"main.parseToken\n\t/root/aigrammar/main.go:150\ngithub.com/labstack/echo-jwt/v4.Config.ToMiddleware.func2.1\n\t/root/go/pkg/mod/github.com/labstack/echo-jwt/v4@v4.2.0/jwt.go:227\ngithub.com/labstack/echo/v4.(*Echo).add.func1\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/echo.go:587\nmain.unifiedResponseHandler.func1\n\t/root/aigrammar/format.go:19\nmain.main.Recover.RecoverWithConfig.func2.1\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/middleware/recover.go:130\ngithub.com/labstack/echo/v4/middleware.RequestLoggerConfig.ToMiddleware.func1.1\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/middleware/request_logger.go:286\ngithub.com/labstack/echo/v4.(*Echo).ServeHTTP\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/echo.go:674\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:3137\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:2039"}
|
||||
{"level":"info","time":"2025-01-18T19:48:25.208+0800","caller":"aigrammar/main.go:48","func":"main.main","msg":"DBManager init successfully. Mysql ","mysql_conn":"172.18.0.3:3306"}
|
||||
{"level":"debug","time":"2025-01-18T19:49:54.283+0800","caller":"aigrammar/main.go:140","func":"main.parseToken","msg":"into func"}
|
||||
{"level":"fatal","time":"2025-01-18T19:49:54.288+0800","caller":"aigrammar/main.go:150","func":"main.parseToken","msg":"ParaseToken Error.","error":"signature is invalid","stacktrace":"main.parseToken\n\t/root/aigrammar/main.go:150\ngithub.com/labstack/echo-jwt/v4.Config.ToMiddleware.func2.1\n\t/root/go/pkg/mod/github.com/labstack/echo-jwt/v4@v4.2.0/jwt.go:227\ngithub.com/labstack/echo/v4.(*Echo).add.func1\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/echo.go:587\nmain.unifiedResponseHandler.func1\n\t/root/aigrammar/format.go:19\nmain.main.Recover.RecoverWithConfig.func2.1\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/middleware/recover.go:130\ngithub.com/labstack/echo/v4/middleware.RequestLoggerConfig.ToMiddleware.func1.1\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/middleware/request_logger.go:286\ngithub.com/labstack/echo/v4.(*Echo).ServeHTTP\n\t/root/go/pkg/mod/github.com/labstack/echo/v4@v4.12.0/echo.go:674\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:3137\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:2039"}
|
||||
{"level":"info","time":"2025-01-18T19:56:22.182+0800","caller":"aigrammar/main.go:48","func":"main.main","msg":"DBManager init successfully. Mysql ","mysql_conn":"172.18.0.3:3306"}
|
||||
{"level":"debug","time":"2025-01-18T19:56:29.911+0800","caller":"aigrammar/main.go:140","func":"main.parseToken","msg":"into func"}
|
||||
{"level":"info","time":"2025-01-18T19:56:29.916+0800","caller":"aigrammar/main.go:155","func":"main.parseToken","msg":"claims: ","GID":10001,"DeviceID":"12345ABC","Exp1":1737201299}
|
||||
{"level":"debug","time":"2025-01-18T20:00:25.259+0800","caller":"aigrammar/main.go:140","func":"main.parseToken","msg":"into func"}
|
||||
{"level":"info","time":"2025-01-18T20:00:25.260+0800","caller":"aigrammar/main.go:155","func":"main.parseToken","msg":"claims: ","GID":10001,"DeviceID":"12345ABC","Exp1":1737201299}
|
||||
{"level":"debug","time":"2025-01-18T20:02:30.579+0800","caller":"aigrammar/main.go:140","func":"main.parseToken","msg":"into func"}
|
||||
{"level":"info","time":"2025-01-18T20:02:30.579+0800","caller":"aigrammar/main.go:155","func":"main.parseToken","msg":"claims: ","GID":10001,"DeviceID":"12345ABC","Exp1":1747201724}
|
||||
{"level":"warn","time":"2025-01-18T20:02:30.615+0800","caller":"aigrammar/user.go:59","func":"main.queryUserHandler","msg":"userid not match","ID":10003,"userGID":10001}
|
||||
{"level":"debug","time":"2025-01-18T20:04:37.741+0800","caller":"aigrammar/main.go:140","func":"main.parseToken","msg":"into func"}
|
||||
{"level":"info","time":"2025-01-18T20:04:37.742+0800","caller":"aigrammar/main.go:155","func":"main.parseToken","msg":"claims: ","GID":10001,"DeviceID":"12345ABC","Exp1":1747201724}
|
||||
{"level":"debug","time":"2025-01-18T20:04:37.764+0800","caller":"aigrammar/user.go:154","func":"main.queryUserBenefits","msg":"CheckAndDecrement","ID":10001,"timeZone":"Asia/Shanghai","secondsFromGMT":28800,"status":0}
|
||||
{"level":"warn","time":"2025-01-18T20:04:44.317+0800","caller":"aigrammar/translate.go:243","func":"main.gTranslate","msg":"filterd","Hate":"safe","Hate-filtered":false,"SelfHarm":"safe","SelfHarm-filtered":false,"Sexual":"safe","Sexual-filtered":false,"Violence":"safe","Violence-filtered":false,"Error":"no content","input":"This is a demo text with more complex grammar checking algorithm of the pro version. This app have been designed to help you to write correctly and appear more professional. I work really hard to make this app as god as possible. If you are happy with the results, please consider supporting the app by subscribing to the PRO plan. The text writen here is to show you how much the app is capable of with the pro version. is this something you would like to use?"}
|
||||
{"level":"debug","time":"2025-01-18T20:04:44.318+0800","caller":"aigrammar/translate.go:262","func":"main.gTranslate","msg":"Finish Reason","index":0,"reason":"stop"}
|
||||
{"level":"info","time":"2025-01-18T20:04:44.318+0800","caller":"aigrammar/translate.go:48","func":"main.TranslateHandler","msg":"translation","ID":10001,"input":"This is a demo text with more complex grammar checking algorithm of the pro version. This app have been designed to help you to write correctly and appear more professional. I work really hard to make this app as god as possible. If you are happy with the results, please consider supporting the app by subscribing to the PRO plan. The text writen here is to show you how much the app is capable of with the pro version. is this something you would like to use?","output":"这是一个演示文本,它使用了更复杂的语法检查算法。这款应用程序的设计是为了帮助您进行正确地写作,以显得更加专业。我非常努力地使这款应用尽可能地完美。如果您对结果满意,请考虑通过订阅PRO计划来支持这款应用。这里写下的文本是为了向您展示这款应用在专业版本中所能达到的效果。这是您想要使用的吗?"}
|
||||
{"level":"info","time":"2025-03-12T16:00:15.593+0800","caller":"aigrammar/main.go:48","func":"main.main","msg":"DBManager init successfully. Mysql ","mysql_conn":"testdb:3306"}
|
||||
{"level":"info","time":"2025-03-12T16:00:46.611+0800","caller":"aigrammar/main.go:48","func":"main.main","msg":"DBManager init successfully. Mysql ","mysql_conn":"testdb:3306"}
|
||||
|
||||
@ -65,3 +65,7 @@
|
||||
{"level":"info","method":"POST","msg":"request log","remote_ip":"192.168.65.1","status":200,"time":"2024-08-01T17:49:38+08:00","uri":"/grammar/words","user_agent":""}
|
||||
{"level":"info","method":"POST","msg":"request log","remote_ip":"192.168.65.1","status":200,"time":"2024-08-01T18:56:25+08:00","uri":"/grammar/words","user_agent":""}
|
||||
{"level":"info","method":"POST","msg":"request log","remote_ip":"192.168.65.1","status":200,"time":"2024-08-01T18:56:35+08:00","uri":"/grammar/feedback","user_agent":""}
|
||||
{"level":"info","method":"POST","msg":"request log","remote_ip":"172.18.0.1","status":401,"time":"2025-01-18T19:56:29+08:00","uri":"/user/get","user_agent":""}
|
||||
{"level":"info","method":"POST","msg":"request log","remote_ip":"172.18.0.1","status":401,"time":"2025-01-18T20:00:25+08:00","uri":"/user/get","user_agent":""}
|
||||
{"level":"info","method":"POST","msg":"request log","remote_ip":"172.18.0.1","status":200,"time":"2025-01-18T20:02:30+08:00","uri":"/user/get","user_agent":""}
|
||||
{"level":"info","method":"POST","msg":"request log","remote_ip":"172.18.0.1","status":200,"time":"2025-01-18T20:04:44+08:00","uri":"/grammar/translate","user_agent":""}
|
||||
|
||||
2
main.go
2
main.go
@ -152,7 +152,7 @@ func parseToken(c echo.Context, auth string) (interface{}, error) {
|
||||
}
|
||||
|
||||
if claims, ok := token.Claims.(*jwtCustomClaims); ok && token.Valid {
|
||||
logger.Info("claims: ", zap.Any("claims", claims))
|
||||
logger.Info("claims: ", zap.Int("GID", claims.GID), zap.String("DeviceID", claims.DeviceID), zap.Int64("Exp1", claims.Exp1))
|
||||
// 判断token有效期
|
||||
if time.Now().Unix() > claims.Exp1 {
|
||||
return nil, echo.NewHTTPError(http.StatusUnauthorized, "Token expired")
|
||||
|
||||
48
user.go
48
user.go
@ -152,6 +152,9 @@ func queryUserBenefits(c echo.Context) (bool, error) {
|
||||
return false, err
|
||||
} else {
|
||||
logger.Debug("CheckAndDecrement", zap.Int("ID", ID), zap.String("timeZone", timeZone), zap.Int("secondsFromGMT", secondsFromGMT), zap.Int("status", status))
|
||||
if status != 0 {
|
||||
logger.Warn("user beyond limit.", zap.Int("ID", ID), zap.String("timeZone", timeZone), zap.Int("secondsFromGMT", secondsFromGMT), zap.Int("status", status))
|
||||
}
|
||||
return status == 0, nil
|
||||
}
|
||||
} else if err != nil {
|
||||
@ -192,16 +195,24 @@ func UpdateOrderByVerify(ID int, AppAcountToken string, OriginTransID string, tr
|
||||
// 如果是Sandbox交易,那么直接使用Transaction中的过期时间,注意匹配时区
|
||||
if strings.EqualFold(string(transantion.Environment), "Sandbox") {
|
||||
nextDay = time.Unix(transantion.ExpiresDate/1000, 0).In(time.Local)
|
||||
logger.Debug("Sandbox ExpireDate", zap.Any("ExpireDate", nextDay), zap.Any("NowDate", currentTime))
|
||||
logger.Debug("Sandbox ExpireDate", zap.Int("ID", ID), zap.Any("ExpireDate", nextDay), zap.Any("NowDate", currentTime))
|
||||
} else {
|
||||
logger.Debug("Production ExpireDate", zap.Int("ID", ID), zap.Any("ExpireDate", nextDay), zap.Any("NowDate", currentTime))
|
||||
}
|
||||
|
||||
// TODO: transaction.TransactionReason 有新购和续费,需要区分;同一个购买或者续费事件,可能有通知多次,需要排重
|
||||
var tmpID int
|
||||
errDup := db.MySQL.QueryRow("SELECT ID from vip where TransactionID = ? and OriginalTransactionID = ? and IsVip = 1 and ExpDate > ?", transantion.TransactionID, transantion.OriginalTransactionId, currentTime).Scan(&tmpID)
|
||||
if errDup != sql.ErrNoRows {
|
||||
// 表示重复了,可以直接返回
|
||||
logger.Info("duplicate request", zap.Int("ID", ID), zap.String("AppAcountToken", AppAcountToken), zap.String("OriginTransID", OriginTransID), zap.String("TransactionID", transantion.TransactionID))
|
||||
return nil
|
||||
// 不为空,有两种可能,一是请求重复了,比如用户发起了Restore;另一种可能,是用户换了设备,甚至是UserID,这时候就得处理,把原来的ID会员拿掉,换到新的上面来。
|
||||
if tmpID != ID {
|
||||
logger.Warn("duplicate request, but different ID", zap.Int("tblID", tmpID), zap.Int("ReqID", ID), zap.String("AppAcountToken", AppAcountToken), zap.String("OriginTransID", OriginTransID), zap.String("TransactionID", transantion.TransactionID))
|
||||
return nil
|
||||
} else {
|
||||
// 表示重复了,可以直接返回
|
||||
logger.Info("duplicate request", zap.Int("ID", ID), zap.String("AppAcountToken", AppAcountToken), zap.String("OriginTransID", OriginTransID), zap.String("TransactionID", transantion.TransactionID))
|
||||
return nil
|
||||
}
|
||||
} else if errDup != nil {
|
||||
logger.Info("prepare to insert record", zap.Int("ID", ID), zap.String("AppAcountToken", AppAcountToken), zap.String("OriginTransID", OriginTransID))
|
||||
// 这里不返回,继续尝试更新。
|
||||
@ -213,15 +224,40 @@ func UpdateOrderByVerify(ID int, AppAcountToken string, OriginTransID string, tr
|
||||
ON DUPLICATE KEY UPDATE
|
||||
IsVip = 1, AppStore = ?, ProductID = ?, ProductType = ?, Environment = ?, Price = ?, Currency = ?, Storefront = ?, PurchaseDate = ?, ExpDate = ?, AutoRenew = ?, OriginalTransactionID = ? , TransactionID = ?, AppAccountToken = ?, TransactionReason = ? `
|
||||
|
||||
_, err2 := db.MySQL.Exec(sql,
|
||||
// 开始事务
|
||||
tx, err := db.MySQL.Begin()
|
||||
if err != nil {
|
||||
logger.Error("Mysql Transaction error.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// 写入订阅信息
|
||||
_, err2 := tx.Exec(sql,
|
||||
ID, APPSTORE, transantion.ProductID, ProductType, transantion.Environment, Price, Currency, transantion.Storefront, currentTime, nextDay, 1, OriginTransID, transantion.TransactionID, transantion.AppAccountToken, transantion.TransactionReason,
|
||||
APPSTORE, transantion.ProductID, ProductType, transantion.Environment, Price, Currency, transantion.Storefront, currentTime, nextDay, 1, OriginTransID, transantion.TransactionID, transantion.AppAccountToken, transantion.TransactionReason)
|
||||
|
||||
if err2 != nil {
|
||||
logger.Error("UpdateOrderByVerify", zap.Error(err), zap.Int("ID", ID), zap.String("AppAcountToken", AppAcountToken), zap.String("OriginTransID", OriginTransID))
|
||||
logger.Error("UpdateOrderByVerify", zap.Error(err2), zap.Int("ID", ID), zap.String("AppAcountToken", AppAcountToken), zap.String("OriginTransID", OriginTransID))
|
||||
tx.Rollback()
|
||||
return err2
|
||||
}
|
||||
|
||||
// 如果是订阅信息转移到了另外一个ID上,需要把旧的ID 的vip去掉。
|
||||
if tmpID != ID {
|
||||
// 更新vip表,tmpID 行的 ExpDate 设置为 currentTime
|
||||
_, err3 := tx.Exec("update vip set ExpDate = ? where ID = ? ", currentTime, tmpID)
|
||||
if err3 != nil {
|
||||
logger.Error("UpdateOrderByVerify, update error", zap.Error(err3), zap.Int("ID", tmpID), zap.String("AppAcountToken", AppAcountToken), zap.String("OriginTransID", OriginTransID))
|
||||
tx.Rollback()
|
||||
return err3
|
||||
}
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
logger.Error("tx.Commit", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user