Merge remote-tracking branch 'origin/tuoyun' into tuoyun

pull/103/head
wenxu12345 3 years ago
commit cda28cb2ee

@ -1 +1 @@
Subproject commit 0e57291413f3cccd365c6947875387638349276a
Subproject commit 369973051405db1102fd1b99a0226ab79b9922e0

@ -0,0 +1,25 @@
.PHONY: all build run gotool install clean help
BINARY_NAME=open_im_demo
BIN_DIR=../../bin/
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
run:
@go run ./
gotool:
go fmt ./
go vet ./
install:
make build
mv ${BINARY_NAME} ${BIN_DIR}
clean:
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi

@ -0,0 +1,28 @@
package main
import (
"Open_IM/internal/demo/register"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"flag"
"github.com/gin-gonic/gin"
"strconv"
)
func main() {
r := gin.Default()
r.Use(utils.CorsHandler())
authRouterGroup := r.Group("/auth")
{
authRouterGroup.POST("/code", register.SendVerificationCode)
authRouterGroup.POST("/verify", register.Verify)
authRouterGroup.POST("/password", register.SetPassword)
authRouterGroup.POST("/login", register.Login)
}
log.NewPrivateLog("demo")
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
flag.Parse()
r.Run(utils.ServerIP + ":" + strconv.Itoa(*ginPort))
}

@ -143,3 +143,24 @@ messagecallback:
callbackUrl: "http://www.xxx.com/msg/judge"
#TimeOut use second as unit
callbackTimeOut: 10
#---------------demo configuration---------------------#
#The following configuration items are applied to openIM Demo configuration
demoswitch: true
demo:
openImDemoPort: [ 42233 ]
alismsverify:
accessKeyId: LTAI5tJPkn4HuuePdiLdGqe71
accessKeySecret: 4n9OJ7ZCVN1U6KeHDAtOyNeVZcjOuV1
signName: OpenIM Corporation
verificationCodeTemplateCode: SMS_2268101641
superCode: 666666
mail:
title: "openIM"
senderMail: "1765567899@qq.com"
senderAuthorizationCode: "1gxyausfoevlzbfag"
smtpAddr: "smtp.qq.com"
smtpPort: 25

