本文档主要涉及开发指引中对主动查询用户车辆服务状态,确认该车牌是否被该用户开通车主服务的处理流程。
查询用户车辆服务状态时,商户后台系统需要提供appid、车牌号、车牌颜色和用户openid,然后调用查询车牌服务开通信息API查询用户车辆的服务状态。
appID := os.Getenv("WXPAY_MERCHANT_APP_ID")
query := r.URL.Query()
plateNumber := query.Get("plate_number")
plateColor := query.Get("plate_color")
openID := query.Get("openid")
if plateNumber == "" || plateColor == "" || openID == "" {
err := errors.Errorf("<plate_number>, <plate_color>, <openid> are required for querying service status")
log.Print(err.Error())
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
apiResult, err := client.GetClient().Get(
r.Context(),
fmt.Sprintf(
"https://api.mch.weixin.qq.com/v3/vehicle/parking/services/find?appid=%s&plate_number=%s&plate_color=%s&openid=%s",
appID,
plateNumber,
plateColor,
openID,
),
)
if err != nil {
err = errors.Errorf("Fail to query service status: %v", err)
log.Print(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
respBody, err := ioutil.ReadAll(apiResult.Response.Body)
if err != nil {
err = errors.Errorf("Fail to read from response body: %v", err)
log.Print(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
log.Printf("Resp: %s", respBody)