查询车牌服务开通信息
更新时间:2025.02.21该接口仅支持停车场景,商户首先请求查询车牌服务开通信息接口,确认该车牌,是否被该用户开通车主服务,以及车牌具体服务开通状态,包括正常服务,和暂停服务,以及未开通三个状态。
接口说明
支持商户:【普通商户】
请求方式:【GET】/v3/vehicle/parking/services/find
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
query 查询参数
appid 必填 string(32)
【公众账号ID】AppID是商户在微信申请公众号或移动应用成功后分配的账号ID,登录平台为mp.weixin.qq.com或open.weixin.qq.com
plate_number 必填 string(32)
【车牌号】车牌号,仅包括省份+车牌,不包括特殊字符。
openid 必填 string(32)
【用户标识】用户在商户对应AppID下的唯一标识
plate_color 必填 string
【车牌颜色】车牌颜色
可选取值:
BLUE
: 蓝色
GREEN
: 绿色
YELLOW
: 黄色
BLACK
: 黑色
WHITE
: 白色
LIMEGREEN
: 黄绿色
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/vehicle/parking/services/find?appid=wxcbda96de0b165486&plate_number=粤B888888&plate_color=BLUE&openid=oUpF8uMuAJOM2pxb1Q \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/merchant/4014931831 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 查询车牌服务开通信息 24 */ 25public class QueryPlateService { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/vehicle/parking/services/find"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 QueryPlateService client = new QueryPlateService( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 QueryPlateServiceRequest request = new QueryPlateServiceRequest(); 41 request.appid = "wxcbda96de0b165486"; 42 request.plateNumber = "粤B888888"; 43 request.plateColor = PlateColor.BLUE; 44 request.openid = "oUpF8uMuAJOM2pxb1Q"; 45 try { 46 PlateService response = client.run(request); 47 // TODO: 请求成功,继续业务逻辑 48 System.out.println(response); 49 } catch (WXPayUtility.ApiException e) { 50 // TODO: 请求失败,根据状态码执行不同的逻辑 51 e.printStackTrace(); 52 } 53 } 54 55 public PlateService run(QueryPlateServiceRequest request) { 56 String uri = PATH; 57 Map<String, Object> args = new HashMap<>(); 58 args.put("appid", request.appid); 59 args.put("plate_number", request.plateNumber); 60 args.put("plate_color", request.plateColor); 61 args.put("openid", request.openid); 62 String queryString = WXPayUtility.urlEncode(args); 63 if (!queryString.isEmpty()) { 64 uri = uri + "?" + queryString; 65 } 66 67 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 68 reqBuilder.addHeader("Accept", "application/json"); 69 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 70 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 71 reqBuilder.method(METHOD, null); 72 Request httpRequest = reqBuilder.build(); 73 74 // 发送HTTP请求 75 OkHttpClient client = new OkHttpClient.Builder().build(); 76 try (Response httpResponse = client.newCall(httpRequest).execute()) { 77 String respBody = WXPayUtility.extractBody(httpResponse); 78 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 79 // 2XX 成功,验证应答签名 80 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 81 httpResponse.headers(), respBody); 82 83 // 从HTTP应答报文构建返回数据 84 return WXPayUtility.fromJson(respBody, PlateService.class); 85 } else { 86 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 87 } 88 } catch (IOException e) { 89 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 90 } 91 } 92 93 private final String mchid; 94 private final String certificateSerialNo; 95 private final PrivateKey privateKey; 96 private final String wechatPayPublicKeyId; 97 private final PublicKey wechatPayPublicKey; 98 99 public QueryPlateService(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 100 this.mchid = mchid; 101 this.certificateSerialNo = certificateSerialNo; 102 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 103 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 104 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 105 } 106 107 public static class QueryPlateServiceRequest { 108 @SerializedName("appid") 109 @Expose(serialize = false) 110 public String appid; 111 112 @SerializedName("plate_number") 113 @Expose(serialize = false) 114 public String plateNumber; 115 116 @SerializedName("openid") 117 @Expose(serialize = false) 118 public String openid; 119 120 @SerializedName("plate_color") 121 @Expose(serialize = false) 122 public PlateColor plateColor; 123 } 124 125 public static class PlateService { 126 @SerializedName("plate_number") 127 public String plateNumber; 128 129 @SerializedName("plate_color") 130 public PlateColor plateColor; 131 132 @SerializedName("service_open_time") 133 public String serviceOpenTime; 134 135 @SerializedName("openid") 136 public String openid; 137 138 @SerializedName("service_state") 139 public String serviceState; 140 } 141 142 public enum PlateColor { 143 @SerializedName("BLUE") 144 BLUE, 145 @SerializedName("GREEN") 146 GREEN, 147 @SerializedName("YELLOW") 148 YELLOW, 149 @SerializedName("BLACK") 150 BLACK, 151 @SerializedName("WHITE") 152 WHITE, 153 @SerializedName("LIMEGREEN") 154 LIMEGREEN 155 } 156 157} 158
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/merchant/4015119334 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9 "time" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &QueryPlateServiceRequest{ 27 Appid: wxpay_utility.String("wxcbda96de0b165486"), 28 PlateNumber: wxpay_utility.String("粤B888888"), 29 PlateColor: PLATECOLOR_BLUE.Ptr(), 30 Openid: wxpay_utility.String("oUpF8uMuAJOM2pxb1Q"), 31 } 32 33 response, err := QueryPlateService(config, request) 34 if err != nil { 35 fmt.Printf("请求失败: %+v\n", err) 36 // TODO: 请求失败,根据状态码执行不同的处理 37 return 38 } 39 40 // TODO: 请求成功,继续业务逻辑 41 fmt.Printf("请求成功: %+v\n", response) 42} 43 44func QueryPlateService(config *wxpay_utility.MchConfig, request *QueryPlateServiceRequest) (response *PlateService, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "GET" 48 path = "/v3/vehicle/parking/services/find" 49 ) 50 51 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 52 if err != nil { 53 return nil, err 54 } 55 query := reqUrl.Query() 56 if request.Appid != nil { 57 query.Add("appid", *request.Appid) 58 } 59 if request.PlateNumber != nil { 60 query.Add("plate_number", *request.PlateNumber) 61 } 62 if request.PlateColor != nil { 63 query.Add("plate_color", fmt.Sprintf("%v", *request.PlateColor)) 64 } 65 if request.Openid != nil { 66 query.Add("openid", *request.Openid) 67 } 68 reqUrl.RawQuery = query.Encode() 69 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 70 if err != nil { 71 return nil, err 72 } 73 httpRequest.Header.Set("Accept", "application/json") 74 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 75 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 76 if err != nil { 77 return nil, err 78 } 79 httpRequest.Header.Set("Authorization", authorization) 80 81 client := &http.Client{} 82 httpResponse, err := client.Do(httpRequest) 83 if err != nil { 84 return nil, err 85 } 86 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 87 if err != nil { 88 return nil, err 89 } 90 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 91 // 2XX 成功,验证应答签名 92 err = wxpay_utility.ValidateResponse( 93 config.WechatPayPublicKeyId(), 94 config.WechatPayPublicKey(), 95 &httpResponse.Header, 96 respBody, 97 ) 98 if err != nil { 99 return nil, err 100 } 101 response := &PlateService{} 102 if err := json.Unmarshal(respBody, response); err != nil { 103 return nil, err 104 } 105 106 return response, nil 107 } else { 108 return nil, wxpay_utility.NewApiException( 109 httpResponse.StatusCode, 110 httpResponse.Header, 111 respBody, 112 ) 113 } 114} 115 116type QueryPlateServiceRequest struct { 117 Appid *string `json:"appid,omitempty"` 118 PlateNumber *string `json:"plate_number,omitempty"` 119 Openid *string `json:"openid,omitempty"` 120 PlateColor *PlateColor `json:"plate_color,omitempty"` 121} 122 123func (o *QueryPlateServiceRequest) MarshalJSON() ([]byte, error) { 124 type Alias QueryPlateServiceRequest 125 a := &struct { 126 Appid *string `json:"appid,omitempty"` 127 PlateNumber *string `json:"plate_number,omitempty"` 128 Openid *string `json:"openid,omitempty"` 129 PlateColor *PlateColor `json:"plate_color,omitempty"` 130 *Alias 131 }{ 132 // 序列化时移除非 Body 字段 133 Appid: nil, 134 PlateNumber: nil, 135 Openid: nil, 136 PlateColor: nil, 137 Alias: (*Alias)(o), 138 } 139 return json.Marshal(a) 140} 141 142type PlateService struct { 143 PlateNumber *string `json:"plate_number,omitempty"` 144 PlateColor *PlateColor `json:"plate_color,omitempty"` 145 ServiceOpenTime *time.Time `json:"service_open_time,omitempty"` 146 Openid *string `json:"openid,omitempty"` 147 ServiceState *string `json:"service_state,omitempty"` 148} 149 150type PlateColor string 151 152func (e PlateColor) Ptr() *PlateColor { 153 return &e 154} 155 156const ( 157 PLATECOLOR_BLUE PlateColor = "BLUE" 158 PLATECOLOR_GREEN PlateColor = "GREEN" 159 PLATECOLOR_YELLOW PlateColor = "YELLOW" 160 PLATECOLOR_BLACK PlateColor = "BLACK" 161 PLATECOLOR_WHITE PlateColor = "WHITE" 162 PLATECOLOR_LIMEGREEN PlateColor = "LIMEGREEN" 163) 164
应答参数
|
plate_number 必填 string(32)
【车牌号】车牌号,仅包括省份+车牌,不包括特殊字符。
plate_color 必填 string
【车牌颜色】车牌颜色
可选取值:
BLUE
: 蓝色
GREEN
: 绿色
YELLOW
: 黄色
BLACK
: 黑色
WHITE
: 白色
LIMEGREEN
: 黄绿色
service_open_time 选填 string(32)
【车牌服务开通时间】车牌服务开通时间,遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
openid 必填 string(32)
【用户标识】用户在商户对应AppID下的唯一标识,此处返回商户请求中的OpenID
service_state 必填 string(32)
【车牌服务开通状态】车牌服务开通状态,
NORMAL 正常服务
PAUSE 暂停服务
OUT_SERVICE 未开通
商户根据状态带用户跳转至对应的微信支付分停车服务小程序页面。 其中NORMAL 和 PAUSE状态,可跳转至车牌管理页,进行车牌服务状态管理。OUT_SERVICE状态,可跳转至服务开通页面。
应答示例
200 OK
1{ 2 "plate_number" : "粤B888888", 3 "plate_color" : "BLUE", 4 "service_open_time" : "2017-08-26T10:43:39+08:00", 5 "openid" : "oUpF8uMuAJOM2pxb1Q", 6 "service_state" : "PAUSE" 7} 8
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 用户信息有误,请检查OpenID | 使用正确的微信OpenID重试 |
403 | NO_AUTH | 商户未入驻 | 当前扣款商户无权限扣款,请确认当前扣款商户已开通微信支付分停车产品权限。修复商户权限后可原参数重试 |
429 | RATELIMIT_EXCEEDED | 达到调用速率限制 | 接口调用频率过快,请降低请求频率 |
500 | SYSTEM_ERROR | 出现内部服务器错误 | 5开头的错误码均为系统错误,请使用相同的参数稍后重试 |