Skip to content

Commit

Permalink
update code2session param
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjiayu committed Jul 23, 2024
1 parent a61231b commit 1b64d26
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.2
require (
github.com/go-sql-driver/mysql v1.8.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/pkusunjy/openai-server-proto v1.1.10
github.com/pkusunjy/openai-server-proto v1.1.11
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
google.golang.org/grpc v1.65.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkusunjy/openai-server-proto v1.1.10 h1:jcMMbrRsm/ycZSbXFJS054HdxhDMk5DhKtYM/7I6UR8=
github.com/pkusunjy/openai-server-proto v1.1.10/go.mod h1:Wy8DZHkU9TDe5/NvBxukAWoDfzclahb1y3B7+b+DaBI=
github.com/pkusunjy/openai-server-proto v1.1.11 h1:PUabIi+bBWhtxmkjKGFt69Mo0JgKimhg44g6M4GGa8s=
github.com/pkusunjy/openai-server-proto v1.1.11/go.mod h1:Wy8DZHkU9TDe5/NvBxukAWoDfzclahb1y3B7+b+DaBI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand Down
13 changes: 4 additions & 9 deletions service/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (server AuthServiceImpl) GetOssToken(ctx context.Context, req *auth.AuthReq
return &resp, nil
}

func (server AuthServiceImpl) Jscode2Session(ctx context.Context, req *auth.AuthRequest) (*auth.AuthResponse, error) {
func (server AuthServiceImpl) Jscode2Session(ctx context.Context, req *auth.Code2SessionRequest) (*auth.Code2SessionResponse, error) {
url := fmt.Sprintf(code2SessionUrl, server.WxAppID, server.WxSecret, req.Code)
grpclog.Infof("code2session gen url: %s", url)
code2SessionResp, err := http.DefaultClient.Get(url)
Expand All @@ -75,17 +75,12 @@ func (server AuthServiceImpl) Jscode2Session(ctx context.Context, req *auth.Auth
return nil, err
}
defer code2SessionResp.Body.Close()
var wxMap map[string]string
err = json.NewDecoder(code2SessionResp.Body).Decode(&wxMap)
resp := auth.Code2SessionResponse{}
err = json.NewDecoder(code2SessionResp.Body).Decode(&resp)
if err != nil {
grpclog.Errorf("code2session json decode fail, err:%v", err)
return nil, err
}
grpclog.Infof("code2session wxMap:%+v", wxMap)
resp := auth.AuthResponse{
Openid: wxMap["openid"],
SessionKey: wxMap["session_key"],
Unionid: wxMap["unionid"],
}
grpclog.Infof("code2session resp:%+v", &resp)
return &resp, nil
}

0 comments on commit 1b64d26

Please sign in to comment.