feat: add getclientcredential func to http handler

This commit is contained in:
lab 2021-11-10 03:19:50 +08:00
parent 18c2b5986b
commit a21afc9719

View File

@ -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)
}