@ -5,6 +5,9 @@ go 1.15
require (
github.com/Shopify/sarama v1.19.0
github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect
github.com/alibabacloud-go/darabonba-openapi v0.1.11
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8
github.com/alibabacloud-go/tea v1.1.17
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/bwmarrin/snowflake v0.3.0
github.com/coreos/go-semver v0.3.0 // indirect
@ -41,6 +44,8 @@ require (
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf
golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect
google.golang.org/grpc v1.33.2
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
sigs.k8s.io/yaml v1.2.0 // indirect

@ -7,6 +7,30 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWso
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alibabacloud-go/darabonba-openapi v0.1.11 h1:w59gtSA0s87p0U5NNG/N/PIHsRP3rtj7qCP9hx9+GL8=
github.com/alibabacloud-go/darabonba-openapi v0.1.11/go.mod h1:MPJMxv7HYrFm5m9uOZWkDYsAWyZztEgnBRfk9Fg0eIU=
github.com/alibabacloud-go/darabonba-string v1.0.0/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA=
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 h1:NqugFkGxx1TXSh/pBcU00Y6bljgDPaFdh5MUSeJ7e50=
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY=
github.com/alibabacloud-go/dysmsapi-20170525 v1.1.2 h1:AiQv4HpDWV0GAXzauPB2Xdrx4cuBo18bqNzIjMJyWjk=
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8 h1:KXMiCg99Jx7B6V+DlRFbWwL9UCGippE5z1wGzhyimiA=
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8/go.mod h1:8aL6tSyQIWJygF7W/Vqxdf/QDbN2S+u57k36bEA8hD8=
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
github.com/alibabacloud-go/openapi-util v0.0.9 h1:Z0DP4LFzkM/rW2nxOMiiLoQVZSeE3jVc5jrZ9Fd/UX0=
github.com/alibabacloud-go/openapi-util v0.0.9/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
github.com/alibabacloud-go/tea v1.1.11/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
github.com/alibabacloud-go/tea v1.1.15/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
github.com/alibabacloud-go/tea v1.1.17 h1:05R5DnaJXe9sCNIe8KUgWHC/z6w/VZIwczgUwzRnul8=
github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
github.com/alibabacloud-go/tea-utils v1.3.9 h1:TtbzxS+BXrisA7wzbAMRtlU8A2eWLg0ufm7m/Tl6fc4=
github.com/alibabacloud-go/tea-utils v1.3.9/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
github.com/aliyun/credentials-go v1.1.2 h1:qU1vwGIBb3UJ8BwunHDRFtAhS6jnQLnde/yk0+Ih2GY=
github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/antonfisher/nested-logrus-formatter v1.3.0 h1:8zixYquU1Odk+vzAaAQPAdRh1ZjmUXNQ1T+dUBvlhVo=
github.com/antonfisher/nested-logrus-formatter v1.3.0/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA=
@ -115,6 +139,9 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@ -142,6 +169,10 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@ -188,6 +219,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olivere/elastic/v7 v7.0.23 h1:b7tjMogDMhf2CisGI+L02LXLVa0ZyE82Z15XfW1e8t8=
github.com/olivere/elastic/v7 v7.0.23/go.mod h1:OuWmD2DiuYhddWegBKPWQuelVKBLrW0fa/VUYgxuGTY=
@ -224,8 +257,13 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/assertions v1.1.1 h1:T/YLemO5Yp7KPzS+lVtu+WsHn8yoSwTfItdAd1r3cck=
github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak=
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
@ -234,14 +272,18 @@ github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca h1:G/aIr3WiUesWHL2YGYgEqjM5tCAJ43Ml+0C18wDkWWs=
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca/go.mod h1:b18KQa4IxHbxeseW1GcZox53d7J0z39VNONTxvvlkXw=
github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@ -252,6 +294,8 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
@ -273,6 +317,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@ -282,6 +328,7 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -294,7 +341,9 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ=
@ -303,6 +352,8 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -314,6 +365,7 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
@ -330,10 +382,12 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/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-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@ -357,11 +411,19 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
gopkg.in/ini.v1 v1.56.0 h1:DPMeDvGTM54DXbPkVIZsp19fp/I2K7zwA/itHYHKo8Y=
gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=

@ -0,0 +1,112 @@
package register
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"bytes"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
)
type ParamsLogin struct {
Email string `json:"email"`
PhoneNumber string `json:"phoneNumber"`
Password string `json:"password"`
Platform int32 `json:"platform"`
}
func Login(c *gin.Context) {
log.NewDebug("Login api is statrting...")
params := ParamsLogin{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var account string
if params.Email != "" {
account = params.Email
} else {
account = params.PhoneNumber
}
log.InfoByKv("api Login get params", account)
queryParams := im_mysql_model.Register{
Account: account,
Password: params.Password,
}
canLogin := im_mysql_model.Login(&queryParams)
if canLogin == 1 {
log.ErrorByKv("Incorrect phone number password", account, "err", "Mobile phone number is not registered")
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Mobile phone number is not registered"})
return
}
if canLogin == 2 {
log.ErrorByKv("Incorrect phone number password", account, "err", "Incorrect password")
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Incorrect password"})
return
}
resp, err := OpenIMToken(account, params.Platform)
if err != nil {
log.ErrorByKv("get token by phone number err", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": err.Error()})
return
}
response, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
log.ErrorByKv("Failed to read file", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoErrot, "errMsg": err.Error()})
return
}
imRep := IMRegisterResp{}
err = json.Unmarshal(response, &imRep)
if err != nil {
log.ErrorByKv("json parsing failed", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
if imRep.ErrCode != 0 {
log.ErrorByKv("openIM Login request failed", account, "err")
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": imRep.ErrMsg})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": imRep.Data})
return
}
func OpenIMToken(Account string, platform int32) (*http.Response, error) {
url := fmt.Sprintf("http://%s:10000/auth/user_token", utils.ServerIP)
client := &http.Client{}
params := make(map[string]interface{})
params["secret"] = config.Config.Secret
params["platform"] = platform
params["uid"] = Account
con, err := json.Marshal(params)
if err != nil {
log.ErrorByKv("json parsing failed", Account, "err", err.Error())
return nil, err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(con)))
if err != nil {
log.ErrorByKv("request error", "/auth/user_token", "err", err.Error())
return nil, err
}
resp, err := client.Do(req)
return resp, err
}

@ -0,0 +1,151 @@
package register
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
"gopkg.in/gomail.v2"
"math/rand"
"net/http"
"time"
)
type paramsVerificationCode struct {
Email string `json:"email"`
PhoneNumber string `json:"phoneNumber"`
}
func SendVerificationCode(c *gin.Context) {
log.InfoByKv("sendCode api is statrting...", "")
params := paramsVerificationCode{}
if err := c.BindJSON(&params); err != nil {
log.ErrorByKv("request params json parsing failed", params.PhoneNumber, params.Email, "err", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var account string
if params.Email != "" {
account = params.Email
} else {
account = params.PhoneNumber
}
queryParams := im_mysql_model.GetRegisterParams{
Account: account,
}
_, err, rowsAffected := im_mysql_model.GetRegister(&queryParams)
if err == nil && rowsAffected != 0 {
log.ErrorByKv("The phone number has been registered", queryParams.Account, "err")
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "The phone number has been registered"})
return
}
log.InfoByKv("begin sendSms", account)
rand.Seed(time.Now().UnixNano())
code := 100000 + rand.Intn(900000)
log.NewDebug("", config.Config.Demo)
if params.Email != "" {
m := gomail.NewMessage()
m.SetHeader(`From`, config.Config.Demo.Mail.SenderMail)
m.SetHeader(`To`, []string{account}...)
m.SetHeader(`Subject`, config.Config.Demo.Mail.Title)
m.SetBody(`text/html`, fmt.Sprintf("%d", code))
if err := gomail.NewDialer(config.Config.Demo.Mail.SmtpAddr, config.Config.Demo.Mail.SmtpPort, config.Config.Demo.Mail.SenderMail, config.Config.Demo.Mail.SenderAuthorizationCode).DialAndSend(m); err != nil {
log.ErrorByKv("send mail error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": err.Error()})
return
}
} else {
client, err := CreateClient(tea.String(config.Config.Demo.AliSMSVerify.AccessKeyID), tea.String(config.Config.Demo.AliSMSVerify.AccessKeySecret))
if err != nil {
log.ErrorByKv("create sendSms client err", "", "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
PhoneNumbers: tea.String(account),
SignName: tea.String(config.Config.Demo.AliSMSVerify.SignName),
TemplateCode: tea.String(config.Config.Demo.AliSMSVerify.VerificationCodeTemplateCode),
TemplateParam: tea.String(fmt.Sprintf("{\"code\":\"%d\"}", code)),
}
response, err := client.SendSms(sendSmsRequest)
if err != nil {
log.ErrorByKv("sendSms error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
if *response.Body.Code != "OK" {
log.ErrorByKv("alibabacloud sendSms error", account, "err", response.Body.Code, response.Body.Message)
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
}
log.InfoByKv("begin store redis", account)
v, err := redis.Int(db.DB.Exec("TTL", account))
if err != nil {
log.ErrorByKv("get account from redis error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
switch {
case v == -2:
_, err = db.DB.Exec("SET", account, code, "EX", 600)
if err != nil {
log.ErrorByKv("set redis error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verification code sent successfully!", "data": data})
log.InfoByKv("send new verification code", account)
return
case v > 540:
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Frequent operation!", "data": data})
log.InfoByKv("frequent operation", account)
return
case v < 540:
_, err = db.DB.Exec("SET", account, code, "EX", 600)
if err != nil {
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enterthe superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verification code has been reset!", "data": data})
log.InfoByKv("Reset verification code", account)
return
}
}
func CreateClient(accessKeyId *string, accessKeySecret *string) (result *dysmsapi20170525.Client, err error) {
c := &openapi.Config{
// 您的AccessKey ID
AccessKeyId: accessKeyId,
// 您的AccessKey Secret
AccessKeySecret: accessKeySecret,
}
// 访问的域名
c.Endpoint = tea.String("dysmsapi.aliyuncs.com")
result = &dysmsapi20170525.Client{}
result, err = dysmsapi20170525.NewClient(c)
return result, err
}

@ -0,0 +1,155 @@
package register
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"bytes"
"encoding/json"
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
)
type ParamsSetPassword struct {
Email string `json:"email"`
PhoneNumber string `json:"phoneNumber"`
Password string `json:"password"`
VerificationCode string `json:"verificationCode"`
}
type Data struct {
ExpiredTime int64 `json:"expiredTime"`
Token string `json:"token"`
Uid string `json:"uid"`
}
type IMRegisterResp struct {
Data Data `json:"data"`
ErrCode int32 `json:"errCode"`
ErrMsg string `json:"errMsg"`
}
func SetPassword(c *gin.Context) {
log.InfoByKv("setPassword api is statrting...", "")
params := ParamsSetPassword{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var account string
if params.Email != "" {
account = params.Email
} else {
account = params.PhoneNumber
}
log.InfoByKv("begin store redis", account)
v, err := redis.String(db.DB.Exec("GET", account))
if params.VerificationCode == config.Config.Demo.SuperCode {
goto openIMRegisterTab
}
fmt.Println("Get Redis:", v, err)
if err != nil {
log.ErrorByKv("password Verification code expired", account, "err", err.Error())
data := make(map[string]interface{})
data["phoneNumber"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification expired!", "data": data})
return
}
if v != params.VerificationCode {
log.InfoByKv("password Verification code error", account, params.VerificationCode)
data := make(map[string]interface{})
data["PhoneNumber"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification code error!", "data": data})
return
}
openIMRegisterTab:
log.InfoByKv("openIM register begin", account)
resp, err := OpenIMRegister(account)
log.InfoByKv("openIM register resp", account, resp, err)
if err != nil {
log.ErrorByKv("request openIM register error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": err.Error()})
return
}
response, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoErrot, "errMsg": err.Error()})
return
}
imrep := IMRegisterResp{}
err = json.Unmarshal(response, &imrep)
if err != nil {
c.JSON(http.StatusOK, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
if imrep.ErrCode != 0 {
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": imrep.ErrMsg})
return
}
queryParams := im_mysql_model.SetPasswordParams{
Account: account,
Password: params.Password,
}
log.InfoByKv("begin store mysql", account, params.Password)
_, err = im_mysql_model.SetPassword(&queryParams)
if err != nil {
log.ErrorByKv("set phone number password error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.DatabaseError, "errMsg": err.Error()})
return
}
log.InfoByKv("end setPassword", account)
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": imrep.Data})
return
}
func OpenIMRegister(account string) (*http.Response, error) {
url := fmt.Sprintf("http://%s:10000/auth/user_register", utils.ServerIP)
fmt.Println("1:", config.Config.Secret)
client := &http.Client{}
params := make(map[string]interface{})
params["secret"] = config.Config.Secret
params["platform"] = 7
params["uid"] = account
params["name"] = account
params["icon"] = ""
params["gender"] = 0
params["mobile"] = ""
params["email"] = ""
params["birth"] = ""
params["ex"] = ""
con, err := json.Marshal(params)
if err != nil {
return nil, err
}
log.InfoByKv("openIM register params", account, params)
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(con)))
if err != nil {
return nil, err
}
resp, err := client.Do(req)
return resp, err
}

@ -0,0 +1,69 @@
package register
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
"net/http"
)
type paramsCertification struct {
Email string `json:"email"`
PhoneNumber string `json:"phoneNumber"`
VerificationCode string `json:"verificationCode"`
}
func Verify(c *gin.Context) {
log.InfoByKv("Verify api is statrting...", "")
params := paramsCertification{}
if err := c.BindJSON(&params); err != nil {
log.ErrorByKv("request params json parsing failed", "", "err", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var account string
if params.Email != "" {
account = params.Email
} else {
account = params.PhoneNumber
}
if params.VerificationCode == config.Config.Demo.SuperCode {
log.InfoByKv("Super Code Verified successfully", account)
data := make(map[string]interface{})
data["account"] = account
data["verificationCode"] = params.VerificationCode
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verified successfully!", "data": data})
return
}
log.InfoByKv("begin get form redis", account)
v, err := redis.String(db.DB.Exec("GET", account))
log.InfoByKv("redis phone number and verificating Code", account, v)
if err != nil {
log.ErrorByKv("Verification code expired", account, "err", err.Error())
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification code expired!", "data": data})
return
}
if params.VerificationCode == v {
log.InfoByKv("Verified successfully", account)
data := make(map[string]interface{})
data["account"] = account
data["verificationCode"] = params.VerificationCode
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verified successfully!", "data": data})
return
} else {
log.InfoByKv("Verification code error", account, params.VerificationCode)
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification code error!", "data": data})
}
}

@ -155,6 +155,23 @@ type config struct {
CallbackUrl string `yaml:"callbackUrl"`
CallBackTimeOut int `yaml:"callbackTimeOut"`
}
Demo struct {
Port []int `yaml:"openImDemoPort"`
AliSMSVerify struct {
AccessKeyID string `yaml:"accessKeyId"`
AccessKeySecret string `yaml:"accessKeySecret"`
SignName string `yaml:"signName"`
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
}
SuperCode string `yaml:"superCode"`
Mail struct {
Title string `yaml:"title"`
SenderMail string `yaml:"senderMail"`
SenderAuthorizationCode string `yaml:"senderAuthorizationCode"`
SmtpAddr string `yaml:"smtpAddr"`
SmtpPort int `yaml:"smtpPort"`
}
}
}
func init() {

@ -60,6 +60,17 @@ var (
TokenUnknown = errors.New("couldn't handle this token")
)
const (
NoError = 0
FormattingError = 10001
DatabaseError = 10002
LogicalError = 10003
ServerError = 10004
HttpError = 10005
IoErrot = 10006
IntentionalError = 10007
)
func (e *ErrInfo) Error() string {
return e.ErrMsg
}

@ -182,6 +182,16 @@ func initMysqlDB() {
panic(err.Error())
}
sqlTable = "CREATE TABLE IF NOT EXISTS `register` (" +
" `account` varchar(255) NOT NULL," +
" `password` varchar(255) NOT NULL," +
" PRIMARY KEY (`account`) USING BTREE" +
" ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;"
err = db.Exec(sqlTable).Error
if err != nil {
panic(err.Error())
}
}
func (m *mysqlDB) DefaultGormDB() (*gorm.DB, error) {

@ -0,0 +1,64 @@
package im_mysql_model
import (
"Open_IM/pkg/common/db"
_ "github.com/jinzhu/gorm"
)
type GetRegisterParams struct {
Account string `json:"account"`
}
type Register struct {
Account string `gorm:"column:account"`
Password string `gorm:"column:password"`
}
func GetRegister(params *GetRegisterParams) (Register, error, int64) {
var r Register
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return r, err, 0
}
result := dbConn.
Where(&Register{Account: params.Account}).
Find(&r)
return r, result.Error, result.RowsAffected
}
type SetPasswordParams struct {
Account string `json:"account"`
Password string `json:"password"`
}
func SetPassword(params *SetPasswordParams) (Register, error) {
r := Register{
Account: params.Account,
Password: params.Password,
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return r, err
}
result := dbConn.Create(&r)
return r, result.Error
}
func Login(params *Register) int64 {
var r Register
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 3
}
result := dbConn.
Where(&Register{Account: params.Account}).
Find(&r)
if result.Error != nil && result.RowsAffected == 0 {
return 1
}
if r.Password != params.Password {
return 2
}
return 0
}

@ -121,7 +121,10 @@ func SelectAllUID() ([]string, error) {
if err != nil {
return uid, err
}
rows, _ := dbConn.Raw("select uid from user").Rows()
rows, err := dbConn.Raw("select uid from user").Rows()
if err != nil {
return uid, err
}
defer rows.Close()
var strUID string
for rows.Next() {

@ -88,11 +88,6 @@ func (d *DataBases) GetTokenMapByUidPid(userID, platformID string) (map[string]i
}
func (d *DataBases) SetTokenMapByUidPid(userID string, platformID int32, m map[string]int) error {
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
//var a []interface{}
//for k, v := range m {
// a = append(a, k)
// a = append(a, v)
//}
_, err := d.Exec("hmset", key, redis.Args{}.Add().AddFlat(m)...)
return err
}

@ -8,8 +8,8 @@ import (
func Test_SetTokenMapByUidPid(t *testing.T) {
m := make(map[string]int, 0)
m["哈哈"] = 1
m["heihei"] = 2
m["test1"] = 1
m["test2"] = 2
m["2332"] = 4
_ = DB.SetTokenMapByUidPid("1234", 2, m)

@ -14,8 +14,15 @@ service_port_name=(
openImPushPort
openImWsPort
openImSdkWsPort
openImDemoPort
)
switch=$(cat $config_path | grep demoswitch |awk -F '[:]' '{print $NF}')
for i in ${service_port_name[*]}; do
if [ ${switch} != "true" ]; then
if [ ${i} == "openImDemoPort"]; then
continue
fi
fi
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
list_to_string $list
for j in ${ports_array}; do

@ -0,0 +1,47 @@
#!/usr/bin/env bash
#Include shell font styles and some basic information
source ./style_info.cfg
source ./path_info.cfg
source ./function.sh
switch=$(cat $config_path | grep demoswitch |awk -F '[:]' '{print $NF}')
if [ ${switch} != "true" ]; then
echo -e ${YELLOW_PREFIX}" demo service switch is false not start demo "${COLOR_SUFFIX}
exit 0
fi
list1=$(cat $config_path | grep openImDemoPort | awk -F '[:]' '{print $NF}')
list_to_string $list1
api_ports=($ports_array)
#Check if the service exists
#If it is exists,kill this process
check=$(ps aux | grep -w ./${demo_server_name} | grep -v grep | wc -l)
if [ $check -ge 1 ]; then
oldPid=$(ps aux | grep -w ./${demo_server_name} | grep -v grep | awk '{print $2}')
kill -9 $oldPid
fi
#Waiting port recycling
sleep 1
cd ${demo_server_binary_root}
for ((i = 0; i < ${#api_ports[@]}; i++)); do
nohup ./${demo_server_name} -port ${api_ports[$i]} >>../logs/openIM.log 2>&1 &
done
sleep 3
#Check launched service process
check=$(ps aux | grep -w ./${demo_server_name} | grep -v grep | wc -l)
if [ $check -ge 1 ]; then
newPid=$(ps aux | grep -w ./${demo_server_name} | grep -v grep | awk '{print $2}')
ports=$(netstat -netulp | grep -w ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}')
allPorts=""
for i in $ports; do
allPorts=${allPorts}"$i "
done
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX}
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${demo_server_name}${COLOR_SUFFIX}
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX}
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX}
else
echo -e ${YELLOW_PREFIX}${demo_server_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX}
fi

@ -10,6 +10,7 @@ need_to_start_server_shell=(
msg_transfer_start.sh
sdk_svr_start.sh
timer_start.sh
demo_svr_start.sh
)
#fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started

@ -27,6 +27,10 @@ sdk_server_name="open_im_sdk_server"
sdk_server_binary_root="../bin/"
sdk_server_source_root="../cmd/Open-IM-SDK-Core/"
demo_server_name="open_im_demo"
demo_server_binary_root="../bin/"
demo_server_source_root="../cmd/open_im_demo/"
#Global configuration file default dir
config_path="../config/config.yaml"
@ -46,6 +50,7 @@ service_source_root=(
${push_source_root}
${sdk_server_source_root}
${timer_task_source_root}
${demo_server_source_root}
)
#service filename
service_names=(
@ -62,6 +67,7 @@ service_names=(
${push_name}
${sdk_server_name}
${timer_task_name}
${demo_server_name}
)

@ -10,6 +10,7 @@ need_to_start_server_shell=(
msg_transfer_start.sh
sdk_svr_start.sh
timer_start.sh
demo_svr_start.sh
)
for i in ${need_to_start_server_shell[*]}; do

Loading…
Cancel
Save