@@ -18,7 +18,7 @@ import ( | |||
) | |||
func main() { | |||
config.Init() | |||
//config.Init() | |||
db.Init() | |||
server := grpc.NewServer(grpc.UnaryInterceptor(interceptor.NewInterceptor("business_interceptor", urlwhitelist.Business))) | |||
@@ -12,9 +12,9 @@ require ( | |||
github.com/jinzhu/gorm v1.9.16 | |||
github.com/json-iterator/go v1.1.12 | |||
go.uber.org/zap v1.21.0 | |||
google.golang.org/genproto v0.0.0-20211207154714-918901c715cf | |||
google.golang.org/grpc v1.42.0 | |||
google.golang.org/protobuf v1.28.0 | |||
google.golang.org/genproto v0.0.0-20221018160656-63c7b68cfc55 | |||
google.golang.org/grpc v1.50.1 | |||
google.golang.org/protobuf v1.28.1 | |||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 | |||
k8s.io/api v0.25.1 | |||
k8s.io/apimachinery v0.25.1 | |||
@@ -35,8 +35,10 @@ require ( | |||
github.com/go-playground/universal-translator v0.17.0 // indirect | |||
github.com/go-playground/validator/v10 v10.4.1 // indirect | |||
github.com/gogo/protobuf v1.3.2 // indirect | |||
github.com/golang/glog v1.0.0 // indirect | |||
github.com/google/gnostic v0.5.7-v3refs // indirect | |||
github.com/google/gofuzz v1.1.0 // indirect | |||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 // indirect | |||
github.com/jinzhu/inflection v1.0.0 // indirect | |||
github.com/josharian/intern v1.0.0 // indirect | |||
github.com/leodido/go-urn v1.2.0 // indirect | |||
@@ -50,13 +52,14 @@ require ( | |||
go.uber.org/atomic v1.7.0 // indirect | |||
go.uber.org/multierr v1.6.0 // indirect | |||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect | |||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect | |||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect | |||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect | |||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect | |||
golang.org/x/text v0.3.7 // indirect | |||
golang.org/x/net v0.1.0 // indirect | |||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect | |||
golang.org/x/sys v0.1.0 // indirect | |||
golang.org/x/term v0.1.0 // indirect | |||
golang.org/x/text v0.4.0 // indirect | |||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect | |||
google.golang.org/appengine v1.6.7 // indirect | |||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 // indirect | |||
gopkg.in/inf.v0 v0.9.1 // indirect | |||
gopkg.in/yaml.v2 v2.4.0 // indirect | |||
gopkg.in/yaml.v3 v3.0.1 // indirect | |||
@@ -154,6 +154,8 @@ github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzw | |||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= | |||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= | |||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= | |||
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= | |||
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= | |||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= | |||
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= | |||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= | |||
@@ -205,6 +207,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ | |||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | |||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= | |||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | |||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | |||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | |||
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= | |||
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | |||
@@ -237,6 +240,8 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U | |||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | |||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= | |||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= | |||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 h1:kr3j8iIMR4ywO/O0rvksXaJvauGGCMg2zAZIiNZ9uIQ= | |||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0/go.mod h1:ummNFgdgLhhX7aIiy35vVmQNS0rWXknfPE0qe6fmFXg= | |||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= | |||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= | |||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= | |||
@@ -450,6 +455,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su | |||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= | |||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= | |||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | |||
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= | |||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= | |||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= | |||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= | |||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= | |||
@@ -467,6 +474,8 @@ golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ | |||
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= | |||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg= | |||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= | |||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 h1:nt+Q6cXKz4MosCSpnbMtqiQ8Oz0pxTef2B4Vca2lvfk= | |||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= | |||
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-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |||
@@ -538,9 +547,13 @@ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBc | |||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= | |||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= | |||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | |||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= | |||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | |||
golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw= | |||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | |||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | |||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | |||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | |||
@@ -551,6 +564,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | |||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | |||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= | |||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | |||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= | |||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= | |||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | |||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | |||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | |||
@@ -711,6 +726,8 @@ google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEc | |||
google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= | |||
google.golang.org/genproto v0.0.0-20211207154714-918901c715cf h1:PSEM+IQFb9xdsj2CGhfqUTfsZvF8DScCVP1QZb2IiTQ= | |||
google.golang.org/genproto v0.0.0-20211207154714-918901c715cf/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= | |||
google.golang.org/genproto v0.0.0-20221018160656-63c7b68cfc55 h1:U1u4KB2kx6KR/aJDjQ97hZ15wQs8ZPvDcGcRynBhkvg= | |||
google.golang.org/genproto v0.0.0-20221018160656-63c7b68cfc55/go.mod h1:45EK0dUbEZ2NHjCeAd2LXmyjAgGUGrpGROgjhC3ADck= | |||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= | |||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= | |||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= | |||
@@ -738,7 +755,11 @@ google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnD | |||
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= | |||
google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A= | |||
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= | |||
google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY= | |||
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= | |||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= | |||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 h1:TLkBREm4nIsEcexnCjgQd5GQWaHcqMzwQV0TX9pq8S0= | |||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY= | |||
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= | |||
@@ -754,6 +775,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ | |||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= | |||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= | |||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= | |||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= | |||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= | |||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | |||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | |||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | |||
@@ -10,14 +10,15 @@ import ( | |||
type BusinessExtServer struct{} | |||
func (s *BusinessExtServer) SignIn(ctx context.Context, req *pb.SignInReq) (*pb.SignInResp, error) { | |||
isNew, userId, token, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.DeviceId) | |||
isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return &pb.SignInResp{ | |||
IsNew: isNew, | |||
UserId: userId, | |||
Token: token, | |||
IsNew: isNew, | |||
UserId: userId, | |||
Token: token, | |||
MasterId: masterId, | |||
}, nil | |||
} | |||
@@ -13,7 +13,7 @@ import ( | |||
) | |||
func getBusinessExtClient() pb.BusinessExtClient { | |||
conn, err := grpc.Dial("111.229.238.28:50200", grpc.WithInsecure()) | |||
conn, err := grpc.Dial("im-rpc-business.izhyin.com:8000", grpc.WithInsecure()) | |||
if err != nil { | |||
fmt.Println(err) | |||
return nil | |||
@@ -24,7 +24,7 @@ func getBusinessExtClient() pb.BusinessExtClient { | |||
func getCtx() context.Context { | |||
token := "0" | |||
return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs( | |||
"user_id", "3", | |||
"user_id", "1", | |||
"device_id", "1", | |||
"token", token, | |||
"request_id", strconv.FormatInt(time.Now().UnixNano(), 10))) | |||
@@ -32,9 +32,9 @@ func getCtx() context.Context { | |||
func TestUserExtServer_SignIn(t *testing.T) { | |||
resp, err := getBusinessExtClient().SignIn(getCtx(), &pb.SignInReq{ | |||
PhoneNumber: "18229775316", | |||
Code: "1", | |||
PhoneNumber: "18229775311", | |||
DeviceId: 1, | |||
MasterId: 123456, | |||
}) | |||
if err != nil { | |||
fmt.Println(err) | |||
@@ -43,7 +43,15 @@ func TestUserExtServer_SignIn(t *testing.T) { | |||
} | |||
func TestUserExtServer_GetUser(t *testing.T) { | |||
resp, err := getBusinessExtClient().GetUser(getCtx(), &pb.GetUserReq{UserId: 1}) | |||
resp, err := getBusinessExtClient().GetUser(getCtx(), &pb.GetUserReq{UserId: 2}) | |||
if err != nil { | |||
fmt.Println(err) | |||
} | |||
fmt.Printf("%+v\n", resp) | |||
} | |||
func TestUserExtServer_SearchUser(t *testing.T) { | |||
resp, err := getBusinessExtClient().SearchUser(getCtx(), &pb.SearchUserReq{Key: "18229"}) | |||
if err != nil { | |||
fmt.Println(err) | |||
} | |||
@@ -9,7 +9,8 @@ import ( | |||
) | |||
func getBusinessIntClient() pb.BusinessIntClient { | |||
conn, err := grpc.Dial("localhost:50300", grpc.WithInsecure()) | |||
//conn, err := grpc.Dial("localhost:50300", grpc.WithInsecure()) | |||
conn, err := grpc.Dial("im-rpc-business.izhyin.com:8000", grpc.WithInsecure()) | |||
if err != nil { | |||
fmt.Println(err) | |||
return nil | |||
@@ -19,7 +20,7 @@ func getBusinessIntClient() pb.BusinessIntClient { | |||
func TestUserIntServer_Auth(t *testing.T) { | |||
_, err := getBusinessIntClient().Auth(getCtx(), &pb.AuthReq{ | |||
UserId: 3, | |||
UserId: 2, | |||
DeviceId: 1, | |||
Token: "0", | |||
}) | |||
@@ -10,8 +10,8 @@ type authApp struct{} | |||
var AuthApp = new(authApp) | |||
// SignIn 长连接登录 | |||
func (*authApp) SignIn(ctx context.Context, phoneNumber, code string, deviceId int64) (bool, int64, string, error) { | |||
return service.AuthService.SignIn(ctx, phoneNumber, code, deviceId) | |||
func (*authApp) SignIn(ctx context.Context, phoneNumber, code string, masterId int, deviceId int64) (bool, int64, string, int, error) { | |||
return service.AuthService.SignIn(ctx, phoneNumber, code, masterId, deviceId) | |||
} | |||
// Auth 验证用户是否登录 | |||
@@ -15,6 +15,7 @@ type User struct { | |||
Extra string // 附加属性 | |||
CreateTime time.Time // 创建时间 | |||
UpdateTime time.Time // 更新时间 | |||
MasterId int // 站长id | |||
} | |||
func (u *User) ToProto() *pb.User { | |||
@@ -30,5 +31,6 @@ func (u *User) ToProto() *pb.User { | |||
Extra: u.Extra, | |||
CreateTime: u.CreateTime.Unix(), | |||
UpdateTime: u.UpdateTime.Unix(), | |||
MasterId: u.MasterId, | |||
} | |||
} |
@@ -39,6 +39,6 @@ func TestUserDao_GetByPhoneNumber(t *testing.T) { | |||
} | |||
func TestUserDao_Search(t *testing.T) { | |||
users, err := UserDao.Search("哈哈哈") | |||
users, err := UserDao.Search("18229") | |||
fmt.Printf("%+v\n %+v\n ", users, err) | |||
} |
@@ -7,6 +7,7 @@ import ( | |||
"gim/pkg/gerrors" | |||
"gim/pkg/pb" | |||
"gim/pkg/rpc" | |||
"gim/pkg/util" | |||
"time" | |||
) | |||
@@ -15,48 +16,49 @@ type authService struct{} | |||
var AuthService = new(authService) | |||
// SignIn 登录 | |||
func (*authService) SignIn(ctx context.Context, phoneNumber, code string, deviceId int64) (bool, int64, string, error) { | |||
func (*authService) SignIn(ctx context.Context, phoneNumber, code string, masterId int, deviceId int64) (bool, int64, string, int, error) { | |||
if !Verify(phoneNumber, code) { | |||
return false, 0, "", gerrors.ErrBadCode | |||
return false, 0, "", 0, gerrors.ErrBadCode | |||
} | |||
user, err := repo.UserRepo.GetByPhoneNumber(phoneNumber) | |||
if err != nil { | |||
return false, 0, "", err | |||
return false, 0, "", 0, err | |||
} | |||
var isNew = false | |||
if user == nil { | |||
user = &model.User{ | |||
PhoneNumber: phoneNumber, | |||
MasterId: masterId, | |||
CreateTime: time.Now(), | |||
UpdateTime: time.Now(), | |||
} | |||
err := repo.UserRepo.Save(user) | |||
if err != nil { | |||
return false, 0, "", err | |||
return false, 0, "", 0, err | |||
} | |||
isNew = true | |||
} | |||
resp, err := rpc.GetLogicIntClient().GetDevice(ctx, &pb.GetDeviceReq{DeviceId: deviceId}) | |||
if err != nil { | |||
return false, 0, "", err | |||
return false, 0, "", 0, err | |||
} | |||
// 方便测试 | |||
token := "0" | |||
//token := util.RandString(40) | |||
//token := "0" | |||
token := util.RandString(40) | |||
err = repo.AuthRepo.Set(user.Id, resp.Device.DeviceId, model.Device{ | |||
Type: resp.Device.Type, | |||
Token: token, | |||
Expire: time.Now().AddDate(0, 3, 0).Unix(), | |||
}) | |||
if err != nil { | |||
return false, 0, "", err | |||
return false, 0, "", 0, err | |||
} | |||
return isNew, user.Id, token, nil | |||
return isNew, user.Id, token, masterId, nil | |||
} | |||
func Verify(phoneNumber, code string) bool { | |||
@@ -15,7 +15,7 @@ import ( | |||
) | |||
func getLogicExtClient() pb.LogicExtClient { | |||
conn, err := grpc.Dial("111.229.238.28:50000", grpc.WithInsecure()) | |||
conn, err := grpc.Dial("im-rpc-logic.izhyin.com:8003", grpc.WithInsecure()) | |||
if err != nil { | |||
fmt.Println(err) | |||
return nil | |||
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: business.ext.proto | |||
// source: business.ext.proto_back | |||
package pb | |||
@@ -32,6 +32,7 @@ type SignInReq struct { | |||
PhoneNumber string `protobuf:"bytes,1,opt,name=phone_number,json=phoneNumber,proto3" json:"phone_number,omitempty"` // 手机号 | |||
Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` // 验证码 | |||
DeviceId int64 `protobuf:"varint,3,opt,name=device_id,json=deviceId,proto3" json:"device_id,omitempty"` // 设备id | |||
MasterId int `protobuf:"varint,4,opt,name=master_id,json=masterId,proto3" json:"master_id,omitempty"` // 站长id | |||
} | |||
func (x *SignInReq) Reset() { | |||
@@ -87,14 +88,22 @@ func (x *SignInReq) GetDeviceId() int64 { | |||
return 0 | |||
} | |||
func (x *SignInReq) GetMasterId() int { | |||
if x != nil { | |||
return x.MasterId | |||
} | |||
return 0 | |||
} | |||
type SignInResp struct { | |||
state protoimpl.MessageState | |||
sizeCache protoimpl.SizeCache | |||
unknownFields protoimpl.UnknownFields | |||
IsNew bool `protobuf:"varint,1,opt,name=is_new,json=isNew,proto3" json:"is_new,omitempty"` // 是否是新用户 | |||
UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 用户id | |||
Token string `protobuf:"bytes,3,opt,name=token,proto3" json:"token,omitempty"` // token | |||
IsNew bool `protobuf:"varint,1,opt,name=is_new,json=isNew,proto3" json:"is_new,omitempty"` // 是否是新用户 | |||
UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 用户id | |||
Token string `protobuf:"bytes,3,opt,name=token,proto3" json:"token,omitempty"` // token | |||
MasterId int `protobuf:"varint,4,opt,name=master_id,json=masterId,proto3" json:"master_id,omitempty"` // 站长id | |||
} | |||
func (x *SignInResp) Reset() { | |||
@@ -162,6 +171,7 @@ type User struct { | |||
Extra string `protobuf:"bytes,5,opt,name=extra,proto3" json:"extra,omitempty"` // 附加字段 | |||
CreateTime int64 `protobuf:"varint,6,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` // 创建时间 | |||
UpdateTime int64 `protobuf:"varint,7,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty"` // 更新时间 | |||
MasterId int `protobuf:"varint,8,opt,name=master_id,json=master_id,proto3" json:"master_id,omitempty"` // 更新时间 | |||
} | |||
func (x *User) Reset() { | |||
@@ -245,6 +255,13 @@ func (x *User) GetUpdateTime() int64 { | |||
return 0 | |||
} | |||
func (x *User) GetMasterId() int { | |||
if x != nil { | |||
return x.MasterId | |||
} | |||
return 0 | |||
} | |||
type GetUserReq struct { | |||
state protoimpl.MessageState | |||
sizeCache protoimpl.SizeCache | |||
@@ -926,5 +943,5 @@ var _BusinessExt_serviceDesc = grpc.ServiceDesc{ | |||
}, | |||
}, | |||
Streams: []grpc.StreamDesc{}, | |||
Metadata: "business.ext.proto", | |||
Metadata: "business.ext.proto_back", | |||
} |
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: business.int.proto | |||
// source: business.int.proto_back | |||
package pb | |||
@@ -484,5 +484,5 @@ var _BusinessInt_serviceDesc = grpc.ServiceDesc{ | |||
}, | |||
}, | |||
Streams: []grpc.StreamDesc{}, | |||
Metadata: "business.int.proto", | |||
Metadata: "business.int.proto_back", | |||
} |
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: common.ext.proto | |||
// source: common.ext.proto_back | |||
package pb | |||
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: connect.ext.proto | |||
// source: connect.ext.proto_back | |||
package pb | |||
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: connect.int.proto | |||
// source: connect.int.proto_back | |||
package pb | |||
@@ -391,5 +391,5 @@ var _ConnectInt_serviceDesc = grpc.ServiceDesc{ | |||
}, | |||
}, | |||
Streams: []grpc.StreamDesc{}, | |||
Metadata: "connect.int.proto", | |||
Metadata: "connect.int.proto_back", | |||
} |
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: logic.ext.proto | |||
// source: logic.ext.proto_back | |||
package pb | |||
@@ -2983,5 +2983,5 @@ var _LogicExt_serviceDesc = grpc.ServiceDesc{ | |||
}, | |||
}, | |||
Streams: []grpc.StreamDesc{}, | |||
Metadata: "logic.ext.proto", | |||
Metadata: "logic.ext.proto_back", | |||
} |
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: logic.int.proto | |||
// source: logic.int.proto_back | |||
package pb | |||
@@ -1543,5 +1543,5 @@ var _LogicInt_serviceDesc = grpc.ServiceDesc{ | |||
}, | |||
}, | |||
Streams: []grpc.StreamDesc{}, | |||
Metadata: "logic.int.proto", | |||
Metadata: "logic.int.proto_back", | |||
} |
@@ -2,7 +2,7 @@ | |||
// versions: | |||
// protoc-gen-go v1.26.0 | |||
// protoc v3.14.0 | |||
// source: push.ext.proto | |||
// source: push.ext.proto_back | |||
package pb | |||
@@ -0,0 +1,60 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
service BusinessExt { | |||
// 登录 | |||
rpc SignIn (SignInReq) returns (SignInResp); | |||
// 获取用户信息 | |||
rpc GetUser (GetUserReq) returns (GetUserResp); | |||
// 更新用户信息 | |||
rpc UpdateUser (UpdateUserReq) returns (Empty); | |||
// 搜索用户(这里简单数据库实现,生产环境建议使用ES) | |||
rpc SearchUser (SearchUserReq) returns (SearchUserResp); | |||
} | |||
message Empty{} | |||
message SignInReq { | |||
string phone_number = 1; // 手机号 | |||
string code = 2; // 验证码 | |||
int64 device_id = 3; // 设备id | |||
} | |||
message SignInResp { | |||
bool is_new = 1; // 是否是新用户 | |||
int64 user_id = 2; // 用户id | |||
string token = 3; // token | |||
} | |||
message User { | |||
int64 user_id = 1; // 用户id | |||
string nickname = 2; // 昵称 | |||
int32 sex = 3; // 性别 | |||
string avatar_url = 4; // 头像地址 | |||
string extra = 5; // 附加字段 | |||
int64 create_time = 6; // 创建时间 | |||
int64 update_time = 7; // 更新时间 | |||
} | |||
message GetUserReq { | |||
int64 user_id = 1; // 用户id | |||
} | |||
message GetUserResp { | |||
User user = 1; // 用户信息 | |||
} | |||
message UpdateUserReq { | |||
string nickname = 1; // 昵称 | |||
int32 sex = 2; // 性别 | |||
string avatar_url = 3; // 头像地址 | |||
string extra = 4; // 附加字段 | |||
} | |||
message SearchUserReq{ | |||
string key = 1; | |||
} | |||
message SearchUserResp{ | |||
repeated User users = 1; | |||
} | |||
@@ -0,0 +1,45 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
service BusinessInt { | |||
// 权限校验 | |||
rpc Auth (AuthReq) returns (Empty); | |||
// 批量获取用户信息 | |||
rpc GetUser (GetUserReq) returns (GetUserResp); | |||
// 批量获取用户信息 | |||
rpc GetUsers (GetUsersReq) returns (GetUsersResp); | |||
} | |||
message Empty{} | |||
message User { | |||
int64 user_id = 1; // 用户id | |||
string nickname = 2; // 昵称 | |||
int32 sex = 3; // 性别 | |||
string avatar_url = 4; // 头像地址 | |||
string extra = 5; // 附加字段 | |||
int64 create_time = 6; // 创建时间 | |||
int64 update_time = 7; // 更新时间 | |||
} | |||
message GetUserReq { | |||
int64 user_id = 1; // 用户id | |||
} | |||
message GetUserResp { | |||
User user = 1; // 用户信息 | |||
} | |||
message AuthReq { | |||
int64 user_id = 1; | |||
int64 device_id = 2; | |||
string token = 3; | |||
} | |||
message GetUsersReq { | |||
map<int64, int32> user_ids = 1; // 用户id | |||
} | |||
message GetUsersResp { | |||
map<int64, User> users = 1; // 用户信息 | |||
} |
@@ -0,0 +1,5 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
message Empty{} |
@@ -0,0 +1,174 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
enum PackageType { | |||
PT_UNKNOWN = 0; // 未知 | |||
PT_SIGN_IN = 1; // 设备登录请求 | |||
PT_SYNC = 2; // 消息同步触发 | |||
PT_HEARTBEAT = 3; // 心跳 | |||
PT_MESSAGE = 4; // 消息投递 | |||
PT_SUBSCRIBE_ROOM = 5; // 订阅房间 | |||
} | |||
/************************************消息体定义开始************************************/ | |||
// 单条消息投递内容(估算大约100个字节),todo 通知栏提醒 | |||
message Message { | |||
Sender sender = 1; // 发送者 | |||
ReceiverType receiver_type = 2; // 接收者类型,1:user;2:group | |||
int64 receiver_id = 3; // 用户id或者群组id | |||
repeated int64 to_user_ids = 4; // 需要@的用户id列表 | |||
MessageType message_type = 5; // 消息类型 | |||
bytes message_content = 6; // 消息内容 | |||
int64 seq = 7; // 用户消息发送序列号 | |||
int64 send_time = 8; // 消息发送时间戳,精确到毫秒 | |||
MessageStatus status = 9; // 消息状态 | |||
} | |||
message Sender { | |||
SenderType sender_type = 1; // 发送者类型,1:系统,2:用户,3:第三方业务系统 | |||
int64 sender_id = 2; // 发送者id | |||
int64 device_id = 3; // 发送者设备id | |||
string avatar_url = 4; // 昵称 | |||
string nickname = 5; // 头像 | |||
string extra = 6; // 扩展字段 | |||
} | |||
// 消息类型 | |||
enum MessageType { | |||
MT_UNKNOWN = 0; // 未知 | |||
MT_TEXT = 1; // 文本 | |||
MT_FACE = 2; // 表情 | |||
MT_VOICE = 3; // 语音消息 | |||
MT_IMAGE = 4; // 图片 | |||
MT_FILE = 5; // 文件 | |||
MT_LOCATION = 6; // 地理位置 | |||
MT_COMMAND = 7; // 指令推送 | |||
MT_CUSTOM = 8; // 自定义 | |||
} | |||
// 文本消息 | |||
message Text { | |||
string text = 1; // 文本消息内容 | |||
} | |||
// 表情消息 | |||
message Face { | |||
int64 face_id = 1; | |||
string face_url = 2; | |||
} | |||
// 语音消息 | |||
message Voice { | |||
string id = 1; // 语音包id | |||
int32 size = 2; // 语音包大小 | |||
int32 duration = 3; // 语音时长 | |||
string url = 4; // 语音文件URL | |||
} | |||
// 图片消息 | |||
message Image { | |||
string id = 1; // 图片id | |||
int32 width = 2; // 图片宽度 | |||
int32 height = 3; // 图片长度 | |||
string url = 4; // 图片URL | |||
string thumbnail_url = 5; // 图片缩略图url | |||
} | |||
// 文件消息 | |||
message File { | |||
int64 id = 12; // 文件id | |||
string name = 13; // 文件名 | |||
int64 size = 14; // 文件大小 | |||
string url = 15; // 文件url | |||
} | |||
// 地理位置消息 | |||
message Location { | |||
string desc = 1; // 描述 | |||
double latitude = 2; // 经度 | |||
double longitude = 3; // 纬度 | |||
} | |||
// Command 指令推送,1000以下,IM内部用,1000以上,留给业务用 | |||
message Command { | |||
int32 code = 1; // 指令码 | |||
bytes data = 2; // 数据内容 | |||
} | |||
// 自定义消息 | |||
message Custom { | |||
string data = 1; // 自定义数据 | |||
} | |||
/************************************消息体定义结束************************************/ | |||
// 上行数据 | |||
message Input { | |||
PackageType type = 1; // 包的类型 | |||
int64 request_id = 2; // 请求id | |||
bytes data = 3; // 数据 | |||
} | |||
// 下行数据 | |||
message Output { | |||
PackageType type = 1; // 包的类型 | |||
int64 request_id = 2; // 请求id | |||
int32 code = 3; // 错误码 | |||
string message = 4; // 错误信息 | |||
bytes data = 5; // 数据 | |||
} | |||
// 设备登录,package_type:1 | |||
message SignInInput { | |||
int64 device_id = 1; // 设备id | |||
int64 user_id = 2; // 用户id | |||
string token = 3; // 秘钥 | |||
} | |||
// 消息同步请求,package_type:2 | |||
message SyncInput { | |||
int64 seq = 1; // 客户端已经同步的序列号 | |||
} | |||
// 消息同步响应,package_type:2 | |||
message SyncOutput { | |||
repeated Message messages = 1; // 消息列表 | |||
bool has_more = 2; // 是否有更多数据 | |||
} | |||
// 订阅房间请求 | |||
message SubscribeRoomInput { | |||
int64 room_id = 1; // 房间ID,如果为0,取消房间订阅 | |||
int64 seq = 2; // 消息消息序列号, | |||
} | |||
enum ReceiverType { | |||
RT_UNKNOWN = 0; // 未知 | |||
RT_USER = 1; // 用户 | |||
RT_GROUP = 2; // 群组 | |||
RT_ROOM = 3; // 房间 | |||
} | |||
// 消息投递,package_type:4 | |||
message MessageSend { | |||
Message message = 1; // 消息 | |||
} | |||
enum SenderType { | |||
ST_UNKNOWN = 0; // 未知的 | |||
ST_SYSTEM = 1; // IM系统 | |||
ST_USER = 2; // 用户 | |||
ST_BUSINESS = 3; // 业务方 | |||
} | |||
enum MessageStatus { | |||
MS_UNKNOWN = 0; // 未知的 | |||
MS_NORMAL = 1; // 正常的 | |||
MS_RECALL = 2; // 撤回 | |||
} | |||
// 投递消息回执,package_type:4 | |||
message MessageACK { | |||
int64 device_ack = 2; // 设备收到消息的确认号 | |||
int64 receive_time = 3; // 消息接收时间戳,精确到毫秒 | |||
} |
@@ -0,0 +1,83 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
service ConnectInt { | |||
// 消息投递 | |||
rpc DeliverMessage (DeliverMessageReq) returns (Empty); | |||
} | |||
message Empty{} | |||
enum SenderType { | |||
ST_UNKNOWN = 0; // 未知的 | |||
ST_SYSTEM = 1; // IM系统 | |||
ST_USER = 2; // 用户 | |||
ST_BUSINESS = 3; // 业务方 | |||
} | |||
message Sender { | |||
SenderType sender_type = 1; // 发送者类型,1:系统,2:用户,3:第三方业务系统 | |||
int64 sender_id = 2; // 发送者id | |||
int64 device_id = 3; // 发送者设备id | |||
string avatar_url = 4; // 昵称 | |||
string nickname = 5; // 头像 | |||
string extra = 6; // 扩展字段 | |||
} | |||
enum ReceiverType { | |||
RT_UNKNOWN = 0; // 未知 | |||
RT_USER = 1; // 用户 | |||
RT_GROUP = 2; // 群组 | |||
RT_ROOM = 3; // 房间 | |||
} | |||
// 单条消息投递内容(估算大约100个字节),todo 通知栏提醒 | |||
message Message { | |||
Sender sender = 1; // 发送者 | |||
ReceiverType receiver_type = 2; // 接收者类型,1:user;2:group | |||
int64 receiver_id = 3; // 用户id或者群组id | |||
repeated int64 to_user_ids = 4; // 需要@的用户id列表 | |||
MessageType message_type = 5; // 消息类型 | |||
bytes message_content = 6; // 消息内容 | |||
int64 seq = 7; // 用户消息发送序列号 | |||
int64 send_time = 8; // 消息发送时间戳,精确到毫秒 | |||
MessageStatus status = 9; // 消息状态 | |||
} | |||
enum MessageStatus { | |||
MS_UNKNOWN = 0; // 未知的 | |||
MS_NORMAL = 1; // 正常的 | |||
MS_RECALL = 2; // 撤回 | |||
} | |||
// 消息类型 | |||
enum MessageType { | |||
MT_UNKNOWN = 0; // 未知 | |||
MT_TEXT = 1; // 文本 | |||
MT_FACE = 2; // 表情 | |||
MT_VOICE = 3; // 语音消息 | |||
MT_IMAGE = 4; // 图片 | |||
MT_FILE = 5; // 文件 | |||
MT_LOCATION = 6; // 地理位置 | |||
MT_COMMAND = 7; // 指令推送 | |||
MT_CUSTOM = 8; // 自定义 | |||
} | |||
// 消息投递,package_type:4 | |||
message MessageSend { | |||
Message message = 1; // 消息 | |||
} | |||
message DeliverMessageReq { | |||
int64 device_id = 1; // 设备id | |||
MessageSend message_send = 2; // 数据 | |||
} | |||
// 房间推送 | |||
message PushRoomMsg{ | |||
int64 room_id = 1; // 设备id | |||
MessageSend message_send = 2; // 数据 | |||
} | |||
// 房间推送 | |||
message PushAllMsg{ | |||
MessageSend message_send = 2; // 数据 | |||
} | |||
@@ -0,0 +1,212 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
message Empty{} | |||
service LogicExt { | |||
// 注册设备 | |||
rpc RegisterDevice (RegisterDeviceReq) returns (RegisterDeviceResp); | |||
// 发送消息 | |||
rpc SendMessage (SendMessageReq) returns (SendMessageResp); | |||
// 推送消息到房间 | |||
rpc PushRoom(PushRoomReq)returns(Empty); | |||
// 添加好友 | |||
rpc AddFriend (AddFriendReq) returns (Empty); | |||
// 同意添加好友 | |||
rpc AgreeAddFriend (AgreeAddFriendReq) returns (Empty); | |||
// 设置好友信息 | |||
rpc SetFriend (SetFriendReq) returns (SetFriendResp); | |||
// 获取好友列表 | |||
rpc GetFriends (Empty) returns (GetFriendsResp); | |||
// 创建群组 | |||
rpc CreateGroup (CreateGroupReq) returns (CreateGroupResp); | |||
// 更新群组 | |||
rpc UpdateGroup (UpdateGroupReq) returns (Empty); | |||
// 获取群组信息 | |||
rpc GetGroup (GetGroupReq) returns (GetGroupResp); | |||
// 获取用户加入的所有群组 | |||
rpc GetGroups (Empty) returns (GetGroupsResp); | |||
// 添加群组成员 | |||
rpc AddGroupMembers (AddGroupMembersReq) returns (AddGroupMembersResp); | |||
// 更新群组成员信息 | |||
rpc UpdateGroupMember (UpdateGroupMemberReq) returns (Empty); | |||
// 添加群组成员 | |||
rpc DeleteGroupMember (DeleteGroupMemberReq) returns (Empty); | |||
// 获取群组成员 | |||
rpc GetGroupMembers (GetGroupMembersReq) returns (GetGroupMembersResp); | |||
} | |||
message RegisterDeviceReq { | |||
int32 type = 2; // 设备类型 | |||
string brand = 3; // 厂商 | |||
string model = 4; // 机型 | |||
string system_version = 5; // 系统版本 | |||
string sdk_version = 6; // sdk版本号 | |||
} | |||
message RegisterDeviceResp { | |||
int64 device_id = 1; // 设备id | |||
} | |||
enum ReceiverType { | |||
RT_UNKNOWN = 0; // 未知 | |||
RT_USER = 1; // 用户 | |||
RT_GROUP = 2; // 群组 | |||
RT_ROOM = 3; // 房间 | |||
} | |||
message SendMessageReq { | |||
ReceiverType receiver_type = 1; // 接收者类型,1:user;2:group | |||
int64 receiver_id = 2; // 用户id或者群组id | |||
repeated int64 to_user_ids = 3; // 需要@的用户id列表 | |||
MessageType message_type = 4; // 消息类型 | |||
bytes message_content = 5; // 消息内容 | |||
int64 send_time = 6; // 消息发送时间戳,精确到毫秒 | |||
bool is_persist = 7; // 是否将消息持久化到数据库 | |||
} | |||
message SendMessageResp { | |||
int64 seq = 1; // 消息序列号 | |||
} | |||
// 消息类型 | |||
enum MessageType { | |||
MT_UNKNOWN = 0; // 未知 | |||
MT_TEXT = 1; // 文本 | |||
MT_FACE = 2; // 表情 | |||
MT_VOICE = 3; // 语音消息 | |||
MT_IMAGE = 4; // 图片 | |||
MT_FILE = 5; // 文件 | |||
MT_LOCATION = 6; // 地理位置 | |||
MT_COMMAND = 7; // 指令推送 | |||
MT_CUSTOM = 8; // 自定义 | |||
} | |||
message PushRoomReq{ | |||
int64 room_id = 1; // 房间id | |||
MessageType message_type = 2; // 消息类型 | |||
bytes message_content = 3; // 消息内容 | |||
int64 send_time = 4; // 消息发送时间戳,精确到毫秒 | |||
bool is_persist = 5; // 是否将消息持久化 | |||
bool is_priority = 6; // 是否优先推送 | |||
} | |||
message AddFriendReq { | |||
int64 friend_id = 1; // 用户id | |||
string remarks = 2; // 备注 | |||
string description = 3; // 描述 | |||
} | |||
message AgreeAddFriendReq { | |||
int64 user_id = 1; // 用户id | |||
string remarks = 2; // 备注 | |||
} | |||
message SetFriendReq { | |||
int64 friend_id = 1; // 好友id | |||
string remarks = 2; // 备注 | |||
string extra = 8; // 附加字段 | |||
} | |||
message SetFriendResp { | |||
int64 friend_id = 1; // 好友id | |||
string remarks = 2; // 备注 | |||
string extra = 8; // 附加字段 | |||
} | |||
message Friend { | |||
int64 user_id = 1; // 用户id | |||
string phone_number = 2; // 电话号码 | |||
string nickname = 3; // 昵称 | |||
int32 sex = 4; // 性别 | |||
string avatar_url = 5; // 头像地址 | |||
string user_extra = 6; // 用户附加字段 | |||
string remarks = 7; // 备注 | |||
string extra = 8; // 附加字段 | |||
} | |||
message GetFriendsResp { | |||
repeated Friend friends = 1; | |||
} | |||
message CreateGroupReq { | |||
string name = 1; // 名称 | |||
string avatar_url = 2; // 头像 | |||
string introduction = 3; // 简介 | |||
string extra = 4; // 附加字段 | |||
repeated int64 member_ids = 5; // 群组成员ID列表 | |||
} | |||
message CreateGroupResp { | |||
int64 group_id = 1; // 群组id | |||
} | |||
message UpdateGroupReq { | |||
int64 group_id = 1; // 群组id | |||
string avatar_url = 2; // 头像 | |||
string name = 3; // 名称 | |||
string introduction = 4; // 简介 | |||
string extra = 5; // 附加字段 | |||
} | |||
message GetGroupReq { | |||
int64 group_id = 1; | |||
} | |||
message GetGroupResp { | |||
Group group = 1; | |||
} | |||
message Group { | |||
int64 group_id = 1; // 群组id | |||
string name = 2; // 名称 | |||
string avatar_url = 3; // 头像 | |||
string introduction = 4; // 简介 | |||
int32 user_mum = 5; // 用户数 | |||
string extra = 6; // 附加字段 | |||
int64 create_time = 7; // 创建时间 | |||
int64 update_time = 8; // 更新时间 | |||
} | |||
message GetGroupsResp { | |||
repeated Group groups = 1; | |||
} | |||
message AddGroupMembersReq { | |||
int64 group_id = 1; // 群组id | |||
repeated int64 user_ids = 2; // 用户id列表 | |||
} | |||
message AddGroupMembersResp { | |||
repeated int64 user_ids = 1; // 已经在群组的用户id列表 | |||
} | |||
enum MemberType { | |||
GMT_UNKNOWN = 0; // 未知 | |||
GMT_ADMIN = 1; // 管理员 | |||
GMT_MEMBER = 2; // 成员 | |||
} | |||
message UpdateGroupMemberReq { | |||
int64 group_id = 1; // 群组id | |||
int64 user_id = 2; // 用户id | |||
MemberType member_type = 3; // 成员类型 | |||
string remarks = 4; // 备注 | |||
string extra = 5; // 附加字段 | |||
} | |||
message DeleteGroupMemberReq { | |||
int64 group_id = 1; // 群组id | |||
int64 user_id = 2; // 用户id | |||
} | |||
message GetGroupMembersReq { | |||
int64 group_id = 1; | |||
} | |||
message GetGroupMembersResp { | |||
repeated GroupMember members = 1; | |||
} | |||
message GroupMember { | |||
int64 user_id = 1; | |||
string nickname = 2; // 昵称 | |||
int32 sex = 3; // 性别 | |||
string avatar_url = 4; // 头像地址 | |||
string user_extra = 5; // 用户附加字段 | |||
MemberType member_type = 6; // 成员类型 | |||
string remarks = 7; // 备注 | |||
string extra = 8; // 群组成员附加字段 | |||
} |
@@ -0,0 +1,177 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
message Empty{} | |||
service LogicInt { | |||
// 登录 | |||
rpc ConnSignIn (ConnSignInReq) returns (Empty); | |||
// 消息同步 | |||
rpc Sync (SyncReq) returns (SyncResp); | |||
// 设备收到消息回执 | |||
rpc MessageACK (MessageACKReq) returns (Empty); | |||
// 设备离线 | |||
rpc Offline (OfflineReq) returns (Empty); | |||
// 订阅房间 | |||
rpc SubscribeRoom(SubscribeRoomReq)returns(Empty); | |||
// 发送消息 | |||
rpc SendMessage (SendMessageReq) returns (SendMessageResp); | |||
// 推送消息到房间 | |||
rpc PushRoom(PushRoomReq)returns(Empty); | |||
// 全服推送 | |||
rpc PushAll(PushAllReq)returns(Empty); | |||
// 获取设备信息 | |||
rpc GetDevice (GetDeviceReq) returns (GetDeviceResp); | |||
// 服务停止 | |||
rpc ServerStop (ServerStopReq) returns (Empty); | |||
} | |||
message PushRoomReq{ | |||
int64 room_id = 1; // 房间id | |||
MessageType message_type = 2; // 消息类型 | |||
bytes message_content = 3; // 消息内容 | |||
int64 send_time = 4; // 消息发送时间戳,精确到毫秒 | |||
bool is_persist = 5; // 是否将消息持久化 | |||
bool is_priority = 6; // 是否优先推送 | |||
} | |||
message SendMessageResp { | |||
int64 seq = 1; // 消息序列号 | |||
} | |||
message SendMessageReq { | |||
ReceiverType receiver_type = 1; // 接收者类型,1:user;2:group | |||
int64 receiver_id = 2; // 用户id或者群组id | |||
repeated int64 to_user_ids = 3; // 需要@的用户id列表 | |||
MessageType message_type = 4; // 消息类型 | |||
bytes message_content = 5; // 消息内容 | |||
int64 send_time = 6; // 消息发送时间戳,精确到毫秒 | |||
bool is_persist = 7; // 是否将消息持久化到数据库 | |||
} | |||
enum ReceiverType { | |||
RT_UNKNOWN = 0; // 未知 | |||
RT_USER = 1; // 用户 | |||
RT_GROUP = 2; // 群组 | |||
RT_ROOM = 3; // 房间 | |||
} | |||
// 消息类型 | |||
enum MessageType { | |||
MT_UNKNOWN = 0; // 未知 | |||
MT_TEXT = 1; // 文本 | |||
MT_FACE = 2; // 表情 | |||
MT_VOICE = 3; // 语音消息 | |||
MT_IMAGE = 4; // 图片 | |||
MT_FILE = 5; // 文件 | |||
MT_LOCATION = 6; // 地理位置 | |||
MT_COMMAND = 7; // 指令推送 | |||
MT_CUSTOM = 8; // 自定义 | |||
} | |||
enum SenderType { | |||
ST_UNKNOWN = 0; // 未知的 | |||
ST_SYSTEM = 1; // IM系统 | |||
ST_USER = 2; // 用户 | |||
ST_BUSINESS = 3; // 业务方 | |||
} | |||
message Sender { | |||
SenderType sender_type = 1; // 发送者类型,1:系统,2:用户,3:第三方业务系统 | |||
int64 sender_id = 2; // 发送者id | |||
int64 device_id = 3; // 发送者设备id | |||
string avatar_url = 4; // 昵称 | |||
string nickname = 5; // 头像 | |||
string extra = 6; // 扩展字段 | |||
} | |||
// 单条消息投递内容(估算大约100个字节),todo 通知栏提醒 | |||
message Message { | |||
Sender sender = 1; // 发送者 | |||
ReceiverType receiver_type = 2; // 接收者类型,1:user;2:group | |||
int64 receiver_id = 3; // 用户id或者群组id | |||
repeated int64 to_user_ids = 4; // 需要@的用户id列表 | |||
MessageType message_type = 5; // 消息类型 | |||
bytes message_content = 6; // 消息内容 | |||
int64 seq = 7; // 用户消息发送序列号 | |||
int64 send_time = 8; // 消息发送时间戳,精确到毫秒 | |||
MessageStatus status = 9; // 消息状态 | |||
} | |||
enum MessageStatus { | |||
MS_UNKNOWN = 0; // 未知的 | |||
MS_NORMAL = 1; // 正常的 | |||
MS_RECALL = 2; // 撤回 | |||
} | |||
message ConnSignInReq { | |||
int64 device_id = 1; // 设备id | |||
int64 user_id = 2; // 用户id | |||
string token = 3; // 秘钥 | |||
string conn_addr = 4; // 服务器地址 | |||
string client_addr = 5; // 客户端地址 | |||
} | |||
message SyncReq { | |||
int64 user_id = 1; // 用户id | |||
int64 device_id = 2; // 设备id | |||
int64 seq = 3; // 客户端已经同步的序列号 | |||
} | |||
message SyncResp { | |||
repeated Message messages = 1; // 消息列表 | |||
bool has_more = 2; // 是否有更多数据 | |||
} | |||
message MessageACKReq { | |||
int64 user_id = 1; // 用户id | |||
int64 device_id = 2; // 设备id | |||
int64 device_ack = 3; // 设备收到消息的确认号 | |||
int64 receive_time = 4; // 消息接收时间戳,精确到毫秒 | |||
} | |||
message OfflineReq { | |||
int64 user_id = 1; // 用户id | |||
int64 device_id = 2; // 设备id | |||
string client_addr = 3; // 客户端地址 | |||
} | |||
message SubscribeRoomReq{ | |||
int64 user_id = 1; // 用户id | |||
int64 device_id = 2; // 设备id | |||
int64 room_id = 3; // 房间id | |||
int64 seq = 4; // 消息序列号 | |||
string conn_addr = 5; // 服务器地址 | |||
} | |||
message PushAllReq{ | |||
MessageType message_type = 1; // 消息类型 | |||
bytes message_content = 2; // 消息内容 | |||
int64 send_time = 3; // 消息发送时间戳,精确到毫秒 | |||
} | |||
message GetDeviceReq { | |||
int64 device_id = 1; | |||
} | |||
message GetDeviceResp { | |||
Device device = 1; | |||
} | |||
message Device { | |||
int64 device_id = 1; // 设备id | |||
int64 user_id = 2; // 用户id | |||
int32 type = 3; // 设备类型,1:Android;2:IOS;3:Windows; 4:MacOS;5:Web | |||
string brand = 4; // 手机厂商 | |||
string model = 5; // 机型 | |||
string system_version = 6; // 系统版本 | |||
string sdk_version = 7; // SDK版本 | |||
int32 status = 8; // 在线状态,0:不在线;1:在线 | |||
string conn_addr = 9; // 服务端连接地址 | |||
string client_addr = 10; // 客户端地址 | |||
int64 create_time = 11; // 创建时间 | |||
int64 update_time = 12; // 更新时间 | |||
} | |||
message ServerStopReq { | |||
string conn_addr = 1; | |||
} |
@@ -0,0 +1,71 @@ | |||
syntax = "proto3"; | |||
package pb; | |||
option go_package = "gim/pkg/pb/"; | |||
enum PushCode { | |||
PC_ADD_DEFAULT = 0; | |||
PC_ADD_FRIEND = 100; // 添加好友请求 | |||
PC_AGREE_ADD_FRIEND = 101; // 同意添加好友 | |||
PC_UPDATE_GROUP = 110; // 更新群组 | |||
PC_ADD_GROUP_MEMBERS = 120; // 添加群组成员 | |||
PC_REMOVE_GROUP_MEMBER = 121; // 移除群组成员 | |||
} | |||
// 推送码 PC_ADD_FRIEND = 100 | |||
message AddFriendPush { | |||
int64 friend_id = 1; // 好友id | |||
string nickname = 2; // 昵称 | |||
string avatar_url = 3; // 头像 | |||
string description = 4; // 描述 | |||
} | |||
// 推送码 PC_AGREE_ADD_FRIEND = 101 | |||
message AgreeAddFriendPush { | |||
int64 friend_id = 1; // 好友id | |||
string nickname = 2; // 昵称 | |||
string avatar_url = 3; // 头像 | |||
} | |||
// 更新群组 PC_UPDATE_GROUP = 110 | |||
message UpdateGroupPush { | |||
int64 opt_id = 1; // 操作人用户id | |||
string opt_name = 2; // 操作人昵称 | |||
string name = 3; // 群组名称 | |||
string avatar_url = 4; // 群组头像 | |||
string introduction = 5; // 群组简介 | |||
string extra = 6; // 附加字段 | |||
} | |||
// 添加群组成员 PC_AGREE_ADD_GROUPS = 120 | |||
message AddGroupMembersPush { | |||
int64 opt_id = 1; // 操作人用户id | |||
string opt_name = 2; // 操作人昵称 | |||
repeated GroupMember members = 3; // 群组成员 | |||
} | |||
// 删除群组成员 PC_REMOVE_GROUP_MEMBER = 121 | |||
message RemoveGroupMemberPush { | |||
int64 opt_id = 1; // 操作人用户id | |||
string opt_name = 2; // 操作人昵称 | |||
int64 deleted_user_id = 3; // 被删除的成员id | |||
} | |||
enum MemberType { | |||
GMT_UNKNOWN = 0; // 未知 | |||
GMT_ADMIN = 1; // 管理员 | |||
GMT_MEMBER = 2; // 成员 | |||
} | |||
message GroupMember { | |||
int64 user_id = 1; | |||
string nickname = 2; // 昵称 | |||
int32 sex = 3; // 性别 | |||
string avatar_url = 4; // 头像地址 | |||
string user_extra = 5; // 用户附加字段 | |||
MemberType member_type = 6; // 成员类型 | |||
string remarks = 7; // 备注 | |||
string extra = 8; // 群组成员附加字段 | |||
} |