Skip to content

Commit

Permalink
qrcode接口修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Kotodian committed Dec 13, 2022
1 parent 619b9c7 commit 7058d2b
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions api/jxcoregw.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,36 @@ func NotifyEvent(hostname, clientID string, req *charger.WarningReq) error {
return handleRequest(url, hostname, req)
}

func QRCode(hostname, clientID string, req *charger.QRCodeReq) error {
type QRCodeResponse struct {
Response
QRCode string `json:"qrCode"`
}

func QRCode(hostname, clientID string, req *charger.QRCodeReq) (string, error) {
url := coregwUrlPrefix + "/qrCode/" + clientID
return handleRequest(url, hostname, req)
resp := &QRCodeResponse{}
err := handleRequestWithResponse(url, hostname, req, resp)
if err != nil {
return "", err
}

if resp.Status == 1 {
return "", errors.New(resp.Msg)
}
return resp.QRCode, nil
}

func handleRequestWithResponse(url, hostname string, req, resp interface{}) error {
message, err := sendRequest(url, req, map[string]string{HostHeader: hostname})
if err != nil {
return err
}

err = json.Unmarshal(message, resp)
if err != nil {
return err
}
return nil
}

func handleRequest(url, hostname string, req interface{}) error {
Expand Down

0 comments on commit 7058d2b

Please sign in to comment.