diff --git a/api/h5/index.go b/api/h5/index.go index 02d7907..51b0d55 100644 --- a/api/h5/index.go +++ b/api/h5/index.go @@ -1,20 +1,9 @@ package h5 import ( - "encoding/json" - "fmt" "github.com/gin-gonic/gin" - "gorm.io/gorm" "insure/errors" - "insure/global" - "insure/request" - "insure/service" - "insure/utils/alipay" "insure/utils/result" - "insure/utils/tlpay/notify" - "insure/utils/weixin" - "net/http" - "strconv" ) func Index(c *gin.Context) (result.Data, error) { @@ -24,299 +13,3 @@ func Index(c *gin.Context) (result.Data, error) { func Error(c *gin.Context) (result.Data, error) { return nil, errors.NewBusinessError("测试", "1122") } - -func Register(c *gin.Context) (result.Data, error) { - mobile := c.PostForm("mobile") - password := c.PostForm("password") - err := service.UserService.Register(mobile, password) - return nil, err -} - -func Login(c *gin.Context) (result.Data, error) { - mobile := c.PostForm("mobile") - password := c.PostForm("password") - token, err := service.UserService.Login(mobile, password) - return result.Data{"token": token}, err -} - -func GetUserInfo(c *gin.Context) (result.Data, error) { - user, _ := c.Get("user") - data := result.Data{"user": user} - return data, nil -} - -func GetUserData(c *gin.Context) (result.Data, error) { - data := service.UserService.GetUserData(user(c)) - return data, nil -} - -func ModifyPassword(c *gin.Context) (result.Data, error) { - oldPassword := c.PostForm("oldPassword") - password := c.PostForm("password") - err := service.UserService.ModifyPassword(password, oldPassword, user(c)) - return nil, err -} - -func GetProductInfo(c *gin.Context) (result.Data, error) { - productId := c.Query("productId") - id, _ := strconv.Atoi(productId) - product, err := service.ProductService.GetProductInfo(id) - if err != nil { - return nil, err - } - data := result.Data{"product": product} - return data, nil -} - -func GetPayments(c *gin.Context) (result.Data, error) { - var paymentQueryRequest request.PaymentQueryRequest - err := c.ShouldBindQuery(&paymentQueryRequest) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - payments, total := service.PaymentService.GetUserPayments(user(c).ID, paymentQueryRequest.Page, paymentQueryRequest.PageSize) - data := result.Data{ - "payments": payments, - "total": total, - } - return data, nil -} - -func Payment(c *gin.Context) (result.Data, error) { - var paymentRequest request.PaymentRequest - err := c.ShouldBind(&paymentRequest) - fmt.Println(paymentRequest) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - return service.PaymentService.Payment(user(c).ID, paymentRequest) -} - -func GetOrders(c *gin.Context) (result.Data, error) { - var orderQueryRequest request.OrderQueryRequest - err := c.ShouldBindQuery(&orderQueryRequest) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - orders, total := service.OrderService.GetUserOrders(user(c).ID, orderQueryRequest.Page, orderQueryRequest.PageSize) - data := result.Data{ - "orders": orders, - "total": total, - } - return data, nil -} - -func Order(c *gin.Context) (result.Data, error) { - var orderRequest request.OrderRequest - err := c.ShouldBind(&orderRequest) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - - order, err := service.OrderService.Order(orderRequest, user(c)) - if err != nil { - return nil, err - } - data := result.Data{"orderNo": order.OrderNo} - return data, nil -} - -func GetWxAuthUrl(c *gin.Context) (result.Data, error) { - amount := c.DefaultQuery("amount", "") - redirectUri := global.Config.Payment.WxPay.AuthRedirectUri - if amount != "" { - redirectUri += "?amount=" + amount - } - authUrl := weixin.WxApi.GetAuthUrl(redirectUri) - fmt.Println(authUrl) - data := result.Data{"url": authUrl} - return data, nil -} - -func GetWxOpenId(c *gin.Context) (result.Data, error) { - code := c.Query("code") - res, err := weixin.WxApi.GetAccessToken(code) - if err != nil { - return nil, err - } - data := result.Data{"openId": res.Openid} - return data, nil -} - -func GetAliOpenId(c *gin.Context) (result.Data, error) { - code := c.Query("code") - res, err := alipay.AlipayApi.GetAuthToken(code) - if err != nil { - return nil, err - } - data := result.Data{"openId": res.OpenID} - return data, nil -} - -func SaveAlipayAccount(c *gin.Context) (result.Data, error) { - alipayAccount := c.PostForm("alipayAccount") - err := service.UserService.SaveAlipayAccount(alipayAccount, user(c)) - return nil, err -} - -func TransferPayNotify(c *gin.Context) { - var req request.TransferPayNotifyRequest - err := c.ShouldBindQuery(&req) - if err != nil { - c.String(http.StatusOK, "fail") - return - } - service.PaymentService.AfterTransferPayNotify(req) - c.String(http.StatusOK, "success") - return -} - -func PaymentNotify(c *gin.Context) { - var req request.PaymentNotifyRequest - err := c.ShouldBind(&req) - if err != nil { - fmt.Println("error: " + err.Error()) - c.String(http.StatusOK, "fail") - return - } - fmt.Println("has-data") - fmt.Println(req) - - service.PaymentService.AfterPaymentNotify(req) - c.String(http.StatusOK, "success") - return -} - -func BindingPayNotify(c *gin.Context) { - var req notify.PayAgreeNotify - err := c.ShouldBind(&req) - if err != nil { - fmt.Println("error: " + err.Error()) - c.String(http.StatusOK, "fail") - return - } - fmt.Println("has-data") - fmt.Println(req) - reqJson, err := json.Marshal(req) - fmt.Println(string(reqJson)) - if err != nil { - c.String(http.StatusOK, "fail") - return - } - service.PaymentService.AfterBindingPayNotify(req) - c.String(http.StatusOK, "success") - return -} - -func GatewayPayRet(c *gin.Context) { - var req notify.GatewayPayRet - err := c.ShouldBind(&req) - if err != nil { - fmt.Println("error: " + err.Error()) - c.String(http.StatusOK, "fail") - return - } - fmt.Println("has-data") - fmt.Println(req) - reqJson, err := json.Marshal(req) - fmt.Println(string(reqJson)) - if err != nil { - c.String(http.StatusOK, "fail") - return - } - c.Redirect(http.StatusMovedPermanently, "http://mall.wrtcjt.com/pages/knq-detail/index") - return -} - -func TlBindingApply(c *gin.Context) (result.Data, error) { - var req request.TlBindingApplyRequest - err := c.ShouldBind(&req) - if err != nil { - return nil, err - } - thpInfo, err := service.UserService.TlBindingApply(req, user(c)) - data := result.Data{"thpInfo": thpInfo} - return data, err -} - -func TlBindingConfirm(c *gin.Context) (result.Data, error) { - var req request.TlBindingConfirmRequest - err := c.ShouldBind(&req) - if err != nil { - return nil, err - } - data, err := service.UserService.TlBindingConfirm(req, user(c)) - return data, err -} - -func GetUserBankCard(c *gin.Context) (result.Data, error) { - var req request.TlBindingConfirmRequest - err := c.ShouldBind(&req) - if err != nil { - return nil, err - } - bankCard, err := service.UserService.GetBankCardByUserID(user(c).ID) - if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { - return result.Data{"bankCard": bankCard}, nil - } - if err != nil { - return nil, err - } - card := result.Data{"agreeId": bankCard.AgreeID, "bankCode": bankCard.BankCode, "bankName": bankCard.BankName} - data := result.Data{"bankCard": card} - return data, err -} - -func BindingPayConfirm(c *gin.Context) (result.Data, error) { - var req request.BindingPayConfirmRequest - err := c.ShouldBind(&req) - if err != nil { - return nil, err - } - data, err := service.PaymentService.ConfirmBindingPayment(req, user(c)) - return data, err -} - -func BindingPaySms(c *gin.Context) (result.Data, error) { - var req request.BindingPaySmsRequest - err := c.ShouldBind(&req) - if err != nil { - return nil, err - } - data, err := service.PaymentService.SmsBindingPayment(req, user(c)) - return data, err -} - -func GatewayPayApply(c *gin.Context) (result.Data, error) { - var req request.PaymentRequest - err := c.ShouldBind(&req) - if err != nil { - return nil, err - } - req.PayType = "gateway" - return service.PaymentService.GatewayPayApply(user(c).ID, req) -} - -func GatewayPay(c *gin.Context) { - c.Writer.Header().Set("content-type", "text/html") - token := c.DefaultQuery("token", "") - if token == "" { - c.Writer.WriteString("token empty") - return - } - body, err := service.PaymentService.GatewayPay(token) - if err != nil { - c.Writer.WriteString(err.Error()) - return - } - c.Writer.WriteString(body) - return -} - -func BankCardUnbind(c *gin.Context) (result.Data, error) { - err := service.UserService.BankCardUnbind(user(c)) - if err != nil { - return nil, err - } - return nil, nil -} diff --git a/api/manage/auth.go b/api/manage/auth.go index 7b10feb..62435d8 100644 --- a/api/manage/auth.go +++ b/api/manage/auth.go @@ -1,44 +1 @@ package manage - -import ( - "fmt" - "github.com/gin-gonic/gin" - "insure/errors" - request "insure/request/manage" - "insure/service" - "insure/utils/result" -) - -func Login(c *gin.Context) (result.Data, error) { - loginRequest := request.LoginRequest{} - err := c.ShouldBindJSON(&loginRequest) - token, err := service.AdminService.Login(loginRequest.Username, loginRequest.Password) - return result.Data{"token": token}, err -} - -func GetAdminInfo(c *gin.Context) (result.Data, error) { - admin := service.AdminService.GetAdminInfo(admin(c).ID) - data := result.Data{ - "admin": admin, - } - return data, nil -} - -func Logout(c *gin.Context) (result.Data, error) { - return nil, nil -} - -func AddAdmin(c *gin.Context) (result.Data, error) { - addAdminRequest := request.AddAdminRequest{} - err := c.ShouldBindJSON(&addAdminRequest) - fmt.Println("addAdminRequest") - fmt.Println(addAdminRequest) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - err = service.AdminService.Add(addAdminRequest.Username, addAdminRequest.Password) - if err != nil { - return nil, err - } - return nil, nil -} diff --git a/api/manage/common.go b/api/manage/common.go index 9d95df0..21ef96d 100644 --- a/api/manage/common.go +++ b/api/manage/common.go @@ -2,7 +2,7 @@ package manage import ( "github.com/gin-gonic/gin" - "gold-shop/model" + "insure/model" ) func admin(c *gin.Context) *model.Admin { diff --git a/api/manage/order.go b/api/manage/order.go deleted file mode 100644 index 1258aae..0000000 --- a/api/manage/order.go +++ /dev/null @@ -1,31 +0,0 @@ -package manage - -import ( - "github.com/gin-gonic/gin" - "gold-shop/errors" - request "gold-shop/request/manage" - "gold-shop/service" - "gold-shop/utils/excel" - "gold-shop/utils/result" -) - -func GetOrders(c *gin.Context) (result.Data, error) { - var req request.OrderQueryRequest - err := c.ShouldBindQuery(&req) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - orders, total := service.OrderService.GetOrders(req) - data := result.Data{ - "records": orders, - "total": total, - } - return data, nil -} - -func DownloadOrders(c *gin.Context) { - var req request.OrderQueryRequest - _ = c.ShouldBindQuery(&req) - f := service.OrderService.GenerateOrdersExcel(req) - excel.Download(f, "订单列表.xlsx", c) -} diff --git a/api/manage/payment.go b/api/manage/payment.go deleted file mode 100644 index cb0a59c..0000000 --- a/api/manage/payment.go +++ /dev/null @@ -1,31 +0,0 @@ -package manage - -import ( - "github.com/gin-gonic/gin" - "gold-shop/errors" - request "gold-shop/request/manage" - "gold-shop/service" - "gold-shop/utils/excel" - "gold-shop/utils/result" -) - -func GetPayments(c *gin.Context) (result.Data, error) { - var req request.PaymentQueryRequest - err := c.ShouldBindQuery(&req) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - records, total := service.PaymentService.GetPayments(req) - data := result.Data{ - "records": records, - "total": total, - } - return data, nil -} - -func DownloadPayments(c *gin.Context) { - var req request.PaymentQueryRequest - _ = c.ShouldBindQuery(&req) - f := service.PaymentService.GeneratePaymentsExcel(req) - excel.Download(f, "支付列表.xlsx", c) -} diff --git a/api/manage/user.go b/api/manage/user.go deleted file mode 100644 index aacc45d..0000000 --- a/api/manage/user.go +++ /dev/null @@ -1,33 +0,0 @@ -package manage - -import ( - "fmt" - "github.com/gin-gonic/gin" - "gold-shop/errors" - request "gold-shop/request/manage" - "gold-shop/service" - "gold-shop/utils/excel" - "gold-shop/utils/result" -) - -func GetUsers(c *gin.Context) (result.Data, error) { - var req request.UserQueryRequest - err := c.ShouldBindQuery(&req) - fmt.Println("ssp", req) - if err != nil { - return nil, errors.NewBusinessError("参数错误") - } - users, total := service.UserService.GetUsers(req) - data := result.Data{ - "records": users, - "total": total, - } - return data, nil -} - -func DownloadUsers(c *gin.Context) { - var req request.UserQueryRequest - _ = c.ShouldBindQuery(&req) - f := service.UserService.GenerateUsersExcel(req) - excel.Download(f, "用户列表.xlsx", c) -} diff --git a/main.go b/cmd/web/main.go similarity index 93% rename from main.go rename to cmd/web/main.go index 2da2022..9c53ef1 100644 --- a/main.go +++ b/cmd/web/main.go @@ -5,7 +5,7 @@ import ( "github.com/gin-gonic/gin" "insure/global" "insure/initialize" - "insure/route" + "insure/router" ) func main() { @@ -33,7 +33,7 @@ func initial() { WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } - route.Initial(r) + router.Initial(r) err := endless.ListenAndServe(":"+global.Config.Server.Port, s.Handler) if err != nil { panic(err) @@ -42,6 +42,6 @@ func initial() { func runServerInWindows() { r := gin.Default() - route.Initial(r) + router.Initial(r) r.Run(":9090") } diff --git a/conf/config.yaml b/conf/config.yaml new file mode 100644 index 0000000..73c1aa2 --- /dev/null +++ b/conf/config.yaml @@ -0,0 +1,21 @@ +server: + port: 9090 + domain: "http://pay.hexidongkeji.top" +alipay: + app-id: "2021004129619376" + private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQChC/5Psy+biyzdT/CkCknQKax44Ol0i6kAWVkw4BYERevISFqOHpVmlztcnYGx3LIDOeReYQ0ghLLT+6oGrymXzPbIOE+PTUEpPfIRdB8P96mkcbuZ7MnMCsA1vXSjYezVIAu8vdzp4FL2H1p3+gwhuLGT5w9tOUZmNAkKI8xEQwXeFDWlQ5G9w5unigEGnlODqxcStrvL14pceqsA3bm9sEDuSqVAmBXbEZxZyWnYoRJj4kNMqYIXLXwsPzE8268B+0NT9plzv8mGBI2jkwBTXvc1TjnAIK6O0vRfAz82Jz6RhMwIIOrA65F1oO44bihd/4lH+FjrMy5nYeEuBZeZAgMBAAECggEBAJ/EPi7jHL+6em+z9o9GhaO1NB1XQ0MTqj1mZk1OgYkLtLWk0fFb9eso7QMcXqYMw6zfqebXcSZpft8+M5cd/q1R8SEAfC01/wbjJVqbUJWOpQU2r14swqVhpP2rTiMn6sQkXoCH+rkqiiMRR7buoUpy5/hKqcs5ntWVmcItcV/lZ/SOshXIY1Pff9WcJkNUQqtM8OizjSA1htc3XencsOroU6KKLnVdBcGYQJQtr7hBQshgGiaNKapv6n/qGV6J6V7uBuSfwZhNXo0GxbBqZHW3LCesipPkNAvYCu+DhpqVr+j44apGhZ56cIhqdYCrnPrMKysvYHnQ7sm3GhwnimECgYEA5WeTVLkRj7gmcWQQn7KobUxfdQXZguJdVYguTwbWENbZRTDxlv3aZvivAMDx9xDfEd58/xqm5mUathxG8M/HINJ9u32elhFLXLHPD5QzCqv4+X+dZmtnnqEHa5smSEpFL2vJ7v8FGnrAqXiZVye7uqcT7j/6hCZol+EZ1SPz6g8CgYEAs7emjtDwKyzyO1kRQfTB/smlS/hfIvknZZKQoYYRgiB60f2t6aDJOzjUMCIgClWpQztDzbKonKx1ykCmiSgtUJF9MVP4iz5cJKc0wdnjO20DxFJGMHl89ejlfrfmM5D1E0d2l7kpO6M/66mjNT7fGtAdorAw8OzKbZh/KCfsq9cCgYEApWEL95ILtP5eyHQI//f+L/1U+7oh2pdyDc1FBTe6bx1UOOtV3zJWltFE6Fgwl5qUFf+9QPNnysSsgwjTo5tGxMS6W8Xt4+XH3KVazrJaMaFUthln0YQwiU0xWkPZT1grlEoyo5c5iKNh7UrB0PEWBzOXzLRW15oQ4R0oUF3A48UCgYARV4Nm/JpwUCH/wBR+PNQLdgHRVuI3SbuXfZEfRQSjfebcJJKHnNBOOqmfC2v0E1gF+M4OJ1NF6w5iueJYEdxtjdx6yhONvDLABrJ8kj3vGhHm+9lyDAcW46Zhl/VKvI4pkhfLhD6KVrJwVyo8lRiKSdLSRBY06WSPNsvuYAvieQKBgQDk52HC2XLdui/wMnESIJ/+qwuKh/BAC7e/jEuZpQxRFVbE8L2m638f+tkXdHlMERqaROd2h31cPpvZzOyeJBvhUEmuQcBfq+G4YsRQIH0XDvx/nBO4m03nFOXyLkFx4X1fZs/0i3CO506WHdgkM5wd8nA6+9S4DdNAjHvoC4WQ3A==" + ali-public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhgLRPY+3aSGRvlcivmcPnSSL9v3BXSea3uDOZpIpzydHxQ16c/A2m6kVh9LxlJJngXldOkO2Q4VS32RufZntc9fkjiiuUxDBlFPKl5x72eiQVoBX4yM7j0gtBlwQFezsIPD0SRC/uxj75+MtjDUupAQLA4gB4zgSDmWWYAIGQlgXXAQExr5k7P1dXrXJMP9SpIYn3Uaug5ifqxanoiDCmMp/sMFasjlVBDIpLOZuKgBwcX3d2FmhRdWIWR5UVy3IbtWuqTJ8vqH8j6Y2jVFLxBA7+woYc0s7npZ0kTa0yGXFw/9LGinSGshGUCBjuAoi67cW6YvODjYFHuGqsrXZvwIDAQAB" +database: + host: "124.223.222.61" + port: "3306" + username: "elf1990" + password: "XtN1YiaqP4BxC9MEe" + dbname: "gold-shop" +redis: + host: "127.0.0.1" + port: "6379" + password: "" + db: 0 +jwt: + key: "I2js2oElEo82NmRru8v73Nwm" + issuer: "gold-shop" \ No newline at end of file diff --git a/config/config.go b/config/config.go index 6bb9088..9e11443 100644 --- a/config/config.go +++ b/config/config.go @@ -5,6 +5,4 @@ type Config struct { Database Database Jwt Jwt Redis Redis - Payment Payment - TlPay TlPay `yaml:"tl-pay"` } diff --git a/config/payment.go b/config/payment.go deleted file mode 100644 index 8194321..0000000 --- a/config/payment.go +++ /dev/null @@ -1,20 +0,0 @@ -package config - -type Payment struct { - BaseUrl string `yaml:"base-url"` - ApiKey string `yaml:"api-key"` - SignKey string `yaml:"sign-key"` - WxPay WxPay `yaml:"wx-pay"` - AliPay AliPay `yaml:"ali-pay"` -} - -type WxPay struct { - SubAppId string `yaml:"sub-app-id"` - SubAppSecret string `yaml:"sub-app-secret"` - AuthRedirectUri string `yaml:"auth-redirect-uri"` -} - -type AliPay struct { - SubAppId string `yaml:"sub-app-id"` - SubPriPemFile string `yaml:"sub-pri-pem-file"` -} diff --git a/config/tl_pay.go b/config/tl_pay.go deleted file mode 100644 index 3ef9bb1..0000000 --- a/config/tl_pay.go +++ /dev/null @@ -1,10 +0,0 @@ -package config - -type TlPay struct { - BaseUrl string `yaml:"base-url"` - CusID string `yaml:"cus-id"` - AppId string `yaml:"app-id"` - PriPemFile string `yaml:"pri-pem-file"` - PubPemFile string `yaml:"pub-pem-file"` - TlPubPemFile string `yaml:"tl-pub-pem-file"` -} diff --git a/dto/request/test_request.go b/dto/request/test_request.go new file mode 100644 index 0000000..d472532 --- /dev/null +++ b/dto/request/test_request.go @@ -0,0 +1,4 @@ +package request + +type TestRequest struct { +} diff --git a/global/global.go b/global/global.go index 52aee07..dd9c828 100644 --- a/global/global.go +++ b/global/global.go @@ -2,8 +2,8 @@ package global import ( "github.com/redis/go-redis/v9" - "gold-shop/config" "gorm.io/gorm" + "insure/config" ) var Config *config.Config diff --git a/go.mod b/go.mod index 603045c..12bb6f6 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,19 @@ module insure go 1.21 +require ( + github.com/gin-contrib/cors v1.7.2 + github.com/gin-gonic/gin v1.10.0 + github.com/golang-jwt/jwt/v5 v5.2.1 + github.com/redis/go-redis/v9 v9.5.2 + github.com/tjfoc/gmsm v1.4.1 + github.com/xuri/excelize/v2 v2.8.1 + golang.org/x/crypto v0.23.0 + gopkg.in/yaml.v3 v3.0.1 + gorm.io/driver/mysql v1.5.6 + gorm.io/gorm v1.25.10 +) + require ( github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect @@ -10,34 +23,32 @@ require ( github.com/cloudwego/iasm v0.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect - github.com/gin-contrib/cors v1.7.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect - github.com/gin-gonic/gin v1.10.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect - github.com/redis/go-redis/v9 v9.5.2 // indirect + github.com/richardlehane/mscfb v1.0.4 // indirect + github.com/richardlehane/msoleps v1.0.3 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect + github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect + github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.23.0 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect google.golang.org/protobuf v1.34.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/driver/mysql v1.5.6 // indirect - gorm.io/gorm v1.25.10 // indirect ) diff --git a/go.sum b/go.sum index b44a8e6..c74443c 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,31 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw= @@ -20,6 +34,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= @@ -32,6 +48,23 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= @@ -43,6 +76,10 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= @@ -52,11 +89,22 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/redis/go-redis/v9 v9.5.2 h1:L0L3fcSNReTRGyZ6AqAEN0K56wYeYAwapBIhkvh0f3E= github.com/redis/go-redis/v9 v9.5.2/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM= +github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk= +github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= +github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM= +github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -67,27 +115,84 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho= +github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 h1:Chd9DkqERQQuHpXjR/HSV1jLZA6uaoiwwH3vSuF3IW0= +github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= +github.com/xuri/excelize/v2 v2.8.1 h1:pZLMEwK8ep+CLIUWpWmvW8IWE/yxqG0I1xcN6cVMGuQ= +github.com/xuri/excelize/v2 v2.8.1/go.mod h1:oli1E4C3Pa5RXg1TBXn4ENCXDV5JUMlBluUhG7c+CEE= +github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 h1:qhbILQo1K3mphbwKh1vNm4oGezE1eF9fQWmNiIpSfI4= +github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= +golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -96,5 +201,7 @@ gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkD gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s= gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/initialize/initialize.go b/initialize/initialize.go index daef195..33b2707 100644 --- a/initialize/initialize.go +++ b/initialize/initialize.go @@ -9,11 +9,8 @@ import ( "gorm.io/gorm/logger" "insure/config" "os" - "path/filepath" ) -const FilePath = "config.yaml" - func InitConfig(filePath string) *config.Config { content, err := os.ReadFile(filePath) if err != nil { @@ -29,15 +26,6 @@ func InitConfig(filePath string) *config.Config { return &conf } -func getCurrentDirectory() (string, error) { - path, err := filepath.Abs(os.Args[0]) - if err != nil { - return "", err - } - dir := filepath.Dir(path) - return dir, nil -} - func InitDB(conf *config.Config) *gorm.DB { var mysqlLogger logger.Interface mysqlLogger = logger.Default.LogMode(logger.Info) diff --git a/model/order.go b/model/order.go deleted file mode 100644 index 8a13773..0000000 --- a/model/order.go +++ /dev/null @@ -1,34 +0,0 @@ -package model - -import ( - "encoding/json" - "time" -) - -type Order struct { - ID int - OrderNo string - UserID int - Amount float64 - User User `gorm:"foreignKey:UserID;references:ID"` - OrderProducts []OrderProduct `gorm:"foreignKey:OrderNo;references:OrderNo"` - CreatedAt time.Time - UpdatedAt time.Time -} - -func (Order) TableName() string { - return "orders" -} - -func (o Order) MarshalJSON() ([]byte, error) { - type Alias Order - return json.Marshal(&struct { - CreatedAt string - UpdatedAt string - *Alias - }{ - CreatedAt: o.CreatedAt.Format("2006-01-02 15:04:05"), - UpdatedAt: o.UpdatedAt.Format("2006-01-02 15:04:05"), - Alias: (*Alias)(&o), - }) -} diff --git a/model/order_product.go b/model/order_product.go deleted file mode 100644 index 0aa6fe7..0000000 --- a/model/order_product.go +++ /dev/null @@ -1,36 +0,0 @@ -package model - -import ( - "encoding/json" - "time" -) - -type OrderProduct struct { - ID uint - OrderNo string - UserID int - ProductID int - Num int - Price float64 - Amount float64 - Order *Order `gorm:"foreignKey:OrderNo;references:OrderNo"` - CreatedAt time.Time - UpdatedAt time.Time -} - -func (OrderProduct) TableName() string { - return "order_products" -} - -func (p OrderProduct) MarshalJSON() ([]byte, error) { - type Alias OrderProduct - return json.Marshal(&struct { - CreatedAt string - UpdatedAt string - *Alias - }{ - CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"), - UpdatedAt: p.UpdatedAt.Format("2006-01-02 15:04:05"), - Alias: (*Alias)(&p), - }) -} diff --git a/model/payment.go b/model/payment.go deleted file mode 100644 index 6df6500..0000000 --- a/model/payment.go +++ /dev/null @@ -1,58 +0,0 @@ -package model - -import ( - "encoding/json" - "time" -) - -const PaymentStatusSuccess = 1 -const PaymentStatusFailed = 2 -const PaymentStatusWait = 0 - -type Payment struct { - ID int - PaymentNo string - PayOrderID string - UserID int - Amount float64 - Token string - User User `gorm:"foreignKey:UserID;references:ID"` - PayType string - OpenID string - ErrorMessage string - PayerCardNo string - PayerAccountName string - Status int - CreatedAt time.Time - UpdatedAt time.Time -} - -func (Payment) TableName() string { - return "payments" -} - -func (p Payment) MarshalJSON() ([]byte, error) { - type Alias Payment - return json.Marshal(&struct { - CreatedAt string - UpdatedAt string - *Alias - }{ - CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"), - UpdatedAt: p.UpdatedAt.Format("2006-01-02 15:04:05"), - Alias: (*Alias)(&p), - }) -} - -func (p Payment) GetStatusText() string { - statusText := "" - switch p.Status { - case PaymentStatusSuccess: - statusText = "支付成功" - case PaymentStatusFailed: - statusText = "支付失败" - case PaymentStatusWait: - statusText = "待支付" - } - return statusText -} diff --git a/model/product.go b/model/product.go deleted file mode 100644 index 16c9cce..0000000 --- a/model/product.go +++ /dev/null @@ -1,16 +0,0 @@ -package model - -import "time" - -type Product struct { - ID int - Name string - Price float64 - Description string - CreatedAt time.Time `json:"-"` - UpdatedAt time.Time `json:"-"` -} - -func (Product) TableName() string { - return "products" -} diff --git a/model/user_bank_card.go b/model/user_bank_card.go deleted file mode 100644 index ac70b8a..0000000 --- a/model/user_bank_card.go +++ /dev/null @@ -1,39 +0,0 @@ -package model - -import ( - "encoding/json" - "time" -) - -type UserBankCard struct { - ID int - UserID int - Mobile string - AccountName string - AccountNo string - IdCardNo string - AgreeID string - BankCode string - BankName string - Status int - ErrorMessage string - CreatedAt time.Time - UpdatedAt time.Time `json:"-"` -} - -func (UserBankCard) TableName() string { - return "user_bank_cards" -} - -func (c UserBankCard) MarshalJSON() ([]byte, error) { - type Alias UserBankCard - return json.Marshal(&struct { - CreatedAt string - UpdatedAt string - *Alias - }{ - CreatedAt: c.CreatedAt.Format("2006-01-02 15:04:05"), - UpdatedAt: c.UpdatedAt.Format("2006-01-02 15:04:05"), - Alias: (*Alias)(&c), - }) -} diff --git a/request/binding_pay_confirm_request.go b/request/binding_pay_confirm_request.go deleted file mode 100644 index 6240dfb..0000000 --- a/request/binding_pay_confirm_request.go +++ /dev/null @@ -1,8 +0,0 @@ -package request - -type BindingPayConfirmRequest struct { - PaymentNo string `json:"paymentNo" form:"paymentNo"` - SmsCode string `json:"smsCode" form:"smsCode"` - ThpInfo string `json:"thpInfo" form:"thpInfo"` - AgreeID string `json:"agreeId" form:"agreeId"` -} diff --git a/request/binding_pay_sms_request.go b/request/binding_pay_sms_request.go deleted file mode 100644 index 32c78a9..0000000 --- a/request/binding_pay_sms_request.go +++ /dev/null @@ -1,7 +0,0 @@ -package request - -type BindingPaySmsRequest struct { - PaymentNo string `json:"paymentNo" form:"paymentNo"` - ThpInfo string `json:"thpInfo" form:"thpInfo"` - AgreeID string `json:"agreeId" form:"agreeId"` -} diff --git a/request/check_out_order_request.go b/request/check_out_order_request.go deleted file mode 100644 index 8da30aa..0000000 --- a/request/check_out_order_request.go +++ /dev/null @@ -1,23 +0,0 @@ -package request - -type CheckOutOrderRequest struct { - Intent string `json:"intent"` - PurchaseUnits []PurchaseUnit `json:"purchase_units"` - ApplicationContext ApplicationContext `json:"application_context"` -} - -type PurchaseUnit struct { - Amount Amount `json:"amount"` - Description string `json:"description"` - CustomId int `json:"custom_id"` -} - -type Amount struct { - CurrencyCode string `json:"currency_code"` - Value string `json:"value"` -} - -type ApplicationContext struct { - CancelUrl string `json:"cancel_url"` - ReturnUrl string `json:"return_url"` -} diff --git a/request/manage/add_admin_request.go b/request/manage/add_admin_request.go deleted file mode 100644 index 2346f73..0000000 --- a/request/manage/add_admin_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package manage - -type AddAdminRequest struct { - Username string `json:"username"` - Password string `json:"password"` -} diff --git a/request/manage/login_request.go b/request/manage/login_request.go deleted file mode 100644 index 9f823d8..0000000 --- a/request/manage/login_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package manage - -type LoginRequest struct { - Username string `json:"username"` - Password string `json:"password"` -} diff --git a/request/manage/order_query_request.go b/request/manage/order_query_request.go deleted file mode 100644 index 8e4735c..0000000 --- a/request/manage/order_query_request.go +++ /dev/null @@ -1,10 +0,0 @@ -package manage - -import "gold-shop/request" - -type OrderQueryRequest struct { - request.PageQueryRequest - UserID int `form:"userId"` - Mobile string `form:"mobile"` - OrderNo string `form:"orderNo"` -} diff --git a/request/manage/payment_query_request.go b/request/manage/payment_query_request.go deleted file mode 100644 index 0d72af6..0000000 --- a/request/manage/payment_query_request.go +++ /dev/null @@ -1,11 +0,0 @@ -package manage - -import "gold-shop/request" - -type PaymentQueryRequest struct { - request.PageQueryRequest - UserID int `form:"userId"` - Mobile string `form:"mobile"` - PaymentNo string `form:"paymentNo"` - Status string `form:"status"` -} diff --git a/request/manage/user_query_request.go b/request/manage/user_query_request.go deleted file mode 100644 index 0a268d5..0000000 --- a/request/manage/user_query_request.go +++ /dev/null @@ -1,9 +0,0 @@ -package manage - -import "gold-shop/request" - -type UserQueryRequest struct { - request.PageQueryRequest - Mobile string `form:"mobile"` - Status string `form:"status"` -} diff --git a/request/order_query_request.go b/request/order_query_request.go deleted file mode 100644 index 67d0268..0000000 --- a/request/order_query_request.go +++ /dev/null @@ -1,5 +0,0 @@ -package request - -type OrderQueryRequest struct { - PageQueryRequest -} diff --git a/request/order_request.go b/request/order_request.go deleted file mode 100644 index 6a65763..0000000 --- a/request/order_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package request - -type OrderRequest struct { - ProductID int `json:"productId" form:"productId"` - Num int `json:"num" form:"num"` -} diff --git a/request/page_query_request.go b/request/page_query_request.go deleted file mode 100644 index f87a41d..0000000 --- a/request/page_query_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package request - -type PageQueryRequest struct { - Page int `form:"page"` - PageSize int `form:"pageSize"` -} diff --git a/request/payment_notify_request.go b/request/payment_notify_request.go deleted file mode 100644 index 786ecf7..0000000 --- a/request/payment_notify_request.go +++ /dev/null @@ -1,18 +0,0 @@ -package request - -type PaymentNotifyRequest struct { - OrderID string `form:"orderid"` - TradeNo string `form:"trade_no"` - DisName string `form:"dis_name"` - PayStatus int `form:"paystatus"` - PayMoney float64 `form:"paymoney"` - PriPayMoney float64 `form:"pri_paymoney"` - OrderTime int64 `form:"order_time"` - PayTime int64 `form:"paytime"` - MchOrderID string `form:"mch_orderid"` - NotifyUrl string `form:"notify_url"` - BuyerAccount string `form:"buyer_account"` - Attach string `form:"attach"` - Sign string `form:"sign"` - SignType string `form:"sign_type"` -} diff --git a/request/payment_query_request.go b/request/payment_query_request.go deleted file mode 100644 index f98fcf7..0000000 --- a/request/payment_query_request.go +++ /dev/null @@ -1,5 +0,0 @@ -package request - -type PaymentQueryRequest struct { - PageQueryRequest -} diff --git a/request/payment_request.go b/request/payment_request.go deleted file mode 100644 index 2a41b2d..0000000 --- a/request/payment_request.go +++ /dev/null @@ -1,9 +0,0 @@ -package request - -type PaymentRequest struct { - OpenID string `json:"openId" form:"openId"` - Amount float64 `json:"amount" form:"amount"` - PayType string `json:"payType" form:"payType"` - AgreeID string `json:"agreeId" form:"agreeId"` - ThpInfo string `json:"thpInfo" form:"thpInfo"` -} diff --git a/request/tl_binding_apply_request.go b/request/tl_binding_apply_request.go deleted file mode 100644 index 8ab91f1..0000000 --- a/request/tl_binding_apply_request.go +++ /dev/null @@ -1,11 +0,0 @@ -package request - -type TlBindingApplyRequest struct { - IdNo string `json:"idNo" form:"idNo"` - AcctName string `json:"acctName" form:"acctName"` - AcctNo string `json:"acctNo" form:"acctNo"` - AcctType string `json:"acctType" form:"acctType"` - Mobile string `json:"mobile" form:"mobile"` - ValidDate string `json:"validDate" form:"validDate"` - Cvv2 string `json:"cvv2" form:"cvv2"` -} diff --git a/request/tl_binding_confirm_request.go b/request/tl_binding_confirm_request.go deleted file mode 100644 index 9f8b0a7..0000000 --- a/request/tl_binding_confirm_request.go +++ /dev/null @@ -1,13 +0,0 @@ -package request - -type TlBindingConfirmRequest struct { - IdNo string `json:"idNo" form:"idNo"` - AcctName string `json:"acctName" form:"acctName"` - AcctNo string `json:"acctNo" form:"acctNo"` - AcctType string `json:"acctType" form:"acctType"` - Mobile string `json:"mobile" form:"mobile"` - ValidDate string `json:"validDate" form:"validDate"` - Cvv2 string `json:"cvv2" form:"cvv2"` - SmsCode string `json:"smsCode" form:"smsCode"` - ThpInfo string `json:"thpInfo" form:"thpInfo"` -} diff --git a/request/transfer_pay_notify_request.go b/request/transfer_pay_notify_request.go deleted file mode 100644 index 6480773..0000000 --- a/request/transfer_pay_notify_request.go +++ /dev/null @@ -1,17 +0,0 @@ -package request - -type TransferPayNotifyRequest struct { - OutOrderID string `json:"out_orderid"` - ApiKey string `json:"apikey"` - PayerCardNo string `json:"payer_card_no"` - OrderID string `json:"orderid"` - PayerAccountName string `json:"payer_account_name"` - OrderMoney string `json:"order_money"` - PayeeAccountName string `json:"payee_account_name"` - PayeeBankName string `json:"payee_bank_name"` - PayMoney string `json:"pay_money"` - PayTime string `json:"pay_time"` - PayeeCardNo string `json:"payee_card_no"` - PayStatus string `json:"pay_status"` - AddTime string `json:"add_time"` -} diff --git a/route/h5.go b/route/h5.go deleted file mode 100644 index fd4a372..0000000 --- a/route/h5.go +++ /dev/null @@ -1,47 +0,0 @@ -package route - -import ( - "github.com/gin-gonic/gin" - "gold-shop/api/h5" - "gold-shop/middleware" - "gold-shop/utils/result" -) - -func h5RouteInit(r *gin.Engine) { - h5Group := r.Group("/h5") - h5Group.Use(middleware.CorsMiddleware("h5")) - h5Group.Match([]string{"POST", "OPTIONS"}, "/login", result.Json(h5.Login)) - h5Group.Match([]string{"POST", "OPTIONS"}, "/register", result.Json(h5.Register)) - h5Group.Match([]string{"GET", "OPTIONS"}, "/get-product-info", result.Json(h5.GetProductInfo)) - h5Group.Match([]string{"POST", "OPTIONS"}, "/transfer-pay-notify", h5.TransferPayNotify) - h5Group.Match([]string{"POST", "OPTIONS"}, "/payment-notify", h5.PaymentNotify) - h5Group.Match([]string{"POST", "OPTIONS"}, "/binding-pay-notify", h5.BindingPayNotify) - h5Group.Match([]string{"GET", "OPTIONS"}, "/test-gateway-pay", h5.GatewayPay) - h5Group.Match([]string{"GET", "OPTIONS"}, "/gateway-pay", h5.GatewayPay) - h5Group.Match([]string{"POST", "GET", "OPTIONS"}, "/gateway-pay-ret", h5.GatewayPayRet) - - authGroup := h5Group.Group("") - authGroup.Use(middleware.JwtMiddleware("user")) - { - authGroup.Match([]string{"GET", "OPTIONS"}, "/ping", result.Json(h5.Index)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/error", result.Json(h5.Error)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-user-info", result.Json(h5.GetUserInfo)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/order", result.Json(h5.Order)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/modify-password", result.Json(h5.ModifyPassword)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/payment", result.Json(h5.Payment)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-wx-open-id", result.Json(h5.GetWxOpenId)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-wx-auth-url", result.Json(h5.GetWxAuthUrl)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-ali-open-id", result.Json(h5.GetAliOpenId)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-orders", result.Json(h5.GetOrders)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-payments", result.Json(h5.GetPayments)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-user-data", result.Json(h5.GetUserData)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/save-alipay-account", result.Json(h5.SaveAlipayAccount)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/tl-binding-apply", result.Json(h5.TlBindingApply)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/tl-binding-confirm", result.Json(h5.TlBindingConfirm)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-user-bank-card", result.Json(h5.GetUserBankCard)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/binding-pay-confirm", result.Json(h5.BindingPayConfirm)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/binding-pay-sms", result.Json(h5.BindingPaySms)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/gateway-pay-apply", result.Json(h5.GatewayPayApply)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/bank-card-unbind", result.Json(h5.BankCardUnbind)) - } -} diff --git a/route/manage.go b/route/manage.go deleted file mode 100644 index f225a0a..0000000 --- a/route/manage.go +++ /dev/null @@ -1,29 +0,0 @@ -package route - -import ( - "github.com/gin-gonic/gin" - "gold-shop/api/manage" - "gold-shop/middleware" - "gold-shop/utils/result" -) - -func adminRouteInit(r *gin.Engine) { - manageGroup := r.Group("/manage") - manageGroup.Use(middleware.CorsMiddleware("manage")) - manageGroup.Match([]string{"POST", "OPTIONS"}, "/login", result.Json(manage.Login)) - manageGroup.GET("/download", manage.DownloadUsers) - - authGroup := manageGroup.Group("") - authGroup.Use(middleware.JwtMiddleware("admin")) - { - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-admin-info", result.Json(manage.GetAdminInfo)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/logout", result.Json(manage.Logout)) - authGroup.Match([]string{"POST", "OPTIONS"}, "/add-admin", result.Json(manage.AddAdmin)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-users", result.Json(manage.GetUsers)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/download-users", manage.DownloadUsers) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-orders", result.Json(manage.GetOrders)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/download-orders", manage.DownloadOrders) - authGroup.Match([]string{"GET", "OPTIONS"}, "/get-payments", result.Json(manage.GetPayments)) - authGroup.Match([]string{"GET", "OPTIONS"}, "/download-payments", manage.DownloadPayments) - } -} diff --git a/route/common.go b/router/common.go similarity index 70% rename from route/common.go rename to router/common.go index 6438637..3ba98f6 100644 --- a/route/common.go +++ b/router/common.go @@ -1,11 +1,10 @@ -package route +package router import ( "github.com/gin-gonic/gin" ) func Initial(r *gin.Engine) { - r.Static("/asset", "./asset") h5RouteInit(r) adminRouteInit(r) } diff --git a/router/h5.go b/router/h5.go new file mode 100644 index 0000000..50652b3 --- /dev/null +++ b/router/h5.go @@ -0,0 +1,8 @@ +package router + +import ( + "github.com/gin-gonic/gin" +) + +func h5RouteInit(r *gin.Engine) { +} diff --git a/router/manage.go b/router/manage.go new file mode 100644 index 0000000..096bffa --- /dev/null +++ b/router/manage.go @@ -0,0 +1,8 @@ +package router + +import ( + "github.com/gin-gonic/gin" +) + +func adminRouteInit(r *gin.Engine) { +} diff --git a/middleware/cors_middleware.go b/router/middleware/cors_middleware.go similarity index 100% rename from middleware/cors_middleware.go rename to router/middleware/cors_middleware.go diff --git a/middleware/jwt_middleware.go b/router/middleware/jwt_middleware.go similarity index 91% rename from middleware/jwt_middleware.go rename to router/middleware/jwt_middleware.go index 322601c..6f63488 100644 --- a/middleware/jwt_middleware.go +++ b/router/middleware/jwt_middleware.go @@ -55,10 +55,10 @@ func JwtMiddleware(role string) gin.HandlerFunc { } if claims.Role == "user" { - user := service.UserService.GetUserInfo(claims.Identity) + user := service.UserService.GetInfo(claims.Identity) c.Set("user", user) } else if claims.Role == "admin" { - user := service.AdminService.GetAdminInfo(claims.Identity) + user := service.AdminService.GetInfo(claims.Identity) c.Set("admin", user) } diff --git a/middleware/test_middleware.go b/router/middleware/test_middleware.go similarity index 100% rename from middleware/test_middleware.go rename to router/middleware/test_middleware.go diff --git a/service/admin_service.go b/service/admin_service.go index 70edba7..8c05fae 100644 --- a/service/admin_service.go +++ b/service/admin_service.go @@ -1,65 +1,12 @@ package service -import ( - e "errors" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/model" - "gold-shop/utils" - "gorm.io/gorm" -) +import "insure/model" var AdminService = adminService{} type adminService struct { } -func (adminService) Login(username string, password string) (string, error) { - admin := &model.Admin{} - err := global.DB.Where("username", username).First(admin).Error - if e.Is(err, gorm.ErrRecordNotFound) { - return "", errors.NewBusinessError("账号或密码错误") - } - if utils.PasswordVerify(password, admin.PasswordHash) { - return utils.GenerateToken(admin.ID, "admin") - } - return "", errors.NewBusinessError("账号或密码错误") -} - -func (adminService) Add(username string, password string) error { - admin := &model.Admin{} - err := global.DB.Where("username", username).First(admin).Error - if err == nil { - return errors.NewBusinessError("账号已存在") - } - admin.Username = username - passwordHash, _ := utils.PasswordHash(password) - admin.PasswordHash = passwordHash - return global.DB.Save(admin).Error -} - -func (adminService) ModifyPassword(password string, oldPassword string, admin *model.Admin) error { - if !utils.PasswordVerify(oldPassword, admin.PasswordHash) { - return errors.NewBusinessError("旧密码错误") - } - passwordHash, _ := utils.PasswordHash(password) - admin.PasswordHash = passwordHash - return global.DB.Save(admin).Error -} - -func (adminService) ResetPassword(adminID int, password string) error { - admin := &model.Admin{} - err := global.DB.Where("id", adminID).First(admin).Error - if e.Is(err, gorm.ErrRecordNotFound) { - return errors.NewBusinessError("账号不存在") - } - passwordHash, _ := utils.PasswordHash(password) - admin.PasswordHash = passwordHash - return global.DB.Save(admin).Error -} - -func (adminService) GetAdminInfo(adminID int) *model.Admin { - admin := &model.Admin{} - global.DB.Where("id", adminID).First(admin) - return admin +func (adminService) GetInfo(id int) *model.Admin { + return &model.Admin{} } diff --git a/service/order_service.go b/service/order_service.go deleted file mode 100644 index 70d40da..0000000 --- a/service/order_service.go +++ /dev/null @@ -1,136 +0,0 @@ -package service - -import ( - e "errors" - "github.com/xuri/excelize/v2" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/model" - "gold-shop/request" - "gold-shop/request/manage" - "gold-shop/utils" - "gold-shop/utils/excel" - "gorm.io/gorm" - "time" -) - -var OrderService = orderService{} - -type orderService struct { -} - -func (orderService) Order(orderRequest request.OrderRequest, user *model.User) (*model.Order, error) { - product := &model.Product{} - err := global.DB.Where("id", orderRequest.ProductID).First(product).Error - if e.Is(err, gorm.ErrRecordNotFound) { - return nil, errors.NewBusinessError("商品不存在") - } - totalAmount := float64(orderRequest.Num) * product.Price - if user.Balance < totalAmount { - return nil, errors.NewBusinessError("账号余额不足") - } - - orderNo := utils.GenerateNo("order") - - tx := global.DB.Begin() - order := model.Order{} - order.OrderNo = orderNo - order.Amount = totalAmount - order.UserID = user.ID - err = global.DB.Save(&order).Error - if err != nil { - tx.Rollback() - return nil, errors.NewBusinessError("保存数据失败") - } - - orderProduct := model.OrderProduct{} - orderProduct.ProductID = orderRequest.ProductID - orderProduct.OrderNo = orderNo - orderProduct.Price = product.Price - orderProduct.Amount = totalAmount - orderProduct.Num = orderRequest.Num - err = global.DB.Save(&orderProduct).Error - if err != nil { - tx.Rollback() - return nil, errors.NewBusinessError("保存数据失败") - } - - global.DB.Model(user).Update("balance", gorm.Expr("balance - ?", totalAmount)) - tx.Commit() - - return &order, nil -} - -func (orderService) GetUserOrders(userID, page, pageSize int) ([]model.Order, int64) { - orders := make([]model.Order, pageSize) - offset := (page - 1) * pageSize - var total int64 - global.DB.Where("user_id", userID).Preload("OrderProducts").Offset(offset).Limit(pageSize).Find(&orders) - global.DB.Model(&model.Order{}).Where("user_id", userID).Count(&total) - return orders, total -} - -func (s *orderService) buildQuery(req manage.OrderQueryRequest) *gorm.DB { - tx := global.DB - if req.Mobile != "" { - var userIds []int - global.DB.Model(&model.User{}).Where("mobile", req.Mobile).Pluck("id", &userIds) - tx = tx.Where("user_id", userIds) - } - if req.OrderNo != "" { - tx = tx.Where("order_no", req.OrderNo) - } - if req.UserID != 0 { - tx = tx.Where("user_id", req.UserID) - } - return tx -} - -func (s *orderService) GetOrders(req manage.OrderQueryRequest) ([]model.Order, int64) { - orders := make([]model.Order, req.PageSize) - offset := (req.Page - 1) * req.PageSize - var total int64 - tx := s.buildQuery(req) - tx.Preload("OrderProducts").Preload("User").Order("id desc").Offset(offset).Limit(req.PageSize).Find(&orders) - tx.Model(&model.Order{}).Count(&total) - return orders, total -} - -func (s *orderService) GenerateOrdersExcel(req manage.OrderQueryRequest) *excelize.File { - pageSize := 200 - lastID := 0 - tx := s.buildQuery(req) - - f := excel.NewFile() - headers := []string{"订单号", "用户手机号", "购买份数", "订单总金额", "下单时间"} - excel.SetSimpleHeaders(headers, "Sheet1", f) - for { - orders := make([]model.Order, pageSize) - tx.Preload("OrderProducts").Preload("User").Where("id > ?", lastID).Limit(pageSize).Find(&orders) - count := len(orders) - if count == 0 { - break - } - s.buildOrdersExcel(orders, "Sheet1", f) - lastIndex := count - 1 - lastID = orders[lastIndex].ID - } - return f -} - -func (orderService) buildOrdersExcel(orders []model.Order, sheet string, f *excelize.File) { - row := 2 - for _, order := range orders { - col := 0 - num := 0 - for _, orderProduct := range order.OrderProducts { - num += orderProduct.Num - } - f.SetCellValue(sheet, excel.CellKey(row, &col), order.OrderNo) - f.SetCellValue(sheet, excel.CellKey(row, &col), order.User.Mobile) - f.SetCellValue(sheet, excel.CellKey(row, &col), num) - f.SetCellValue(sheet, excel.CellKey(row, &col), order.Amount) - f.SetCellValue(sheet, excel.CellKey(row, &col), order.CreatedAt.Format(time.DateTime)) - row++ - } -} diff --git a/service/payment_service.go b/service/payment_service.go deleted file mode 100644 index ee56e40..0000000 --- a/service/payment_service.go +++ /dev/null @@ -1,441 +0,0 @@ -package service - -import ( - "encoding/base64" - e "errors" - "fmt" - "github.com/xuri/excelize/v2" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/model" - "gold-shop/request" - "gold-shop/request/manage" - "gold-shop/utils" - "gold-shop/utils/excel" - "gold-shop/utils/payment" - "gold-shop/utils/result" - "gold-shop/utils/tlpay" - "gold-shop/utils/tlpay/notify" - "gold-shop/utils/tlpay/param" - "gorm.io/gorm" - "strconv" - "time" -) - -var PaymentService = paymentService{} - -type paymentService struct { -} - -func (paymentService) GetUserPayments(userID, page, pageSize int) ([]model.Payment, int64) { - payments := make([]model.Payment, pageSize) - offset := (page - 1) * pageSize - var total int64 - global.DB.Where("user_id", userID).Order("id desc").Offset(offset).Limit(pageSize).Find(&payments) - global.DB.Model(&model.Payment{}).Where("user_id", userID).Count(&total) - return payments, total -} - -func (s paymentService) Payment(userID int, paymentRequest request.PaymentRequest) (result.Data, error) { - p, err := s.createPayment(userID, paymentRequest) - if err != nil { - return nil, err - } - - data := result.Data{} - if paymentRequest.PayType == "wxgzh" { - data, err = s.wxPayment(paymentRequest, p.PaymentNo) - } else if paymentRequest.PayType == "alishh" { - data, err = s.aliPayment(paymentRequest, p.PaymentNo) - } else if paymentRequest.PayType == "transfer" { - data, err = s.transferPayment(paymentRequest, p) - } else if paymentRequest.PayType == "binding" { - data, err = s.bindingPayment(paymentRequest, p) - } else if paymentRequest.PayType == "gateway" { - data, err = s.getGatewayPayUrl(p) - } else { - err = errors.NewBusinessError("payType参数错误") - } - if err != nil { - p.Status = 2 - p.ErrorMessage = err.Error() - global.DB.Save(p) - return nil, err - } - - p.PayOrderID = data["orderId"].(string) - global.DB.Save(p) - fmt.Println(data) - return data, nil -} - -func (s paymentService) wxPayment(paymentRequest request.PaymentRequest, orderID string) (result.Data, error) { - param := payment.WxPayParam{} - param.Remark = "payment" - param.OrderId = orderID - param.OpenId = paymentRequest.OpenID - param.Amount = paymentRequest.Amount - param.NotifyUrl = "http://api.wrtcjt.com/h5/payment-notify" - res, err := payment.PayApi.WxPay(param) - if err != nil { - return nil, err - } - - if res.Status != payment.Success { - return nil, errors.NewBusinessError(res.Message) - } - - data := result.Data{ - "orderId": res.OrderID, - "paySign": res.PaySign, - "package": res.Package, - "signType": res.PaySignType, - "nonceStr": res.NonceStr, - "appId": res.AppId, - "timeStamp": res.Timestamp, - } - return data, nil -} - -func (s paymentService) aliPayment(paymentRequest request.PaymentRequest, orderID string) (result.Data, error) { - param := payment.AliPayParam{} - param.Remark = "payment" - param.OrderId = orderID - param.BuyerId = paymentRequest.OpenID - param.Amount = paymentRequest.Amount - param.NotifyUrl = "http://api.wrtcjt.com/h5/payment-notify" - res, err := payment.PayApi.AliPay(param) - if err != nil { - return nil, err - } - - if res.Status != payment.Success { - return nil, errors.NewBusinessError(res.Message) - } - - data := result.Data{ - "orderId": res.OrderID, - "tradeNo": res.TradeNo, - "paymentNo": orderID, - } - return data, nil -} - -func (s paymentService) transferPayment(paymentRequest request.PaymentRequest, p *model.Payment) (result.Data, error) { - param := payment.TransferPayParam{} - param.Remark = "payment" - param.OrderId = utils.GenerateNo("payment") - param.Amount = paymentRequest.Amount - param.NotifyUrl = "" - res, err := payment.PayApi.TransferPay(param) - if err != nil { - return nil, err - } - - if res.Status != payment.Success { - return nil, errors.NewBusinessError(res.Message) - } - - data := result.Data{ - "payeeAccountName": res.PayeeAccountName, - "payeeBankName": res.PayeeBankName, - "payeeCardNo": res.PayeeCardNo, - "orderID": res.OrderID, - "paymentNo": p.PaymentNo, - } - return data, nil -} - -func (s paymentService) bindingPayment(paymentRequest request.PaymentRequest, p *model.Payment) (result.Data, error) { - payParam := param.PayApplyAgreeParam{} - payParam.Amount = strconv.FormatFloat(paymentRequest.Amount*100, 'f', 0, 64) - payParam.AgreeID = paymentRequest.AgreeID - payParam.ReqSn = p.PaymentNo - payParam.Currency = "CNY" - payParam.Subject = "充值" - payParam.TrxReserve = "充值" - payParam.NotifyUrl = "http://api.wrtcjt.com/h5/binding-pay-notify" - res, err := tlpay.TLPay.PayApplyAgree(payParam) - if err != nil { - return nil, err - } - - if err != nil { - return nil, err - } - if res.RetCode != "SUCCESS" { - return nil, errors.NewBusinessError(res.RetMsg) - } - if res.TrxStatus != "1999" { - return nil, errors.NewBusinessError(res.ErrMsg) - } - - data := result.Data{ - "paymentNo": p.PaymentNo, - "orderId": res.TrxID, - "thpInfo": base64.StdEncoding.EncodeToString([]byte(res.ThpInfo)), - } - return data, nil -} - -func (s paymentService) ConfirmBindingPayment(req request.BindingPayConfirmRequest, user *model.User) (result.Data, error) { - pm := &model.Payment{} - err := global.DB.Where("user_id", user.ID).Where("payment_no", req.PaymentNo).Where("status", 0).First(&pm).Error - if err != nil { - return nil, err - } - thpInfo, err := base64.StdEncoding.DecodeString(req.ThpInfo) - if err != nil { - return nil, err - } - payParam := param.PayAgreeConfirmParam{} - payParam.AgreeID = req.AgreeID - payParam.ThpInfo = string(thpInfo) - payParam.ReqSn = req.PaymentNo - payParam.SmsCode = req.SmsCode - res, err := tlpay.TLPay.PayAgreeConfirm(payParam) - if err != nil { - return nil, err - } - - if err != nil { - return nil, err - } - if res.RetCode != "SUCCESS" { - return nil, errors.NewBusinessError(res.RetMsg) - } - - if res.TrxStatus != "0000" { - return nil, errors.NewBusinessError(res.ErrMsg) - } - - data := result.Data{ - "paymentNo": pm.PaymentNo, - "orderId": res.TrxID, - } - return data, nil -} - -func (s paymentService) SmsBindingPayment(req request.BindingPaySmsRequest, user *model.User) (result.Data, error) { - pm := &model.Payment{} - err := global.DB.Where("user_id", user.ID).Where("payment_no", req.PaymentNo).Where("status", 0).First(&pm).Error - if err != nil { - return nil, err - } - thpInfo, err := base64.StdEncoding.DecodeString(req.ThpInfo) - if err != nil { - return nil, err - } - smsParam := param.PaySmsAgreeParam{} - smsParam.AgreeID = req.AgreeID - smsParam.ThpInfo = string(thpInfo) - smsParam.OrderID = req.PaymentNo - res, err := tlpay.TLPay.PaySmsAgree(smsParam) - if err != nil { - return nil, err - } - - if err != nil { - return nil, err - } - if res.RetCode != "SUCCESS" { - return nil, errors.NewBusinessError(res.RetMsg) - } - - data := result.Data{ - "paymentNo": pm.PaymentNo, - } - return data, nil -} - -func (paymentService) createPayment(userID int, paymentRequest request.PaymentRequest) (*model.Payment, error) { - p := model.Payment{} - p.PaymentNo = utils.GenerateNo("payment") - p.Amount = paymentRequest.Amount - p.OpenID = paymentRequest.OpenID - p.PayType = paymentRequest.PayType - p.Status = 0 - p.UserID = userID - err := global.DB.Save(&p).Error - if err != nil { - return nil, errors.NewBusinessError("保存数据失败") - } - return &p, nil -} - -func (s *paymentService) buildQuery(req manage.PaymentQueryRequest) *gorm.DB { - tx := global.DB - if req.Mobile != "" { - var userIds []int - global.DB.Model(&model.User{}).Where("mobile", req.Mobile).Pluck("id", &userIds) - tx = tx.Where("user_id", userIds) - } - if req.PaymentNo != "" { - tx = tx.Where("payment_no", req.PaymentNo) - } - if req.Status != "" { - tx = tx.Where("status", req.Status) - } - if req.UserID != 0 { - tx = tx.Where("user_id", req.UserID) - } - return tx -} - -func (s *paymentService) GetPayments(req manage.PaymentQueryRequest) ([]model.Payment, int64) { - payments := make([]model.Payment, req.PageSize) - offset := (req.Page - 1) * req.PageSize - var total int64 - tx := s.buildQuery(req) - tx.Preload("User").Order("id desc").Offset(offset).Limit(req.PageSize).Find(&payments) - tx.Model(&model.Order{}).Count(&total) - return payments, total -} - -func (s *paymentService) GeneratePaymentsExcel(req manage.PaymentQueryRequest) *excelize.File { - pageSize := 200 - lastID := 0 - tx := s.buildQuery(req) - f := excel.NewFile() - headers := []string{"支付订单号", "用户手机号", "金额", "支付状态", "支付时间"} - excel.SetSimpleHeaders(headers, "Sheet1", f) - for { - payments := make([]model.Payment, pageSize) - tx.Preload("User").Where("id > ?", lastID).Limit(pageSize).Find(&payments) - count := len(payments) - if count == 0 { - break - } - s.buildPaymentsExcel(payments, "Sheet1", f) - lastIndex := count - 1 - lastID = payments[lastIndex].ID - } - return f -} - -func (paymentService) buildPaymentsExcel(payments []model.Payment, sheet string, f *excelize.File) { - row := 2 - for _, p := range payments { - col := 0 - f.SetCellValue(sheet, excel.CellKey(row, &col), p.PaymentNo) - f.SetCellValue(sheet, excel.CellKey(row, &col), p.User.Mobile) - f.SetCellValue(sheet, excel.CellKey(row, &col), p.Amount) - f.SetCellValue(sheet, excel.CellKey(row, &col), p.GetStatusText()) - f.SetCellValue(sheet, excel.CellKey(row, &col), p.CreatedAt.Format(time.DateTime)) - row++ - } -} - -func (s paymentService) AfterTransferPayNotify(req request.TransferPayNotifyRequest) error { - pm := &model.Payment{} - err := global.DB.Where("payment_no", req.OutOrderID).Where("status", 0).First(&pm).Error - if err != nil && e.Is(err, gorm.ErrRecordNotFound) { - return errors.NewBusinessError("记录不存在") - } - - user := model.User{} - global.DB.Model(&model.User{}).Where("id", pm.UserID).Find(&user) - - if req.PayStatus == "1" { - pm.Status = 1 - pm.PayerCardNo = req.PayerCardNo - pm.PayerAccountName = req.PayerAccountName - global.DB.Save(&user) - } else { - pm.Status = 2 - } - - err = global.DB.Save(&pm).Error - - return err -} - -func (s paymentService) AfterPaymentNotify(req request.PaymentNotifyRequest) error { - pm := &model.Payment{} - err := global.DB.Where("payment_no", req.MchOrderID).Where("status", 0).First(&pm).Error - if err != nil && e.Is(err, gorm.ErrRecordNotFound) { - return errors.NewBusinessError("记录不存在") - } - - user := model.User{} - global.DB.Model(&model.User{}).Where("id", pm.UserID).Find(&user) - - if req.PayStatus == 1 { - pm.Status = 1 - global.DB.Model(&user).UpdateColumn("balance", gorm.Expr("balance + ?", pm.Amount)) - } else { - pm.Status = 2 - } - - err = global.DB.Save(&pm).Error - - return err -} - -func (s paymentService) AfterBindingPayNotify(req notify.PayAgreeNotify) error { - pm := &model.Payment{} - err := global.DB.Where("payment_no", req.CusOrderID).Where("status", 0).First(&pm).Error - if err != nil && e.Is(err, gorm.ErrRecordNotFound) { - return errors.NewBusinessError("记录不存在") - } - - user := model.User{} - global.DB.Model(&model.User{}).Where("id", pm.UserID).Find(&user) - - if req.TrxStatus == "0000" { - pm.Status = 1 - global.DB.Model(&user).UpdateColumn("balance", gorm.Expr("balance + ?", pm.Amount)) - } else { - pm.Status = 2 - } - - err = global.DB.Save(&pm).Error - - return err -} - -func (s paymentService) GatewayPay(token string) (string, error) { - pm := &model.Payment{} - err := global.DB.Where("token", token).Where("status", 0).First(&pm).Error - - if err != nil { - return "", err - } - p := param.GatewayPayParam{} - p.OrderID = pm.PaymentNo - p.PayType = "B2B,B2C" - p.TrxAmt = strconv.FormatFloat(pm.Amount*100, 'f', 0, 64) - p.LimitPay = "no_credit" - p.RetUrl = "http://api.wrtcjt.com/h5/gateway-pay-ret" - //p.RetUrl = "https://www.baidu.com" - p.NotifyUrl = "http://api.wrtcjt.com/h5/binding-pay-notify" - p.GoodsID = "1" - p.GoodsInf = "充值" - p.Charset = "UTF-8" - - str := tlpay.TLPay.GatewayPay(p) - return str, nil -} - -func (s paymentService) GatewayPayRet(ret notify.GatewayPayRet) (string, error) { - return "", nil -} - -func (s paymentService) GatewayPayApply(userID int, paymentRequest request.PaymentRequest) (result.Data, error) { - pm, err := s.createPayment(userID, paymentRequest) - if err != nil { - return nil, err - } - return s.getGatewayPayUrl(pm) -} - -func (s paymentService) getGatewayPayUrl(pm *model.Payment) (result.Data, error) { - token := utils.Md5(pm.PaymentNo + strconv.Itoa(pm.UserID) + "_gateway") - pm.Token = token - err := global.DB.Save(pm).Error - if err != nil { - return nil, err - } - data := result.Data{"url": "http://api.wrtcjt.com/h5/gateway-pay?token=" + token, "orderId": ""} - return data, nil -} diff --git a/service/product_service.go b/service/product_service.go deleted file mode 100644 index 4cbcea1..0000000 --- a/service/product_service.go +++ /dev/null @@ -1,23 +0,0 @@ -package service - -import ( - e "errors" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/model" - "gorm.io/gorm" -) - -var ProductService = productService{} - -type productService struct { -} - -func (productService) GetProductInfo(productID int) (*model.Product, error) { - product := &model.Product{} - err := global.DB.Where("id", productID).First(product).Error - if e.Is(err, gorm.ErrRecordNotFound) { - return nil, errors.NewBusinessError("商品不存在") - } - return product, nil -} diff --git a/service/user_service.go b/service/user_service.go index 93e1ba9..3ce9b6c 100644 --- a/service/user_service.go +++ b/service/user_service.go @@ -1,306 +1,12 @@ package service -import ( - "encoding/base64" - e "errors" - "fmt" - "github.com/xuri/excelize/v2" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/model" - "gold-shop/request" - "gold-shop/request/manage" - "gold-shop/utils" - "gold-shop/utils/excel" - "gold-shop/utils/result" - "gold-shop/utils/tlpay" - "gold-shop/utils/tlpay/param" - "gorm.io/gorm" - "strconv" - "time" -) +import "insure/model" var UserService = userService{} type userService struct { } -func (userService) Login(mobile string, password string) (string, error) { - user := &model.User{} - err := global.DB.Where("mobile", mobile).First(user).Error - if e.Is(err, gorm.ErrRecordNotFound) { - return "", errors.NewBusinessError("手机号或密码错误") - } - if utils.PasswordVerify(password, user.PasswordHash) { - return utils.GenerateToken(user.ID, "user") - } - return "", errors.NewBusinessError("手机号或密码错误") -} - -func (userService) Register(mobile string, password string) error { - user := &model.User{} - err := global.DB.Where("mobile", mobile).First(user).Error - if err == nil { - return errors.NewBusinessError("手机号已注册") - } - user.Mobile = mobile - passwordHash, _ := utils.PasswordHash(password) - user.PasswordHash = passwordHash - user.Status = 1 - return global.DB.Save(user).Error -} - -func (userService) GetUserInfo(userId int) *model.User { - user := &model.User{} - global.DB.Where("id", userId).First(user) - return user -} - -func (userService) ModifyPassword(password string, oldPassword string, user *model.User) error { - if !utils.PasswordVerify(oldPassword, user.PasswordHash) { - return errors.NewBusinessError("旧密码错误") - } - passwordHash, _ := utils.PasswordHash(password) - user.PasswordHash = passwordHash - return global.DB.Save(user).Error -} - -func (userService) GetUserData(user *model.User) result.Data { - var orderCount int64 - global.DB.Model(&model.Order{}).Where("user_id", user.ID).Count(&orderCount) - data := result.Data{ - "orderCount": orderCount, - } - return data -} - -func (s *userService) GetUsers(req manage.UserQueryRequest) ([]model.User, int64) { - users := make([]model.User, req.PageSize) - offset := (req.Page - 1) * req.PageSize - var total int64 - tx := s.buildQuery(req) - tx.Order("id desc").Offset(offset).Limit(req.PageSize).Find(&users) - tx.Model(&model.User{}).Count(&total) - return users, total -} - -func (userService) SaveAlipayAccount(alipayAccount string, user *model.User) error { - err := global.DB.Model(&model.User{}).Where("id", user.ID).Update("alipay_account", alipayAccount).Error - return err -} - -func (s *userService) buildQuery(req manage.UserQueryRequest) *gorm.DB { - tx := global.DB - if req.Mobile != "" { - tx = tx.Where("mobile", req.Mobile) - } - if req.Status != "" { - tx = tx.Where("status", req.Status) - } - return tx -} - -func (s *userService) GenerateUsersExcel(req manage.UserQueryRequest) *excelize.File { - pageSize := 200 - lastID := 0 - tx := s.buildQuery(req) - f := excel.NewFile() - headers := []string{"用户ID", "手机号", "支付宝账号", "账户余额", "用户状态", "注册时间"} - excel.SetSimpleHeaders(headers, "Sheet1", f) - for { - users := make([]model.User, pageSize) - tx.Where("id > ?", lastID).Limit(pageSize).Find(&users) - count := len(users) - if count == 0 { - break - } - s.buildUserListExcel(users, "Sheet1", f) - lastIndex := count - 1 - lastID = users[lastIndex].ID - } - return f -} - -func (userService) buildUserListExcel(users []model.User, sheet string, f *excelize.File) { - row := 2 - for _, user := range users { - col := 0 - f.SetCellValue(sheet, excel.CellKey(row, &col), user.ID) - f.SetCellValue(sheet, excel.CellKey(row, &col), user.Mobile) - f.SetCellValue(sheet, excel.CellKey(row, &col), user.AlipayAccount) - f.SetCellValue(sheet, excel.CellKey(row, &col), user.Balance) - f.SetCellValue(sheet, excel.CellKey(row, &col), user.GetStatusText()) - f.SetCellValue(sheet, excel.CellKey(row, &col), user.CreatedAt.Format(time.DateTime)) - row++ - } -} - -func (s *userService) TlBindingApply(req request.TlBindingApplyRequest, user *model.User) (string, error) { - thpInfo, err := s.doTlBindingApply(req, user) - if err != nil { - return "", err - } - _, err = s.createBankCard(req, user) - if err != nil { - return "", err - } - return thpInfo, nil -} - -func (s *userService) doTlBindingApply(req request.TlBindingApplyRequest, user *model.User) (string, error) { - acctType := "00" - if req.AcctType != "" { - acctType = req.AcctType - } - p := param.AgreeApplyParam{} - p.Mobile = req.Mobile - p.IdNo = req.IdNo - p.Cvv2 = req.Cvv2 - p.AcctNo = req.AcctNo - p.AcctName = req.AcctName - p.ValidDate = req.ValidDate - p.MerUserID = strconv.Itoa(user.ID) - p.IdType = "0" - p.AcctType = acctType - p.ReqIp = "127.0.0.1" - p.Version = "11" - - r, err := tlpay.TLPay.AgreeApply(p) - fmt.Println(r) - if err != nil { - return "", err - } - if r.RetCode != "SUCCESS" { - return "", errors.NewBusinessError(r.RetMsg) - } - if r.TrxStatus != "1999" { - return "", errors.NewBusinessError(r.ErrMsg) - } - return base64.StdEncoding.EncodeToString([]byte(r.ThpInfo)), nil -} - -func (userService) createBankCard(req request.TlBindingApplyRequest, user *model.User) (*model.UserBankCard, error) { - c := model.UserBankCard{} - err := global.DB.Where("user_id", user.ID).Where("account_no", req.AcctNo).First(&c).Error - if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return nil, err - } - if err == nil && c.Status == 1 { - return nil, errors.NewBusinessError("该卡号已绑定") - } - c.AccountName = req.AcctName - c.IdCardNo = req.IdNo - c.AccountNo = req.AcctNo - c.Mobile = req.Mobile - c.Status = 0 - c.UserID = user.ID - err = global.DB.Save(&c).Error - if err != nil { - return nil, errors.NewBusinessError("保存数据失败") - } - return &c, nil -} - -func (s *userService) TlBindingConfirm(req request.TlBindingConfirmRequest, user *model.User) (result.Data, error) { - c := model.UserBankCard{} - err := global.DB.Where("user_id", user.ID).Where("account_no", req.AcctNo).First(&c).Error - if err != nil { - return nil, err - } - - data, err := s.doTlBindingConfirm(req, user) - if err != nil { - c.Status = 2 - c.ErrorMessage = err.Error() - global.DB.Save(&c) - return nil, err - } - c.AgreeID = data["agreeId"].(string) - c.Status = 1 - c.ErrorMessage = "成功" - c.BankName = data["bankName"].(string) - c.BankCode = data["bankCode"].(string) - global.DB.Save(&c) - return data, nil -} - -func (userService) doTlBindingConfirm(req request.TlBindingConfirmRequest, user *model.User) (result.Data, error) { - acctType := "00" - if req.AcctType != "" { - acctType = req.AcctType - } - thpInfo, err := base64.StdEncoding.DecodeString(req.ThpInfo) - if err != nil { - return nil, err - } - p := param.AgreeConfirmParam{} - p.Mobile = req.Mobile - p.IdNo = req.IdNo - p.Cvv2 = req.Cvv2 - p.AcctNo = req.AcctNo - p.AcctName = req.AcctName - p.SmsCode = req.SmsCode - p.ThpInfo = string(thpInfo) - p.ValidDate = req.ValidDate - p.MerUserID = strconv.Itoa(user.ID) - p.IdType = "0" - p.AcctType = acctType - p.ReqIp = "127.0.0.1" - p.Version = "11" - - r, err := tlpay.TLPay.AgreeConfirm(p) - fmt.Println(r) - if err != nil { - return nil, err - } - if r.RetCode != "SUCCESS" { - return nil, errors.NewBusinessError(r.RetMsg) - } - if r.TrxStatus != "0000" { - return nil, errors.NewBusinessError(r.ErrMsg) - } - data := result.Data{"agreeId": r.AgreeID, "bankCode": r.BankCode, "bankName": r.BankName} - return data, nil -} - -func (s *userService) GetBankCardByUserID(userID int) (*model.UserBankCard, error) { - c := model.UserBankCard{} - err := global.DB.Where("user_id", userID).Where("status", 1).First(&c).Error - fmt.Println(err) - if err != nil { - return nil, err - } - return &c, nil -} - -func (s *userService) BankCardUnbind(user *model.User) error { - c := model.UserBankCard{} - err := global.DB.Where("user_id", user.ID).Where("status", 1).First(&c).Error - if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { - return errors.NewBusinessError("银行卡不存在") - } - - if err != nil { - return err - } - - p := param.UnbindParam{} - p.AgreeID = c.AgreeID - p.ReqIp = "127.0.0.1" - p.Version = "11" - r, err := tlpay.TLPay.Unbind(p) - if err != nil { - return err - } - - if r.RetCode != "SUCCESS" { - return errors.NewBusinessError(r.RetMsg) - } - - c.Status = 3 - err = global.DB.Save(&c).Error - if err != nil { - return errors.NewBusinessError("更新失败") - } - return nil +func (userService) GetInfo(id int) *model.User { + return &model.User{} } diff --git a/system/application.go b/system/application.go deleted file mode 100644 index 9b140a3..0000000 --- a/system/application.go +++ /dev/null @@ -1 +0,0 @@ -package system diff --git a/third_party/alipay/index.go b/third_party/alipay/index.go new file mode 100644 index 0000000..e9800b2 --- /dev/null +++ b/third_party/alipay/index.go @@ -0,0 +1 @@ +package alipay diff --git a/utils/alipay/alipay_api.go b/utils/alipay/alipay_api.go deleted file mode 100644 index 5bc3065..0000000 --- a/utils/alipay/alipay_api.go +++ /dev/null @@ -1,111 +0,0 @@ -package alipay - -import ( - "encoding/json" - "fmt" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/utils" - "io" - "net/http" - "net/url" - "strings" - "time" -) - -var AlipayApi alipayApi = alipayApi{} - -type alipayApi struct { -} - -func (api alipayApi) GetAuthToken(code string) (*AuthTokenResult, error) { - - commonParam := api.buildCommonParam("alipay.system.oauth.token") - param := AuthTokenParam{} - param.CommonParam = commonParam - param.Code = code - param.GrantType = "authorization_code" - - p, err := utils.StructToURLValues(param) - if err != nil { - return nil, err - } - - sign, err := api.sign(p) - if err != nil { - return nil, err - } - p.Set("sign", sign) - - body, err := api.post(p) - if err != nil { - return nil, err - } - result := AuthTokenResult{} - err = json.Unmarshal(body, &result) - fmt.Println(result) - if err != nil { - return nil, errors.NewBusinessError("数据解析错误") - } - if result.Code != "10000" { - return nil, errors.NewBusinessError(result.Msg) - } - return &result, nil -} - -func (api alipayApi) buildCommonParam(method string) CommonParam { - param := CommonParam{} - param.AppID = global.Config.Payment.AliPay.SubAppId - param.Method = method - param.Format = "JSON" - param.Charset = "utf-8" - param.SignType = "RSA2" - param.Timestamp = time.Now().Format("2006-01-02 15:04:05") - param.Version = "1.0" - return param -} - -func (api *alipayApi) sign(params url.Values) (string, error) { - params.Del("sign") - for key, value := range params { - if len(value) == 0 || value[0] == "" { - params.Del(key) - } - } - signStr, err := url.QueryUnescape(params.Encode()) - if err != nil { - return "", err - } - - fmt.Println("signStr: " + signStr) - return utils.RSASign([]byte(signStr), global.Config.Payment.AliPay.SubPriPemFile) -} - -func (alipayApi) post(data url.Values) ([]byte, error) { - client := &http.Client{} - body := strings.NewReader(data.Encode()) - request, err := http.NewRequest("POST", "https://openapi.alipay.com/gateway.do", body) - request.Header.Set("content-type", "application/x-www-form-urlencoded") - - if err != nil { - return nil, errors.NewBusinessError("请求错误") - } - response, err := client.Do(request) - - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - - } - }(response.Body) - - bodyBytes, err := io.ReadAll(response.Body) - - fmt.Println(string(bodyBytes)) - - if err != nil { - return nil, errors.NewBusinessError("返回内容错误") - } - - return bodyBytes, nil -} diff --git a/utils/alipay/auth_token_param.go b/utils/alipay/auth_token_param.go deleted file mode 100644 index 3abaf11..0000000 --- a/utils/alipay/auth_token_param.go +++ /dev/null @@ -1,8 +0,0 @@ -package alipay - -type AuthTokenParam struct { - CommonParam - Code string `json:"code"` - GrantType string `json:"grant_type"` - RefreshToken string `json:"refresh_token"` -} diff --git a/utils/alipay/auth_token_result.go b/utils/alipay/auth_token_result.go deleted file mode 100644 index 3b37171..0000000 --- a/utils/alipay/auth_token_result.go +++ /dev/null @@ -1,12 +0,0 @@ -package alipay - -type AuthTokenResult struct { - CommonResult - AccessToken string `json:"access_token"` - ExpiresIn string `json:"expires_in"` - RefreshToken string `json:"refresh_token"` - ReExpiresIn string `json:"re_expires_in"` - OpenID string `json:"open_id"` - UserID string `json:"user_id"` - AuthStart string `json:"auth_start"` -} diff --git a/utils/alipay/common_param.go b/utils/alipay/common_param.go deleted file mode 100644 index 8e6452a..0000000 --- a/utils/alipay/common_param.go +++ /dev/null @@ -1,13 +0,0 @@ -package alipay - -type CommonParam struct { - AppID string `json:"app_id"` - Method string `json:"method"` - Format string `json:"format"` - Charset string `json:"charset"` - SignType string `json:"sign_type"` - Sign string `json:"sign"` - Timestamp string `json:"timestamp"` - Version string `json:"version"` - AppAuthToken string `json:"app_auth_token"` -} diff --git a/utils/alipay/common_result.go b/utils/alipay/common_result.go deleted file mode 100644 index ff6003d..0000000 --- a/utils/alipay/common_result.go +++ /dev/null @@ -1,9 +0,0 @@ -package alipay - -type CommonResult struct { - Code string `json:"code"` - Msg string `json:"msg"` - SubCode string `json:"sub_code"` - SubMsg string `json:"sub_msg"` - Sign string `json:"sign"` -} diff --git a/utils/custom/datetime.go b/utils/custom/datetime.go deleted file mode 100644 index f5ab29b..0000000 --- a/utils/custom/datetime.go +++ /dev/null @@ -1,13 +0,0 @@ -package custom - -import "time" - -type DateTime struct { - time.Time -} - -// MarshalJSON 实现json.Marshaler接口,自定义序列化格式 -func (dt DateTime) MarshalJSON() ([]byte, error) { - formatted := `"` + dt.Format("2006-01-02 15:04:05") + `"` - return []byte(formatted), nil -} diff --git a/utils/encrypt.go b/utils/encrypt.go index 3ff6a2d..443805a 100644 --- a/utils/encrypt.go +++ b/utils/encrypt.go @@ -12,11 +12,8 @@ import ( "errors" "fmt" "golang.org/x/crypto/bcrypt" - "io" - "net/http" "net/url" "os" - "strings" ) func Md5(str string) string { @@ -42,82 +39,6 @@ func PasswordVerify(password, hash string) bool { return err == nil } -func Post(url string, params url.Values) { - client := &http.Client{} - body := strings.NewReader(params.Encode()) - request, err := http.NewRequest("POST", url, body) - request.Header.Set("content-type", "application/x-www-form-urlencoded") - - if err != nil { - panic(err) - } - response, err := client.Do(request) - - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - - } - }(response.Body) - - bodyBytes, err := io.ReadAll(response.Body) - if err != nil { - panic(err) - } - fmt.Println(string(bodyBytes)) -} - -func Post1(url string, params url.Values) { - client := &http.Client{} - //reqBodyBytes, _ := json.Marshal(params) - //body := strings.NewReader(string(reqBodyBytes)) - body := strings.NewReader(params.Encode()) - request, err := http.NewRequest("POST", url, body) - request.SetBasicAuth("AUOi0TCR3m9_LGyxPGo15X2Nvvd6D-l8WTgTBMj39XqyzuFTwTPT3zxU11o0tWT8ouGZ4kFQv2mtmK7f", "EI7JYZQUOl4emunnuOMhCbqKFVFMxcO4Qk9ZctlrUu4h1Q_Gv_i-YDMhHv5Rt2J74lbEEPiuHb8Ot6eo") - request.Header.Set("content-type", "application/json") - if err != nil { - panic(err) - } - response, err := client.Do(request) - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - - } - }(response.Body) - - bodyBytes, err := io.ReadAll(response.Body) - if err != nil { - panic(err) - } - fmt.Println(string(bodyBytes)) -} - -func Post2(url string, params string, token string) { - client := &http.Client{} - body := strings.NewReader(params) - request, err := http.NewRequest("POST", url, body) - request.Header.Set("Content-Type", "application/json") - request.Header.Set("Accept", "application/json") - request.Header.Set("Authorization", "Bearer "+token) - if err != nil { - panic(err) - } - response, err := client.Do(request) - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - - } - }(response.Body) - - bodyBytes, err := io.ReadAll(response.Body) - if err != nil { - panic(err) - } - fmt.Println(string(bodyBytes)) -} - func RSASign(data []byte, filename string) (string, error) { // 1、选择hash算法,对需要签名的数据进行hash运算 myHash := crypto.SHA1 diff --git a/utils/payment/ali_pay_param.go b/utils/payment/ali_pay_param.go deleted file mode 100644 index 0b1c308..0000000 --- a/utils/payment/ali_pay_param.go +++ /dev/null @@ -1,9 +0,0 @@ -package payment - -type AliPayParam struct { - BuyerId string - Amount float64 - OrderId string - NotifyUrl string - Remark string -} diff --git a/utils/payment/ali_pay_result.go b/utils/payment/ali_pay_result.go deleted file mode 100644 index 3f1a4ae..0000000 --- a/utils/payment/ali_pay_result.go +++ /dev/null @@ -1,14 +0,0 @@ -package payment - -type AliPayResult struct { - TradeNo string `json:"trade_no"` - OrderID string `json:"orderid"` - OrderTime string `json:"order_time"` - MchOrderID string `json:"mch_orderid"` - Version string `json:"version"` - Charset string `json:"charset"` - Message string `json:"message"` - Status string `json:"status"` - SignType string `json:"sign_ype"` - Sign string `json:"sign"` -} diff --git a/utils/payment/const.go b/utils/payment/const.go deleted file mode 100644 index 6fd7122..0000000 --- a/utils/payment/const.go +++ /dev/null @@ -1,3 +0,0 @@ -package payment - -const Success = "10000" diff --git a/utils/payment/pay_api.go b/utils/payment/pay_api.go deleted file mode 100644 index 5f7d0d2..0000000 --- a/utils/payment/pay_api.go +++ /dev/null @@ -1,164 +0,0 @@ -package payment - -import ( - "encoding/json" - "fmt" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/utils" - "io" - "net/http" - "net/url" - "strconv" - "strings" -) - -var PayApi payApi = payApi{} - -type payApi struct { -} - -func (api *payApi) WxPay(param WxPayParam) (*WxPayResult, error) { - payment := global.Config.Payment - data := url.Values{} - data.Set("service", "comm.js.pay") - data.Set("apikey", payment.ApiKey) - data.Set("money", fmt.Sprintf("%.2f", param.Amount)) - data.Set("sub_appid", payment.WxPay.SubAppId) - data.Set("sub_openid", param.OpenId) - data.Set("nonce_str", utils.GenerateRandomString(32)) - data.Set("mch_orderid", param.OrderId) - data.Set("notify_url", param.NotifyUrl) - data.Set("remarks", param.Remark) - sign := api.sign(data, payment.SignKey) - data.Set("sign", sign) - fmt.Println(data.Encode()) - - data.Set("notify_url", url.QueryEscape(param.NotifyUrl)) - - res, err := api.post(payment.BaseUrl+"/payapi/mini/wxpay", data) - if err != nil { - return nil, err - } - result := WxPayResult{} - err = json.Unmarshal(res, &result) - if err != nil { - return nil, errors.NewBusinessError("结果解析错误") - } - return &result, nil -} - -func (api *payApi) AliPay(param AliPayParam) (*AliPayResult, error) { - payment := global.Config.Payment - data := url.Values{} - data.Set("service", "comm.js.pay") - data.Set("apikey", payment.ApiKey) - data.Set("money", fmt.Sprintf("%.2f", param.Amount)) - data.Set("sub_appid", payment.WxPay.SubAppId) - data.Set("buyer_id", param.OrderId) - data.Set("nonce_str", utils.GenerateRandomString(32)) - data.Set("mch_orderid", param.OrderId) - data.Set("notify_url", param.NotifyUrl) - data.Set("remarks", param.Remark) - sign := api.sign(data, payment.SignKey) - data.Set("sign", sign) - fmt.Println(data.Encode()) - - data.Set("notify_url", url.QueryEscape(param.NotifyUrl)) - - res, err := api.post(payment.BaseUrl+"/payapi/trade/alipay", data) - if err != nil { - return nil, err - } - result := AliPayResult{} - err = json.Unmarshal(res, &result) - if err != nil { - return nil, errors.NewBusinessError("结果解析错误") - } - return &result, nil -} - -func (api *payApi) QueryOrder(param QueryOrderParam) (*QueryOrderResult, error) { - payment := global.Config.Payment - data := url.Values{} - data.Set("service", "pay.comm.query_order") - data.Set("apikey", payment.ApiKey) - data.Set("orderid", param.OrderID) - data.Set("mch_orderid", param.MchOrderID) - data.Set("nonce_str", utils.GenerateRandomString(32)) - data.Set("order_time", strconv.Itoa(int(param.OrderTime))) - data.Set("dis_name", param.DisName) - sign := api.sign(data, payment.SignKey) - data.Set("sign", sign) - fmt.Println(data.Encode()) - res, err := api.post(payment.BaseUrl+"/payapi/pay/query_order", data) - if err != nil { - return nil, err - } - result := QueryOrderResult{} - err = json.Unmarshal(res, &result) - if err != nil { - return nil, errors.NewBusinessError("结果解析错误") - } - return &result, nil -} - -func (api *payApi) TransferPay(param TransferPayParam) (*TransferPayResult, error) { - payment := global.Config.Payment - data := url.Values{} - data.Set("service", "pay.heli.large_query") - data.Set("apikey", payment.ApiKey) - data.Set("order_money", fmt.Sprintf("%.2f", param.Amount)) - data.Set("nonce_str", utils.GenerateRandomString(32)) - data.Set("out_orderid", param.OrderId) - //data.Set("notify_url", param.NotifyUrl) - //data.Set("remark", param.Remark) - sign := api.sign(data, payment.SignKey) - data.Set("sign", sign) - fmt.Println(data.Encode()) - fmt.Println("url: " + payment.BaseUrl + "/payapi/pay/large_create") - res, err := api.post(payment.BaseUrl+"/payapi/pay/large_create", data) - if err != nil { - return nil, err - } - result := TransferPayResult{} - err = json.Unmarshal(res, &result) - if err != nil { - return nil, errors.NewBusinessError("结果解析错误") - } - return &result, nil -} - -func (payApi) sign(params url.Values, signKey string) string { - fmt.Println(params.Encode() + "&signkey=" + signKey) - return utils.Md5(params.Encode() + "&signkey=" + signKey) -} - -func (payApi) post(url string, data url.Values) ([]byte, error) { - client := &http.Client{} - body := strings.NewReader(data.Encode()) - request, err := http.NewRequest("POST", url, body) - request.Header.Set("content-type", "application/x-www-form-urlencoded") - - if err != nil { - return nil, errors.NewBusinessError("请求错误") - } - response, err := client.Do(request) - - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - - } - }(response.Body) - - bodyBytes, err := io.ReadAll(response.Body) - - fmt.Println(string(bodyBytes)) - - if err != nil { - return nil, errors.NewBusinessError("返回内容错误") - } - - return bodyBytes, nil -} diff --git a/utils/payment/query_order_param.go b/utils/payment/query_order_param.go deleted file mode 100644 index ceecbec..0000000 --- a/utils/payment/query_order_param.go +++ /dev/null @@ -1,8 +0,0 @@ -package payment - -type QueryOrderParam struct { - OrderID string - DisName string - MchOrderID string - OrderTime int64 -} diff --git a/utils/payment/query_order_result.go b/utils/payment/query_order_result.go deleted file mode 100644 index fbc5f3b..0000000 --- a/utils/payment/query_order_result.go +++ /dev/null @@ -1,25 +0,0 @@ -package payment - -type QueryOrderResult struct { - OrderID string `form:"orderid"` - TradeNo string `form:"trade_no"` - DisName string `form:"dis_name"` - PayStatus int `form:"paystatus"` - PayMoney float64 `form:"paymoney"` - PriPayMoney float64 `form:"pri_paymoney"` - OrderTime int64 `form:"order_time"` - PayTime int64 `form:"paytime"` - MchOrderID string `form:"mch_orderid"` - NotifyUrl string `form:"notify_url"` - BuyerAccount string `form:"buyer_account"` - Attach string `form:"attach"` - ReceiptAmount float64 `form:"receipt_amount"` - BuyerPayAmount float64 `form:"buyer_pay_amount"` - CouponFee float64 `form:"coupon_fee"` - Version string `form:"version"` - Charset string `form:"charset"` - Message string `form:"message"` - Status string `form:"status"` - Sign string `form:"sign"` - SignType string `form:"sign_type"` -} diff --git a/utils/payment/transfer_pay_param.go b/utils/payment/transfer_pay_param.go deleted file mode 100644 index a8e947d..0000000 --- a/utils/payment/transfer_pay_param.go +++ /dev/null @@ -1,9 +0,0 @@ -package payment - -type TransferPayParam struct { - OpenId string - Amount float64 - OrderId string - NotifyUrl string - Remark string -} diff --git a/utils/payment/transfer_pay_result.go b/utils/payment/transfer_pay_result.go deleted file mode 100644 index 30ab28d..0000000 --- a/utils/payment/transfer_pay_result.go +++ /dev/null @@ -1,16 +0,0 @@ -package payment - -type TransferPayResult struct { - Service string `json:"service"` - OrderID string `json:"orderid"` - OutOrderID string `json:"out_orderid"` - OrderMoney string `json:"order_money"` - PayeeAccountName string `json:"payee_account_name"` - PayeeCardNo string `json:"payee_card_no"` - PayeeBankName string `json:"payee_bank_name"` - Version string `json:"version"` - Message string `json:"message"` - Status string `json:"status"` - SignType string `json:"sign_ype"` - Sign string `json:"sign"` -} diff --git a/utils/payment/wx_pay_param.go b/utils/payment/wx_pay_param.go deleted file mode 100644 index 6bb6358..0000000 --- a/utils/payment/wx_pay_param.go +++ /dev/null @@ -1,9 +0,0 @@ -package payment - -type WxPayParam struct { - OpenId string - Amount float64 - OrderId string - NotifyUrl string - Remark string -} diff --git a/utils/payment/wx_pay_result.go b/utils/payment/wx_pay_result.go deleted file mode 100644 index 5a508bc..0000000 --- a/utils/payment/wx_pay_result.go +++ /dev/null @@ -1,23 +0,0 @@ -package payment - -type WxPayResult struct { - AppId string `json:"appId"` - Timestamp string `json:"timeStamp"` - NonceStr string `json:"nonceStr"` - Package string `json:"package"` - PaySign string `json:"paySign"` - PaySignType string `json:"signType"` - Service string `json:"service"` - OrderID string `json:"orderid"` - OrderTime string `json:"order_time"` - MchOrderID string `json:"mch_orderid"` - QrCode string `json:"qr_code"` - TradeType string `json:"trade_type"` - PrepayId string `json:"prepay_id"` - Version string `json:"version"` - Charset string `json:"charset"` - Message string `json:"message"` - Status string `json:"status"` - SignType string `json:"sign_ype"` - Sign string `json:"sign"` -} diff --git a/utils/tlpay/api.go b/utils/tlpay/api.go deleted file mode 100644 index c7b65aa..0000000 --- a/utils/tlpay/api.go +++ /dev/null @@ -1,276 +0,0 @@ -package tlpay - -import ( - "encoding/json" - "fmt" - "gold-shop/errors" - "gold-shop/global" - "gold-shop/utils" - "gold-shop/utils/tlpay/param" - "gold-shop/utils/tlpay/result" - "io" - "net/http" - "net/url" - "strings" - "time" -) - -var TLPay tlPay = tlPay{} - -type tlPay struct { -} - -func (api *tlPay) AgreeApply(p param.AgreeApplyParam) (*result.AgreeApplyResult, error) { - payConfig := global.Config.TlPay - data, err := utils.StructToURLValues(p) - data = api.SetCommonParams(data, true) - sign, err := api.sign(data) - if err != nil { - return nil, err - } - fmt.Println(sign) - data.Set("sign", sign) - res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/agreeapply", data) - if err != nil { - return nil, err - } - r := result.AgreeApplyResult{} - err = json.Unmarshal(res, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -func (api *tlPay) AgreeConfirm(p param.AgreeConfirmParam) (*result.AgreeConfirmResult, error) { - payConfig := global.Config.TlPay - data, err := utils.StructToURLValues(p) - data = api.SetCommonParams(data, true) - sign, err := api.sign(data) - if err != nil { - return nil, err - } - fmt.Println(sign) - data.Set("sign", sign) - res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/agreeconfirm", data) - if err != nil { - return nil, err - } - r := result.AgreeConfirmResult{} - err = json.Unmarshal(res, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -func (api *tlPay) Unbind(p param.UnbindParam) (*result.CommonResult, error) { - payConfig := global.Config.TlPay - data, err := utils.StructToURLValues(p) - data = api.SetCommonParams(data, true) - sign, err := api.sign(data) - if err != nil { - return nil, err - } - fmt.Println(sign) - data.Set("sign", sign) - res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/unbind", data) - if err != nil { - return nil, err - } - r := result.CommonResult{} - err = json.Unmarshal(res, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -func (api *tlPay) PayApplyAgree(p param.PayApplyAgreeParam) (*result.PayApplyAgreeResult, error) { - payConfig := global.Config.TlPay - data, err := utils.StructToURLValues(p) - data = api.SetCommonParams(data, true) - sign, err := api.sign(data) - if err != nil { - return nil, err - } - fmt.Println(sign) - data.Set("sign", sign) - res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/payapplyagree", data) - if err != nil { - return nil, err - } - r := result.PayApplyAgreeResult{} - err = json.Unmarshal(res, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -func (api *tlPay) PayAgreeConfirm(p param.PayAgreeConfirmParam) (*result.PayAgreeConfirmResult, error) { - payConfig := global.Config.TlPay - data, err := utils.StructToURLValues(p) - data = api.SetCommonParams(data, true) - sign, err := api.sign(data) - if err != nil { - return nil, err - } - fmt.Println(sign) - data.Set("sign", sign) - res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/payagreeconfirm", data) - if err != nil { - return nil, err - } - r := result.PayAgreeConfirmResult{} - err = json.Unmarshal(res, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -func (api *tlPay) PaySmsAgree(p param.PaySmsAgreeParam) (*result.PaySmsAgreeResult, error) { - payConfig := global.Config.TlPay - data, err := utils.StructToURLValues(p) - data = api.SetCommonParams(data, true) - sign, err := api.sign(data) - if err != nil { - return nil, err - } - fmt.Println(sign) - data.Set("sign", sign) - res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/paysmsagree", data) - if err != nil { - return nil, err - } - r := result.PaySmsAgreeResult{} - err = json.Unmarshal(res, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -func (api *tlPay) SetCommonParams(data url.Values, isNeedReqTime bool) url.Values { - payConfig := global.Config.TlPay - data.Set("cusid", payConfig.CusID) - data.Set("appid", payConfig.AppId) - data.Set("randomstr", utils.GenerateRandomString(32)) - if isNeedReqTime { - data.Set("reqtime", time.Now().Format("20060102150405")) - } - data.Set("signtype", "RSA") - return data -} - -func (api *tlPay) sign(params url.Values) (string, error) { - payConfig := global.Config.TlPay - params.Del("sign") - for key, value := range params { - if len(value) == 0 || value[0] == "" { - params.Del(key) - } - } - signStr, err := url.QueryUnescape(params.Encode()) - if err != nil { - return "", err - } - - fmt.Println("signStr: " + signStr) - return utils.RSASign([]byte(signStr), payConfig.PriPemFile) -} - -func (api *tlPay) Verify(params url.Values) error { - payConfig := global.Config.TlPay - sign := params.Get("sign") - params.Del("sign") - for key, value := range params { - if len(value) == 0 || value[0] == "" { - params.Del(key) - } - } - //signStr, err := url.QueryUnescape(params.Encode()) - //if err != nil { - // return err - //} - signStr := params.Encode() - - fmt.Println("sign: ", sign) - fmt.Println("signStr: ", signStr) - return utils.RSAVerify([]byte(signStr), sign, payConfig.PriPemFile) -} - -func (api *tlPay) post(url string, data url.Values) ([]byte, error) { - client := &http.Client{} - body := strings.NewReader(data.Encode()) - - fmt.Println("url: " + url) - fmt.Println("data: " + data.Encode()) - request, err := http.NewRequest("POST", url, body) - request.Header.Set("content-type", "application/x-www-form-urlencoded") - if err != nil { - return nil, errors.NewBusinessError("请求错误") - } - response, err := client.Do(request) - - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - - } - }(response.Body) - - bodyBytes, err := io.ReadAll(response.Body) - - fmt.Println("res: ", string(bodyBytes)) - - if err != nil { - return nil, errors.NewBusinessError("返回内容错误") - } - - return bodyBytes, nil -} - -func (api *tlPay) GatewayPay(p param.GatewayPayParam) string { - data, _ := utils.StructToURLValues(p) - data = api.SetCommonParams(data, false) - sign, _ := api.sign(data) - data.Set("sign", sign) - return api.BuildForm(data) -} - -func (api *tlPay) BuildForm(data url.Values) string { - htmlBegin := ` - - - - 充值 - - - - ` - - htmlEnd := - ` - - ` - return htmlBegin + api.buildFormHtml(data) + htmlEnd -} - -func (api *tlPay) buildFormHtml(data url.Values) string { - payConfig := global.Config.TlPay - formUrl := payConfig.BaseUrl + "/apiweb/gateway/pay" - formHtml := "
" - for key, value := range data { - formHtml += "" - } - - //formHtml += "" - formHtml += "
" - return formHtml -} diff --git a/utils/tlpay/notify/gateway_pay_ret.go b/utils/tlpay/notify/gateway_pay_ret.go deleted file mode 100644 index d6daf02..0000000 --- a/utils/tlpay/notify/gateway_pay_ret.go +++ /dev/null @@ -1,16 +0,0 @@ -package notify - -type GatewayPayRet struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - TrxCode string `json:"trxcode" form:"trxcode"` - TrxID string `json:"trxid" form:"trxid"` - TrxAmt string `json:"trxamt" form:"trxamt"` - TrxDate string `json:"trxdate" form:"trxdate"` - PayTime string `json:"paytime" form:"paytime"` - TrxStatus string `json:"trxstatus" form:"trxstatus"` - TrxReserved string `json:"trxreserved" form:"trxreserved"` - CusOrderID string `json:"cusorderid" form:"cusorderid"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` -} diff --git a/utils/tlpay/notify/pay_agree_notify.go b/utils/tlpay/notify/pay_agree_notify.go deleted file mode 100644 index da93127..0000000 --- a/utils/tlpay/notify/pay_agree_notify.go +++ /dev/null @@ -1,36 +0,0 @@ -package notify - -type PayAgreeNotify struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - OutTrxID string `json:"outTrxid" form:"outtrxid"` - TrxCode string `json:"trxcode" form:"trxcode"` - TrxID string `json:"trxid" form:"trxid"` - InitAmt string `json:"initamt" form:"initamt"` - TrxAmt string `json:"trxamt" form:"trxamt"` - TrxDate string `json:"trxdate" form:"trxdate"` - PayTime string `json:"paytime" form:"paytime"` - ChannelTrxID string `json:"chnltrxid" form:"chnltrxid"` - TrxStatus string `json:"trxstatus" form:"trxstatus"` - - TermNo string `json:"termno" form:"termno"` - TermBatchID string `json:"termbatchid" form:"termbatchid"` - TermTraceNo string `json:"termtraceno" form:"termtraceno"` - TermAuthNo string `json:"termauthno" form:"termauthno"` - TermRefNum string `json:"termrefnum" form:"termrefnum"` - - TrxReserved string `json:"trxreserved" form:"trxreserved"` - SrcTrxID string `json:"srctrxid" form:"srctrxid"` - CusOrderID string `json:"cusorderid" form:"cusorderid"` - Acct string `json:"acct" form:"acct"` - Fee string `json:"fee" form:"fee"` - CmID string `json:"cmid" form:"cmid"` - ChannelID string `json:"chnlid" form:"chnlid"` - ChannelData string `json:"chnldata" form:"chnldata"` - AcctType string `json:"accttype" form:"accttype"` - BankCode string `json:"bankcode" form:"bankcode"` - LogOnID string `json:"logonid" form:"logonid"` - - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` -} diff --git a/utils/tlpay/param/agree_apply_param.go b/utils/tlpay/param/agree_apply_param.go deleted file mode 100644 index addca4e..0000000 --- a/utils/tlpay/param/agree_apply_param.go +++ /dev/null @@ -1,22 +0,0 @@ -package param - -type AgreeApplyParam struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - ReqTime string `json:"reqtime" form:"reqtime"` - ReqIp string `json:"reqip" form:"reqip"` - Version string `json:"version" form:"version"` - RandomStr string `json:"randomstr" form:"randomstr"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` - - MerUserID string `json:"meruserid" form:"meruserid"` - AcctType string `json:"accttype" form:"accttype"` - AcctNo string `json:"acctno" form:"acctno"` - IdType string `json:"idtype" form:"idtype"` - IdNo string `json:"idno" form:"idno"` - AcctName string `json:"acctname" form:"acctname"` - Mobile string `json:"mobile" form:"mobile"` - ValidDate string `json:"validdate" form:"validdate"` - Cvv2 string `json:"cvv2" form:"cvv2"` -} diff --git a/utils/tlpay/param/agree_confirm_param.go b/utils/tlpay/param/agree_confirm_param.go deleted file mode 100644 index dd2e23b..0000000 --- a/utils/tlpay/param/agree_confirm_param.go +++ /dev/null @@ -1,24 +0,0 @@ -package param - -type AgreeConfirmParam struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - ReqTime string `json:"reqtime" form:"reqtime"` - ReqIp string `json:"reqip" form:"reqip"` - Version string `json:"version" form:"version"` - RandomStr string `json:"randomstr" form:"randomstr"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` - - MerUserID string `json:"meruserid" form:"meruserid"` - AcctType string `json:"accttype" form:"accttype"` - AcctNo string `json:"acctno" form:"acctno"` - IdType string `json:"idtype" form:"idtype"` - IdNo string `json:"idno" form:"idno"` - AcctName string `json:"acctname" form:"acctname"` - Mobile string `json:"mobile" form:"mobile"` - ValidDate string `json:"validdate" form:"validdate"` - Cvv2 string `json:"cvv2" form:"cvv2"` - SmsCode string `json:"smscode" form:"smscode"` - ThpInfo string `json:"thpinfo" form:"thpinfo"` -} diff --git a/utils/tlpay/param/gateway_pay_param.go b/utils/tlpay/param/gateway_pay_param.go deleted file mode 100644 index 31bbc29..0000000 --- a/utils/tlpay/param/gateway_pay_param.go +++ /dev/null @@ -1,22 +0,0 @@ -package param - -type GatewayPayParam struct { - OrgID string `json:"orgid" form:"orgid"` - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - Charset string `json:"charset" form:"charset"` - RandomStr string `json:"randomstr" form:"randomstr"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` - - RetUrl string `json:"returl" form:"returl"` - NotifyUrl string `json:"notifyurl" form:"notifyurl"` - GoodsID string `json:"goodsid" form:"goodsid"` - GoodsInf string `json:"goodsinf" form:"goodsinf"` - TrxAmt string `json:"trxamt" form:"trxamt"` - OrderID string `json:"orderid" form:"orderid"` - GateID string `json:"gateid" form:"gateid"` - PayType string `json:"paytype" form:"paytype"` - LimitPay string `json:"limitpay" form:"limitpay"` - ValidTime string `json:"validtime" form:"validtime"` -} diff --git a/utils/tlpay/param/pay_agree_confirm_param.go b/utils/tlpay/param/pay_agree_confirm_param.go deleted file mode 100644 index ddfe677..0000000 --- a/utils/tlpay/param/pay_agree_confirm_param.go +++ /dev/null @@ -1,17 +0,0 @@ -package param - -type PayAgreeConfirmParam struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - ReqTime string `json:"reqtime" form:"reqtime"` - ReqIp string `json:"reqip" form:"reqip"` - Version string `json:"version" form:"version"` - RandomStr string `json:"randomstr" form:"randomstr"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` - - ReqSn string `json:"reqsn" form:"reqsn"` - AgreeID string `json:"agreeid" form:"agreeid"` - SmsCode string `json:"smscode" form:"smscode"` - ThpInfo string `json:"thpinfo" form:"thpinfo"` -} diff --git a/utils/tlpay/param/pay_apply_agree_param.go b/utils/tlpay/param/pay_apply_agree_param.go deleted file mode 100644 index 13cdf17..0000000 --- a/utils/tlpay/param/pay_apply_agree_param.go +++ /dev/null @@ -1,21 +0,0 @@ -package param - -type PayApplyAgreeParam struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - ReqTime string `json:"reqtime" form:"reqtime"` - ReqIp string `json:"reqip" form:"reqip"` - Version string `json:"version" form:"version"` - RandomStr string `json:"randomstr" form:"randomstr"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` - - ReqSn string `json:"reqsn" form:"reqsn"` - AgreeID string `json:"agreeid" form:"agreeid"` - Amount string `json:"amount" form:"amount"` - Currency string `json:"currency" form:"currency"` - Subject string `json:"subject" form:"subject"` - TrxReserve string `json:"trxreserve" form:"trxreserve"` - NotifyUrl string `json:"notifyurl" form:"notifyurl"` - AsInfo string `json:"asinfo" form:"asinfo"` -} diff --git a/utils/tlpay/param/pay_sms_agree_param.go b/utils/tlpay/param/pay_sms_agree_param.go deleted file mode 100644 index ed775da..0000000 --- a/utils/tlpay/param/pay_sms_agree_param.go +++ /dev/null @@ -1,16 +0,0 @@ -package param - -type PaySmsAgreeParam struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - ReqTime string `json:"reqtime" form:"reqtime"` - ReqIp string `json:"reqip" form:"reqip"` - Version string `json:"version" form:"version"` - RandomStr string `json:"randomstr" form:"randomstr"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` - - OrderID string `json:"orderid" form:"orderid"` - AgreeID string `json:"agreeid" form:"agreeid"` - ThpInfo string `json:"thpinfo" form:"thpinfo"` -} diff --git a/utils/tlpay/param/unbind_param.go b/utils/tlpay/param/unbind_param.go deleted file mode 100644 index 903583b..0000000 --- a/utils/tlpay/param/unbind_param.go +++ /dev/null @@ -1,14 +0,0 @@ -package param - -type UnbindParam struct { - CusID string `json:"cusid" form:"cusid"` - AppID string `json:"appid" form:"appid"` - ReqTime string `json:"reqtime" form:"reqtime"` - ReqIp string `json:"reqip" form:"reqip"` - Version string `json:"version" form:"version"` - RandomStr string `json:"randomstr" form:"randomstr"` - SignType string `json:"signtype" form:"signtype"` - Sign string `json:"sign" form:"sign"` - - AgreeID string `json:"agreeid" form:"agreeid"` -} diff --git a/utils/tlpay/result/agree_apply_result.go b/utils/tlpay/result/agree_apply_result.go deleted file mode 100644 index 5cb76b5..0000000 --- a/utils/tlpay/result/agree_apply_result.go +++ /dev/null @@ -1,12 +0,0 @@ -package result - -type AgreeApplyResult struct { - RetCode string `json:"retcode" form:"retcode"` - RetMsg string `json:"retmsg" form:"retmsg"` - RandomStr string `json:"randomstr" form:"randomstr"` - Sign string `json:"sign" form:"sign"` - - TrxStatus string `json:"trxstatus" form:"trxstatus"` - ErrMsg string `json:"errmsg" form:"errmsg"` - ThpInfo string `json:"thpinfo" form:"thpinfo"` -} diff --git a/utils/tlpay/result/agree_confirm_result.go b/utils/tlpay/result/agree_confirm_result.go deleted file mode 100644 index 95c5718..0000000 --- a/utils/tlpay/result/agree_confirm_result.go +++ /dev/null @@ -1,11 +0,0 @@ -package result - -type AgreeConfirmResult struct { - CommonResult - - TrxStatus string `json:"trxstatus" form:"trxstatus"` - ErrMsg string `json:"errmsg" form:"errmsg"` - AgreeID string `json:"agreeid" form:"agreeid"` - BankCode string `json:"bankcode" form:"bankcode"` - BankName string `json:"bankname" form:"bankname"` -} diff --git a/utils/tlpay/result/common_result.go b/utils/tlpay/result/common_result.go deleted file mode 100644 index b331061..0000000 --- a/utils/tlpay/result/common_result.go +++ /dev/null @@ -1,8 +0,0 @@ -package result - -type CommonResult struct { - RetCode string `json:"retcode" form:"retcode"` - RetMsg string `json:"retmsg" form:"retmsg"` - RandomStr string `json:"randomstr" form:"randomstr"` - Sign string `json:"sign" form:"sign"` -} diff --git a/utils/tlpay/result/pay_agree_confirm_result.go b/utils/tlpay/result/pay_agree_confirm_result.go deleted file mode 100644 index b7d4d3e..0000000 --- a/utils/tlpay/result/pay_agree_confirm_result.go +++ /dev/null @@ -1,14 +0,0 @@ -package result - -type PayAgreeConfirmResult struct { - CommonResult - - TrxStatus string `json:"trxstatus" form:"trxstatus"` - ReqSn string `json:"reqsn" form:"reqsn"` - ErrMsg string `json:"errmsg" form:"errmsg"` - TrxID string `json:"trxid" form:"trxid"` - ChannelTrxID string `json:"chnltrxid" form:"chnltrxid"` - FinTime string `json:"fintime" form:"fintime"` - ThpInfo string `json:"thpinfo" form:"thpinfo"` - Fee string `json:"fee" form:"fee"` -} diff --git a/utils/tlpay/result/pay_apply_agree_result.go b/utils/tlpay/result/pay_apply_agree_result.go deleted file mode 100644 index 58173b1..0000000 --- a/utils/tlpay/result/pay_apply_agree_result.go +++ /dev/null @@ -1,13 +0,0 @@ -package result - -type PayApplyAgreeResult struct { - CommonResult - - TrxStatus string `json:"trxstatus" form:"trxstatus"` - ReqSn string `json:"reqsn" form:"reqsn"` - ErrMsg string `json:"errmsg" form:"errmsg"` - TrxID string `json:"trxid" form:"trxid"` - ChannelTrxID string `json:"chnltrxid" form:"chnltrxid"` - FinTime string `json:"fintime" form:"fintime"` - ThpInfo string `json:"thpinfo" form:"thpinfo"` -} diff --git a/utils/tlpay/result/pay_sms_agree_result.go b/utils/tlpay/result/pay_sms_agree_result.go deleted file mode 100644 index bdd11dc..0000000 --- a/utils/tlpay/result/pay_sms_agree_result.go +++ /dev/null @@ -1,7 +0,0 @@ -package result - -type PaySmsAgreeResult struct { - CommonResult - - ThpInfo string `json:"thpinfo" form:"thpinfo"` -} diff --git a/utils/weixin/access_token_result.go b/utils/weixin/access_token_result.go deleted file mode 100644 index 41ec5c5..0000000 --- a/utils/weixin/access_token_result.go +++ /dev/null @@ -1,13 +0,0 @@ -package weixin - -type AccessTokenResult struct { - ErrorCode int `json:"errcode"` - ErrorMessage string `json:"errmsg"` - AccessToken string `json:"access_token"` - ExpiresIn int `json:"expires_in"` - RefreshToken string `json:"refresh_token"` - Openid string `json:"openid"` - Scope string `json:"scope"` - IsSnapshotuser int `json:"is_snapshotuser"` - Unionid string `json:"unionid"` -} diff --git a/utils/weixin/wx_api.go b/utils/weixin/wx_api.go deleted file mode 100644 index 267f1a0..0000000 --- a/utils/weixin/wx_api.go +++ /dev/null @@ -1,76 +0,0 @@ -package weixin - -import ( - "encoding/json" - "fmt" - "gold-shop/errors" - "gold-shop/global" - "io" - "net/http" - "net/url" -) - -var WxApi wxApi = wxApi{} - -type wxApi struct { -} - -func (api wxApi) GetAccessToken(code string) (*AccessTokenResult, error) { - params := url.Values{} - params.Set("appid", global.Config.Payment.WxPay.SubAppId) - params.Set("secret", global.Config.Payment.WxPay.SubAppSecret) - params.Set("code", code) - params.Set("grant_type", "authorization_code") - urlStr := params.Encode() - tokenUrl := "https://api.weixin.qq.com/sns/oauth2/access_token?" + urlStr - body, err := api.get(tokenUrl) - if err != nil { - return nil, err - } - result := AccessTokenResult{} - err = json.Unmarshal(body, &result) - fmt.Println(result) - if err != nil { - return nil, errors.NewBusinessError("数据解析错误") - } - if result.ErrorCode != 0 && result.ErrorCode != 200 { - return nil, errors.NewBusinessError(result.ErrorMessage) - } - return &result, nil -} - -func (api wxApi) GetAuthUrl(redirectUrl string) string { - fmt.Println(global.Config) - params := url.Values{} - params.Set("appid", global.Config.Payment.WxPay.SubAppId) - params.Set("redirect_uri", redirectUrl) - params.Set("response_type", "code") - params.Set("scope", "snsapi_base") - params.Set("state", "pay") - urlStr := params.Encode() - return "https://open.weixin.qq.com/connect/oauth2/authorize?" + urlStr + "#wechat_redirect" -} - -func (api wxApi) get(url string) ([]byte, error) { - resp, err := http.Get(url) - if err != nil { - return nil, err - } - - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - fmt.Println(err.Error()) - } - }(resp.Body) - - bodyBytes, err := io.ReadAll(resp.Body) - - fmt.Println(string(bodyBytes)) - - if err != nil { - return nil, errors.NewBusinessError("返回内容错误") - } - - return bodyBytes, nil -}