This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AH-dark/refactor/migrate
refactor(actions/migrate): use json file instead of variable config
- Loading branch information
Showing
16 changed files
with
657 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package factory | ||
|
||
import "github.com/urfave/cli/v2" | ||
|
||
type ActionService interface { | ||
Command() *cli.Command | ||
Do(c *cli.Context) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package mapi | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/AH-dark/epay-cli/actions/factory" | ||
"github.com/AH-dark/epay-cli/pkg/epay" | ||
"github.com/AH-dark/epay-cli/pkg/utils" | ||
) | ||
|
||
type service struct { | ||
} | ||
|
||
func NewService() factory.ActionService { | ||
return &service{} | ||
} | ||
|
||
func (svc *service) getSign(c *cli.Context) string { | ||
sign := utils.CalculateEPaySign(map[string]string{ | ||
"pid": strconv.Itoa(c.Int("pid")), | ||
"type": c.String("type"), | ||
"out_trade_no": c.String("trade-no"), | ||
"notify_url": c.String("notify-url"), | ||
"return_url": c.String("return-url"), | ||
"name": c.String("name"), | ||
"money": c.String("money"), | ||
"clientip": c.String("client-ip"), | ||
"device": c.String("device"), | ||
"param": c.String("param"), | ||
}, c.String("secret")) | ||
|
||
return sign | ||
} | ||
|
||
func (svc *service) Do(c *cli.Context) error { | ||
client, err := epay.NewClient(&epay.Config{ | ||
PartnerID: c.Int("pid"), | ||
AppSecret: c.String("secret"), | ||
Endpoint: c.String("endpoint"), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sign := svc.getSign(c) | ||
fmt.Println("Sign:", sign) | ||
|
||
url, args, err := client.MApiSubmit(c.Context, &epay.MApiSubmitArgs{ | ||
Type: epay.PaymentType(c.String("type")), | ||
OutTradeNo: c.String("trade-no"), | ||
Name: c.String("name"), | ||
Money: c.String("money"), | ||
NotifyUrl: c.String("notify-url"), | ||
ReturnUrl: utils.EmptyPtr(c.String("return-url")), | ||
ClientIP: c.String("client-ip"), | ||
Device: utils.EmptyPtr(epay.DeviceType(c.String("device"))), | ||
Param: utils.EmptyPtr(c.String("param")), | ||
Sign: sign, | ||
SignType: "MD5", | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("URL:", url) | ||
fmt.Println("Args:", args) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package migrate | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/AH-dark/epay-cli/pkg/utils" | ||
) | ||
|
||
func (svc *service) Command() *cli.Command { | ||
return &cli.Command{ | ||
Name: "migrate", | ||
Usage: "generate sql schema", | ||
Action: svc.Do, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "database.driver", | ||
Usage: "database driver", | ||
EnvVars: []string{"DATABASE_DRIVER", "DB_DRIVER"}, | ||
Value: "mysql", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "database.host", | ||
Usage: "database host", | ||
EnvVars: []string{"DATABASE_HOST", "DB_HOST"}, | ||
Value: "localhost", | ||
}, | ||
&cli.IntFlag{ | ||
Name: "database.port", | ||
Usage: "database port", | ||
EnvVars: []string{"DATABASE_PORT", "DB_PORT"}, | ||
Value: 3306, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "database.name", | ||
Usage: "database name", | ||
EnvVars: []string{"DATABASE_NAME", "DB_NAME"}, | ||
Value: "epay", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "database.user", | ||
Usage: "database user", | ||
EnvVars: []string{"DATABASE_USER", "DB_USER"}, | ||
Value: "root", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "database.password", | ||
Usage: "database password", | ||
EnvVars: []string{"DATABASE_PASSWORD", "DB_PASSWORD"}, | ||
Value: "", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "database.prefix", | ||
Usage: "database prefix", | ||
EnvVars: []string{"DATABASE_PREFIX", "DB_PREFIX"}, | ||
Value: "pay_", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "database.sslmode", | ||
Usage: "database sslmode", | ||
EnvVars: []string{"DATABASE_SSL_MODE", "DB_SSL_MODE"}, | ||
Value: "disable", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "database.charset", | ||
Usage: "database charset", | ||
EnvVars: []string{"DATABASE_CHARSET", "DB_CHARSET"}, | ||
Value: "utf8mb4", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "app.syskey", | ||
Usage: "app syskey", | ||
EnvVars: []string{"APP_SYSKEY", "APP_SYS_KEY"}, | ||
Value: utils.RandString(32), | ||
}, | ||
&cli.StringFlag{ | ||
Name: "app.cronkey", | ||
Usage: "app cronkey", | ||
EnvVars: []string{"APP_CRONKEY", "APP_CRON_KEY"}, | ||
Value: strconv.Itoa(utils.RandInt(100000, 999999)), | ||
}, | ||
&cli.StringFlag{ | ||
Name: "migrate.default_config", | ||
Usage: "migrate default config", | ||
EnvVars: []string{"MIGRATE_DEFAULT_CONFIG", "MIGRATION_DEFAULT_CONFIG"}, | ||
Value: "./data/default_config.json", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "migrate.default_payment_types", | ||
Usage: "migrate default payment types", | ||
EnvVars: []string{"MIGRATE_DEFAULT_PAYMENT_TYPES", "MIGRATION_DEFAULT_PAYMENT_TYPES"}, | ||
Value: "./data/default_payment_types.json", | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.