diff --git a/cmd/mp-auth-http/main.go b/cmd/mp-auth-http/main.go index bef0e87..61ad3d9 100644 --- a/cmd/mp-auth-http/main.go +++ b/cmd/mp-auth-http/main.go @@ -7,6 +7,7 @@ import ( pb "git.esin.io/lab/weixin/protobuf/clientapi/mp/auth" "google.golang.org/grpc" + "google.golang.org/protobuf/types/known/emptypb" ) var ( @@ -43,6 +44,7 @@ func run() error { http.HandleFunc("/token", h.exchangeToken) http.HandleFunc("/userinfo", h.getUserinfo) http.HandleFunc("/userinfo/sync", h.syncUserinfo) + http.HandleFunc("/clientcredential", h.getClientCredential) return http.ListenAndServe(":"+lisPort, nil) } @@ -111,3 +113,12 @@ func (h restHandler) syncUserinfo(w http.ResponseWriter, r *http.Request) { } json.NewEncoder(w).Encode(resp) } + +func (h restHandler) getClientCredential(w http.ResponseWriter, r *http.Request) { + resp, err := h.client.GetClientCredential(r.Context(), &emptypb.Empty{}) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + json.NewEncoder(w).Encode(resp) +}