diff --git a/apps/fushouxian-server-liangliangit/.processManager b/apps/fushouxian-server-liangliangit/.processManager new file mode 100644 index 0000000..10e5afb --- /dev/null +++ b/apps/fushouxian-server-liangliangit/.processManager @@ -0,0 +1 @@ +{"pid":36728} \ No newline at end of file diff --git a/apps/fushouxian-server-liangliangit/build.sh b/apps/fushouxian-server-liangliangit/build.sh new file mode 100644 index 0000000..e06668a --- /dev/null +++ b/apps/fushouxian-server-liangliangit/build.sh @@ -0,0 +1,51 @@ +case $3 in + "") + goarch="amd64" + releasePath="x86_64" + break + ;; + "arm") + goarch="arm" + releasePath="arm" + break + ;; + "arm64") + goarch="arm64" + releasePath="arm64" + break + ;; + "loong64") + goarch="loong64" + releasePath="loong64" + break + ;; + *) + echo '目标 ' $3 ' 无法编译' + exit + ;; +esac + +buildfile=$1 + + +case $2 in + "linux") echo '交叉编译目标为linux+'$goarch + echo "CGO_ENABLED=0 GOOS=linux GOARCH="$goarch" go build "$1 + CGO_ENABLED=0 GOOS=linux GOARCH=$goarch go build -o ./"${buildfile%%.*}-"$releasePath $1 + break + ;; + "windows") echo '交叉编译目标为windows+'$goarch + echo "CGO_ENABLED=0 GOOS=windows GOARCH="$goarch" go build "$1 + CGO_ENABLED=0 GOOS=windows GOARCH=$goarch go build -o ././"${buildfile%%.*}-"$releasePath".exe" $1 + break + ;; + "darwin") echo '交叉编译目标为maxos+'$goarch + echo "CGO_ENABLED=0 GOOS=darwin GOARCH="$goarch" go build "$1 + CGO_ENABLED=0 GOOS=darwin GOARCH=$goarch go build -o ./"${buildfile%%.*}-"$releasePath $1 + break + ;; + *) echo '参数不正确:'$goarch + break + ;; +esac + echo '脚本执行结束...' diff --git a/apps/fushouxian-server-liangliangit/config/config.json b/apps/fushouxian-server-liangliangit/config/config.json new file mode 100644 index 0000000..62ea81d --- /dev/null +++ b/apps/fushouxian-server-liangliangit/config/config.json @@ -0,0 +1,3 @@ +{ + "serverport":"9001" +} diff --git a/apps/fushouxian-server-liangliangit/config/dbconfig copy.json b/apps/fushouxian-server-liangliangit/config/dbconfig copy.json new file mode 100644 index 0000000..459825a --- /dev/null +++ b/apps/fushouxian-server-liangliangit/config/dbconfig copy.json @@ -0,0 +1,10 @@ +[ + { + "DbType":"mysql", + "IsMaster":true, + "Dsn":"root:Password1!@tcp(mysql-a.fanhaninfo.test:3306)/dev_digital?charset=utf8mb4", + "sqlMaxIdleConns":100, + "sqlMaxOpenConns":100, + "sqlLogLevel":2 + } +] \ No newline at end of file diff --git a/apps/fushouxian-server-liangliangit/config/dbconfig.json b/apps/fushouxian-server-liangliangit/config/dbconfig.json new file mode 100644 index 0000000..07eee43 --- /dev/null +++ b/apps/fushouxian-server-liangliangit/config/dbconfig.json @@ -0,0 +1,10 @@ +[ + { + "DbType":"mysql", + "IsMaster":true, + "Dsn":"root:12345678@tcp(127.0.0.1:3306)/fushouxian?charset=utf8mb4", + "sqlMaxIdleConns":1, + "sqlMaxOpenConns":1, + "sqlLogLevel":2 + } +] diff --git a/apps/fushouxian-server-liangliangit/config/rpaconfig.json b/apps/fushouxian-server-liangliangit/config/rpaconfig.json new file mode 100644 index 0000000..171003c --- /dev/null +++ b/apps/fushouxian-server-liangliangit/config/rpaconfig.json @@ -0,0 +1,5 @@ +{ + "rpa_url": "http://172.0.0.19:19005", + "username": "admin", + "password": "123" +} diff --git a/apps/fushouxian-server-liangliangit/config/togocdn.client.config.json b/apps/fushouxian-server-liangliangit/config/togocdn.client.config.json new file mode 100644 index 0000000..bfc19c2 --- /dev/null +++ b/apps/fushouxian-server-liangliangit/config/togocdn.client.config.json @@ -0,0 +1,7 @@ +{ + "Priority":100, + "ModuleName":"go", + "ServerUrls":[ + "wss://shop.ruixininfo.com/websocket/jsonrpc" + ] +} diff --git a/apps/fushouxian-server-liangliangit/fushouxian-server.go b/apps/fushouxian-server-liangliangit/fushouxian-server.go new file mode 100644 index 0000000..1944c69 --- /dev/null +++ b/apps/fushouxian-server-liangliangit/fushouxian-server.go @@ -0,0 +1,108 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" + _ "src/init" + + "github.com/towgo/towgo/dao/basedboperat" + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/lib/processmanager" + "github.com/towgo/towgo/lib/system" + "github.com/towgo/towgo/towgo" +) + +var appName string = "fushouxian-server" +var appVersion string = "1.0.0" + +var basePath = system.GetPathOfProgram() + +func init() { + //初始化xorm数据库驱动 + var dbconfig []xormDriver.DsnConfig + system.ScanConfigJson(basePath+"/config/dbconfig.json", &dbconfig) + xormDriver.New(dbconfig) + + //设定默认orm引擎 + err := basedboperat.SetOrmEngine("xorm") + if err != nil { + log.Print(err.Error()) + } + +} +func main() { + pm := processmanager.GetManager() + for k, v := range os.Args { + switch v { + case "start": + if k == 1 { + if pm.Start() { + log.Print("启动成功") + start() + return + } else { + log.Print("启动失败:" + pm.Error.Error()) + return + } + } + case "restart": + if k == 1 { + if pm.ReStart() { + log.Print("重启成功") + start() + return + } else { + log.Print("重启失败:" + pm.Error.Error()) + } + return + } + case "stop": + if k == 1 { + if pm.Stop() { + log.Print("程序停止成功") + } else { + log.Print("程序停止失败:程序没有运行") + } + return + } + case "version": + if k == 1 { + fmt.Print(appName + ":" + appVersion + "\n") + os.Exit(0) + } + return + + } + } + log.Print("参数传递错误,有效参数如下:\n" + os.Args[0] + " start | stop | reload | stop") + +} + +func start() { + + moduleClientInit() + + conf := struct { + Serverport string `json:"serverport"` + }{} + system.ScanConfigJson(basePath+"/config/config.json", &conf) + + http.HandleFunc("/jsonrpc", towgo.HttpHandller) + + log.Print("http服务运行中:0.0.0.0:" + conf.Serverport + "\n") + http.ListenAndServe("0.0.0.0:"+conf.Serverport, nil) +} + +func moduleClientInit() { + var node towgo.EdgeServerNodeConfig + system.ScanConfigJson(basePath+"config/togocdn.client.config.json", &node) + node.Methods = towgo.GetMethods() + node.ModuleName = appName + for _, v := range node.ServerUrls { + node.ServerUrl = v + client := towgo.NewEdgeServerNode(node) + client.Connect() + } +} diff --git a/apps/fushouxian-server/.processManager b/apps/fushouxian-server/.processManager index 6361003..10e5afb 100644 --- a/apps/fushouxian-server/.processManager +++ b/apps/fushouxian-server/.processManager @@ -1 +1 @@ -{"pid":33859} \ No newline at end of file +{"pid":36728} \ No newline at end of file diff --git a/module/tencent/sms.go b/module/tencent/sms.go index 1ead888..f66d699 100644 --- a/module/tencent/sms.go +++ b/module/tencent/sms.go @@ -1,7 +1,9 @@ package tencent import ( + "encoding/json" "fmt" + "log" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" @@ -9,6 +11,21 @@ import ( sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111" // 引入sms ) +type SMSResponse struct { + SendStatusSet []SendStatus `json:"SendStatusSet"` // 发送状态集 + RequestId string `json:"RequestId"` // 请求ID +} + +type SendStatus struct { + SerialNo string `json:"SerialNo"` // 序列号 + PhoneNumber string `json:"PhoneNumber"` // 手机号码 + Fee int `json:"Fee"` // 费用 + SessionContext string `json:"SessionContext"` // 会话上下文 + Code string `json:"Code"` // 状态码 + Message string `json:"Message"` // 消息 + IsoCode string `json:"IsoCode"` // 国际标准化组织代码 +} + func SendSMSVerificationCode(templateID, signName, mobile, verificationCode string) error { /* 必要步骤: * 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey。 @@ -86,7 +103,7 @@ func SendSMSVerificationCode(templateID, signName, mobile, verificationCode stri request.SenderId = common.StringPtr("") // 通过client对象调用想要访问的接口,需要传入请求对象 - _, err := client.SendSms(request) + response, err := client.SendSms(request) // 处理异常 if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) @@ -97,6 +114,14 @@ func SendSMSVerificationCode(templateID, signName, mobile, verificationCode stri return err } + var resp SMSResponse + + b, _ := json.Marshal(response.Response) + json.Unmarshal(b, &resp) + // 打印返回的json字符串 + + log.Print(resp) + /* 当出现以下错误码时,快速解决方案参考 * [FailedOperation.SignatureIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.signatureincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F) * [FailedOperation.TemplateIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.templateincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F) diff --git a/module/usercenter/SMSVerificationCode.go b/module/usercenter/SMSVerificationCode.go index d2d64c3..d2a6618 100644 --- a/module/usercenter/SMSVerificationCode.go +++ b/module/usercenter/SMSVerificationCode.go @@ -8,26 +8,26 @@ import ( "time" ) -var loginOrregSMSVerificationCode sync.Map +var loginOrRegSMSVerificationCode sync.Map // 登记注册用验证码 func StoreLoginOrloginOrRegSMSVerificationCode(mobile string) (string, error) { - codeInterface, ok := loginOrregSMSVerificationCode.Load(mobile) + codeInterface, ok := loginOrRegSMSVerificationCode.Load(mobile) if ok { return codeInterface.(string), nil } verificationCode := randCharNumber(6) - loginOrregSMSVerificationCode.Store(mobile, verificationCode) + loginOrRegSMSVerificationCode.Store(mobile, verificationCode) go func(mobile string) { time.Sleep(time.Second * 5 * 60) - loginOrregSMSVerificationCode.Delete(mobile) + loginOrRegSMSVerificationCode.Delete(mobile) }(mobile) return verificationCode, nil } // 验证注册验证码 func LoginOrRegSMSVerification(mobile, verificationCode string) bool { - codeInterface, ok := loginOrregSMSVerificationCode.LoadAndDelete(mobile) + codeInterface, ok := loginOrRegSMSVerificationCode.LoadAndDelete(mobile) if !ok { return false }