Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
it512 committed Dec 16, 2024
1 parent 886793c commit b0ffa8c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions wechat/cmd/wechat-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetEnv(env string) string {

func main() {
appId := GetEnv(WECHAT_APPID)
appSecret :=GetEnv(WECHAT_APPSECRET)
appSecret := GetEnv(WECHAT_APPSECRET)
addr := GetEnv(SERVER_ADDR)
/*
mchId := os.Getenv(WECHAT_MCHID)
Expand All @@ -63,7 +63,7 @@ func main() {

mux := chi.NewMux()
mux.Use(middleware.Logger, middleware.Recoverer)
mux.Mount("/rpc", gql.New(auth))
mux.Mount("/gqlrpc", gql.New(auth))
//mux.Mount("/wxnotify", bc.WxBCNotify())

svr := web.NewHttpServer(ctx, addr, mux)
Expand Down
4 changes: 2 additions & 2 deletions wechat/rpc/gql/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func New(a *sns.Auth) chi.Router {
srv := rpc.New(es)

r := chi.NewRouter()
r.Handle("/", playground.ApolloSandboxHandler("rpc", "/rpc/gql"))
r.Handle("/gql", srv)
r.Handle("/", playground.ApolloSandboxHandler("rpc", "/gqlrpc/query"))
r.Handle("/query", srv)

return r
}
11 changes: 7 additions & 4 deletions wxlogin/cmd/wxlogin/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"context"
"log"
"net/http"
"os"
Expand All @@ -10,9 +10,11 @@ import (

"github.com/Khan/genqlient/graphql"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"

"github.com/twiglab/crm/wxlogin"
"github.com/twiglab/crm/wxlogin/gql"
"github.com/twiglab/crm/wxlogin/web"
"github.com/twiglab/crm/wxlogin/wx"
)

Expand Down Expand Up @@ -48,12 +50,13 @@ func main() {

root := chi.NewMux()

root.Use(middleware.Logger, middleware.Recoverer)

root.Mount("/gql", gql.GQLRouter(cli))
root.Mount("/jwt", wxlogin.JWTVerify(secret))

if err := http.ListenAndServe(addr, root); err != nil {
svr := web.NewHttpServer(context.Background(), addr, root)
if err := web.RunServer(context.Background(), svr); err != nil {
log.Fatal(err)
}

fmt.Println(mb)
}
2 changes: 1 addition & 1 deletion wxlogin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/twiglab/crm/member v0.0.0-20241116061244-2ba4efae26f1
github.com/twiglab/crm/wechat v0.0.0-20241116061244-2ba4efae26f1
github.com/twiglab/crm/wechat v0.0.0-20241216131727-886793cf0a25
github.com/vektah/gqlparser/v2 v2.5.20
)

Expand Down
2 changes: 2 additions & 0 deletions wxlogin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/twiglab/crm/member v0.0.0-20241116061244-2ba4efae26f1 h1:JnPUqp1Jgrxr
github.com/twiglab/crm/member v0.0.0-20241116061244-2ba4efae26f1/go.mod h1:dV6ntWKUnXXLbCzYkNU2d1jjD9FKUOcZon1SJ+X20xo=
github.com/twiglab/crm/wechat v0.0.0-20241116061244-2ba4efae26f1 h1:wjngLNRqau18Vqn6ybCn4Ws2U1fwehXrQJ0sEWLDsh8=
github.com/twiglab/crm/wechat v0.0.0-20241116061244-2ba4efae26f1/go.mod h1:gXsub5c9PNnxisPDWoDkAwKrt99MeUYgAb0ehGZRyTk=
github.com/twiglab/crm/wechat v0.0.0-20241216131727-886793cf0a25 h1:+nB/i8TimBVTxif2trD0S52Znpk3vb7HIZ3ozVtfvrA=
github.com/twiglab/crm/wechat v0.0.0-20241216131727-886793cf0a25/go.mod h1:lEvPdYOttpqGXb+ywgx4iLZlUdh9W8LGwSknlYEYDYs=
github.com/vektah/gqlparser/v2 v2.5.20 h1:kPaWbhBntxoZPaNdBaIPT1Kh0i1b/onb5kXgEdP5JCo=
github.com/vektah/gqlparser/v2 v2.5.20/go.mod h1:xMl+ta8a5M1Yo1A1Iwt/k7gSpscwSnHZdw7tfhEGfTM=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
Expand Down
4 changes: 2 additions & 2 deletions wxlogin/gql/gql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func GQLRouter(acli *wxlogin.AuthClient) chi.Router {
))

r := chi.NewRouter()
r.Handle("/", playground.ApolloSandboxHandler("pg", "/gql"))
r.Handle("/gql", srv)
r.Handle("/", playground.ApolloSandboxHandler("pg", "/gql/query"))
r.Handle("/query", srv)

return r
}
2 changes: 1 addition & 1 deletion wxlogin/gql/graph/login.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion wxlogin/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type AuthJWTConfig struct {
type X struct {
Jwt string
Code string
OpenID string
Claims *jwt.Claims
}

Expand All @@ -33,6 +34,24 @@ type AuthClient struct {
// AuthJWTConfig AuthJWTConfig
}

func (x *AuthClient) Login3(ctx context.Context, jsCode string) (*X, error) {
codes, err := x.WxCli.AuthUser(ctx, jsCode)
if err != nil {
return nil, err
}

Code := uuid.NewString()

claims := NewClaims(Code)

jwt, err := signed(claims, x.Secret)
if err != nil {
return nil, err
}

return &X{Jwt: jwt, Code: Code, OpenID: codes.OpenID, Claims: claims}, nil
}

func (x *AuthClient) Login2(ctx context.Context, jsCode string) (*X, error) {
codes, err := x.WxCli.AuthUser(ctx, jsCode)
if err != nil {
Expand All @@ -51,7 +70,7 @@ func (x *AuthClient) Login2(ctx context.Context, jsCode string) (*X, error) {
return nil, err
}

return &X{Jwt: jwt, Code: member.Code, Claims: claims}, nil
return &X{Jwt: jwt, Code: member.Code, OpenID: codes.OpenID, Claims: claims}, nil
}

func NewClaims(code string) *jwt.Claims {
Expand Down
6 changes: 3 additions & 3 deletions wxlogin/wx/wx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"

"github.com/Khan/genqlient/graphql"
"github.com/twiglab/crm/wechat/pkg/data"
"github.com/twiglab/crm/wechat/pkg/low"
"github.com/twiglab/crm/wechat/pkg/sns"
"github.com/twiglab/crm/wechat/pkg/sns/low"
)

type WxCli struct {
Expand All @@ -24,7 +24,7 @@ type Codes struct {
// @return *Codes
// @return error
func (c *WxCli) AuthUser(ctx context.Context, jsCode string) (*Codes, error) {
resp, err := low.AuthUser(ctx, c.Client, data.JsCodeReq{JsCode: jsCode})
resp, err := low.AuthUser(ctx, c.Client, sns.JsCodeReq{JsCode: jsCode})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b0ffa8c

Please sign in to comment.