服务人员查询
更新时间:2025.01.09用于查询已注册的服务人员ID等信息。
|
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/smartguide/guides
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Wechatpay-Serial 必填 string
【微信支付公钥ID】或【微信支付平台证书序列号】请求参数中的敏感字段,需要使用微信支付公钥加密(推荐),请参考获取微信支付公钥ID说明以及微信支付公钥加密敏感信息指引,也可以使用微信支付平台证书公钥加密,参考获取平台证书序列号、平台证书加密敏感信息指引
query 查询参数
sub_mchid 选填 string(64)
【子商户ID】导购所属商户的商户ID
store_id 必填 integer
【门店ID】门店在微信支付商户平台的唯一标识
userid 选填 string(64)
【企业微信的员工ID】员工在商户企业微信通讯录使用的唯一标识,企业微信商家可传入
mobile 选填 string
【手机号码】服务人员通过小程序注册时填写的手机号码,该字段需要使用微信支付公钥加密(推荐),请参考获取微信支付公钥ID说明以及微信支付公钥加密敏感信息指引,也可以使用微信支付平台证书公钥加密,参考获取平台证书序列号、平台证书加密敏感信息指引
work_id 选填 string
【工号】服务人员通过小程序注册时填写的工号,个人微信商家可传入
limit 选填 integer
【最大资源条数】该次请求可返回的最大资源条数,不大于10
offset 选填 integer
【请求资源起始位置】该次请求资源的起始位置,默认值为0
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/smartguide/guides?sub_mchid=1234567890&store_id=1234&userid=robert&mobile=str2WoWy8uUiWM7xahvNv0lV3C+nn3t4QlKNnyr+iwlk2FoMcn/lxrR6YdKKFI6NFJkC5oyvzNwc1MDzIgjLR0W6bJKiwWeOV3Fp0x+VIoRDONal1Mgb6VTYg7lvACEqdwmVkvbt4/oEWaWP62njMGGe0fMiBSAvao3LrcsOwDvN3E9kiaw5XQZMP/rUdWTFfy5THuohcQobGMrxclHKAnwAHU8CWfkziW5crUc3Z83uMVcFQu38y9EcWR12FJ3jip5nyVKiqCF4iDSN+JRXjWsWlqTZ0Y8Q+piBCS5ACusK6nz7mKQeypi9fKjAggRfvNFPf/bNxPvork4mMVgZkA==&work_id=robert&limit=5&offset=0 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: 5157F09EFDC096DE15EBE81A47057A7232F1B8E1" 6
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777 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 ListGuides { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/smartguide/guides"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ListGuides client = new ListGuides( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 ListGuidesRequest request = new ListGuidesRequest(); 41 request.subMchid = "1234567890"; 42 request.storeId = 1234L; 43 request.userid = "robert"; 44 request.mobile = "str2WoWy8uUiWM7xahvNv0lV3C+nn3t4QlKNnyr+iwlk2FoMcn/lxrR6YdKKFI6NFJkC5oyvzNwc1MDzIgjLR0W6bJKiwWeOV3Fp0x+VIoRDONal1Mgb6VTYg7lvACEqdwmVkvbt4/oEWaWP62njMGGe0fMiBSAvao3LrcsOwDvN3E9kiaw5XQZMP/rUdWTFfy5THuohcQobGMrxclHKAnwAHU8CWfkziW5crUc3Z83uMVcFQu38y9EcWR12FJ3jip5nyVKiqCF4iDSN+JRXjWsWlqTZ0Y8Q+piBCS5ACusK6nz7mKQeypi9fKjAggRfvNFPf/bNxPvork4mMVgZkA=="; 45 request.workId = "robert"; 46 request.limit = 5L; 47 request.offset = 0L; 48 try { 49 ListGuidesResponse response = client.run(request); 50 // TODO: 请求成功,继续业务逻辑 51 System.out.println(response); 52 } catch (WXPayUtility.ApiException e) { 53 // TODO: 请求失败,根据状态码执行不同的逻辑 54 e.printStackTrace(); 55 } 56 } 57 58 public ListGuidesResponse run(ListGuidesRequest request) { 59 String uri = PATH; 60 Map<String, Object> args = new HashMap<>(); 61 args.put("sub_mchid", request.subMchid); 62 args.put("store_id", request.storeId); 63 args.put("userid", request.userid); 64 args.put("mobile", request.mobile); 65 args.put("work_id", request.workId); 66 args.put("limit", request.limit); 67 args.put("offset", request.offset); 68 String queryString = WXPayUtility.urlEncode(args); 69 if (!queryString.isEmpty()) { 70 uri = uri + "?" + queryString; 71 } 72 73 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 74 reqBuilder.addHeader("Accept", "application/json"); 75 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 76 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 77 reqBuilder.method(METHOD, null); 78 Request httpRequest = reqBuilder.build(); 79 80 // 发送HTTP请求 81 OkHttpClient client = new OkHttpClient.Builder().build(); 82 try (Response httpResponse = client.newCall(httpRequest).execute()) { 83 String respBody = WXPayUtility.extractBody(httpResponse); 84 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 85 // 2XX 成功,验证应答签名 86 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 87 httpResponse.headers(), respBody); 88 89 // 从HTTP应答报文构建返回数据 90 return WXPayUtility.fromJson(respBody, ListGuidesResponse.class); 91 } else { 92 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 93 } 94 } catch (IOException e) { 95 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 96 } 97 } 98 99 private final String mchid; 100 private final String certificateSerialNo; 101 private final PrivateKey privateKey; 102 private final String wechatPayPublicKeyId; 103 private final PublicKey wechatPayPublicKey; 104 105 public ListGuides(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 106 this.mchid = mchid; 107 this.certificateSerialNo = certificateSerialNo; 108 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 109 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 110 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 111 } 112 113 public String encrypt(String plainText) { 114 return WXPayUtility.encrypt(this.wechatPayPublicKey, plainText); 115 } 116 117 public static class ListGuidesRequest { 118 @SerializedName("sub_mchid") 119 @Expose(serialize = false) 120 public String subMchid; 121 122 @SerializedName("store_id") 123 @Expose(serialize = false) 124 public Long storeId; 125 126 @SerializedName("userid") 127 @Expose(serialize = false) 128 public String userid; 129 130 @SerializedName("mobile") 131 @Expose(serialize = false) 132 public String mobile; 133 134 @SerializedName("work_id") 135 @Expose(serialize = false) 136 public String workId; 137 138 @SerializedName("limit") 139 @Expose(serialize = false) 140 public Long limit; 141 142 @SerializedName("offset") 143 @Expose(serialize = false) 144 public Long offset; 145 } 146 147 public static class ListGuidesResponse { 148 @SerializedName("data") 149 public List<Guide> data; 150 151 @SerializedName("total_count") 152 public Long totalCount; 153 154 @SerializedName("limit") 155 public Long limit; 156 157 @SerializedName("offset") 158 public Long offset; 159 } 160 161 public static class Guide { 162 @SerializedName("guide_id") 163 public String guideId; 164 165 @SerializedName("store_id") 166 public Long storeId; 167 168 @SerializedName("name") 169 public String name; 170 171 @SerializedName("mobile") 172 public String mobile; 173 174 @SerializedName("userid") 175 public String userid; 176 177 @SerializedName("work_id") 178 public String workId; 179 } 180 181} 182
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9) 10 11func main() { 12 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 13 config, err := wxpay_utility.CreateMchConfig( 14 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 16 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 17 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 18 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 19 ) 20 if err != nil { 21 fmt.Println(err) 22 return 23 } 24 25 request := &ListGuidesRequest{ 26 SubMchid: wxpay_utility.String("1234567890"), 27 StoreId: wxpay_utility.Int64(1234), 28 Userid: wxpay_utility.String("robert"), 29 Mobile: wxpay_utility.String("str2WoWy8uUiWM7xahvNv0lV3C+nn3t4QlKNnyr+iwlk2FoMcn/lxrR6YdKKFI6NFJkC5oyvzNwc1MDzIgjLR0W6bJKiwWeOV3Fp0x+VIoRDONal1Mgb6VTYg7lvACEqdwmVkvbt4/oEWaWP62njMGGe0fMiBSAvao3LrcsOwDvN3E9kiaw5XQZMP/rUdWTFfy5THuohcQobGMrxclHKAnwAHU8CWfkziW5crUc3Z83uMVcFQu38y9EcWR12FJ3jip5nyVKiqCF4iDSN+JRXjWsWlqTZ0Y8Q+piBCS5ACusK6nz7mKQeypi9fKjAggRfvNFPf/bNxPvork4mMVgZkA=="), 30 WorkId: wxpay_utility.String("robert"), 31 Limit: wxpay_utility.Int64(5), 32 Offset: wxpay_utility.Int64(0), 33 } 34 35 response, err := ListGuides(config, request) 36 if err != nil { 37 fmt.Printf("请求失败: %+v\n", err) 38 // TODO: 请求失败,根据状态码执行不同的处理 39 return 40 } 41 42 // TODO: 请求成功,继续业务逻辑 43 fmt.Printf("请求成功: %+v\n", response) 44} 45 46func ListGuides(config *wxpay_utility.MchConfig, request *ListGuidesRequest) (response *ListGuidesResponse, err error) { 47 const ( 48 host = "https://api.mch.weixin.qq.com" 49 method = "GET" 50 path = "/v3/smartguide/guides" 51 ) 52 53 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 54 if err != nil { 55 return nil, err 56 } 57 query := reqUrl.Query() 58 if request.SubMchid != nil { 59 query.Add("sub_mchid", *request.SubMchid) 60 } 61 if request.StoreId != nil { 62 query.Add("store_id", fmt.Sprintf("%v", *request.StoreId)) 63 } 64 if request.Userid != nil { 65 query.Add("userid", *request.Userid) 66 } 67 if request.Mobile != nil { 68 query.Add("mobile", *request.Mobile) 69 } 70 if request.WorkId != nil { 71 query.Add("work_id", *request.WorkId) 72 } 73 if request.Limit != nil { 74 query.Add("limit", fmt.Sprintf("%v", *request.Limit)) 75 } 76 if request.Offset != nil { 77 query.Add("offset", fmt.Sprintf("%v", *request.Offset)) 78 } 79 reqUrl.RawQuery = query.Encode() 80 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 81 if err != nil { 82 return nil, err 83 } 84 httpRequest.Header.Set("Accept", "application/json") 85 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 86 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 87 if err != nil { 88 return nil, err 89 } 90 httpRequest.Header.Set("Authorization", authorization) 91 92 client := &http.Client{} 93 httpResponse, err := client.Do(httpRequest) 94 if err != nil { 95 return nil, err 96 } 97 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 98 if err != nil { 99 return nil, err 100 } 101 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 102 // 2XX 成功,验证应答签名 103 err = wxpay_utility.ValidateResponse( 104 config.WechatPayPublicKeyId(), 105 config.WechatPayPublicKey(), 106 &httpResponse.Header, 107 respBody, 108 ) 109 if err != nil { 110 return nil, err 111 } 112 response := &ListGuidesResponse{} 113 if err := json.Unmarshal(respBody, response); err != nil { 114 return nil, err 115 } 116 117 return response, nil 118 } else { 119 return nil, wxpay_utility.NewApiException( 120 httpResponse.StatusCode, 121 httpResponse.Header, 122 respBody, 123 ) 124 } 125} 126 127type ListGuidesRequest struct { 128 SubMchid *string `json:"sub_mchid,omitempty"` 129 StoreId *int64 `json:"store_id,omitempty"` 130 Userid *string `json:"userid,omitempty"` 131 Mobile *string `json:"mobile,omitempty"` 132 WorkId *string `json:"work_id,omitempty"` 133 Limit *int64 `json:"limit,omitempty"` 134 Offset *int64 `json:"offset,omitempty"` 135} 136 137func (o *ListGuidesRequest) MarshalJSON() ([]byte, error) { 138 type Alias ListGuidesRequest 139 a := &struct { 140 SubMchid *string `json:"sub_mchid,omitempty"` 141 StoreId *int64 `json:"store_id,omitempty"` 142 Userid *string `json:"userid,omitempty"` 143 Mobile *string `json:"mobile,omitempty"` 144 WorkId *string `json:"work_id,omitempty"` 145 Limit *int64 `json:"limit,omitempty"` 146 Offset *int64 `json:"offset,omitempty"` 147 *Alias 148 }{ 149 // 序列化时移除非 Body 字段 150 SubMchid: nil, 151 StoreId: nil, 152 Userid: nil, 153 Mobile: nil, 154 WorkId: nil, 155 Limit: nil, 156 Offset: nil, 157 Alias: (*Alias)(o), 158 } 159 return json.Marshal(a) 160} 161 162type ListGuidesResponse struct { 163 Data []Guide `json:"data,omitempty"` 164 TotalCount *int64 `json:"total_count,omitempty"` 165 Limit *int64 `json:"limit,omitempty"` 166 Offset *int64 `json:"offset,omitempty"` 167} 168 169type Guide struct { 170 GuideId *string `json:"guide_id,omitempty"` 171 StoreId *int64 `json:"store_id,omitempty"` 172 Name *string `json:"name,omitempty"` 173 Mobile *string `json:"mobile,omitempty"` 174 Userid *string `json:"userid,omitempty"` 175 WorkId *string `json:"work_id,omitempty"` 176} 177
应答参数
|
data 选填 array[object]
【服务人员列表】
属性 | |
guide_id 选填 string 【服务人员ID】导购在导购系统中的唯一标识 store_id 选填 integer 【门店ID】门店在微信支付商户平台的唯一标识 name 选填 string 【服务人员姓名】员工在商户企业微信通讯录上的姓名,该字段需进行解密处理,解密方法详见如何使用API证书解密敏感字段。 mobile 选填 string 【手机号码】服务人员通过小程序注册时填写的手机号码,使用微信商家不返回,该字段需进行解密处理,解密方法详见如何使用API证书解密敏感字段。 userid 选填 string 【企业微信的员工ID】员工在商户企业微信通讯录使用的唯一标识,使用微信商家不返回 work_id 选填 string 【工号】服务人员通过小程序注册时填写的工号,使用微信商家不返回 |
total_count 选填 integer
【服务人员数量】符合条件筛选的服务人员数量
limit 选填 integer
【最大资源条数】该次请求可返回的最大资源条数,不大于10
offset 选填 integer
【请求资源起始位置】该次请求资源的起始位置,默认值为0
应答示例
200 OK
1{ 2 "data" : [ 3 { 4 "guide_id" : "LLA3WJ6DSZUfiaZDS79FH5Wm5m4X69TBic", 5 "store_id" : 1234, 6 "name" : "str2WoWy8uUiWM7xahvNv0lV3C+nn3t4QlKNnyr+iwlk2FoMcn/lxrR6YdKKFI6NFJkC5oyvzNwc1MDzIgjLR0W6bJKiwWeOV3Fp0x+VIoRDONal1Mgb6VTYg7lvACEqdwmVkvbt4/oEWaWP62njMGGe0fMiBSAvao3LrcsOwDvN3E9kiaw5XQZMP/rUdWTFfy5THuohcQobGMrxclHKAnwAHU8CWfkziW5crUc3Z83uMVcFQu38y9EcWR12FJ3jip5nyVKiqCF4iDSN+JRXjWsWlqTZ0Y8Q+piBCS5ACusK6nz7mKQeypi9fKjAggRfvNFPf/bNxPvork4mMVgZkA==", 7 "mobile" : "str2WoWy8uUiWM7xahvNv0lV3C+nn3t4QlKNnyr+iwlk2FoMcn/lxrR6YdKKFI6NFJkC5oyvzNwc1MDzIgjLR0W6bJKiwWeOV3Fp0x+VIoRDONal1Mgb6VTYg7lvACEqdwmVkvbt4/oEWaWP62njMGGe0fMiBSAvao3LrcsOwDvN3E9kiaw5XQZMP/rUdWTFfy5THuohcQobGMrxclHKAnwAHU8CWfkziW5crUc3Z83uMVcFQu38y9EcWR12FJ3jip5nyVKiqCF4iDSN+JRXjWsWlqTZ0Y8Q+piBCS5ACusK6nz7mKQeypi9fKjAggRfvNFPf/bNxPvork4mMVgZkA==", 8 "userid" : "robert", 9 "work_id" : "robert" 10 } 11 ], 12 "total_count" : 10, 13 "limit" : 5, 14 "offset" : 0 15} 16
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 子商户未授权 | 子商户未授权,请联系子商户授权 |
400 | INVALID_REQUEST | 子商户产品权限未开通 | 子商户产品权限未开通,请联系子商户开通 |
400 | INVALID_REQUEST | 子商户产品配置未完成 | 子商户产品配置未完成,请确认子商户完成产品配置后重试 |
400 | MCH_NOT_EXISTS | 子商户不存在 | 请确认商户号是否有误 |
400 | MCH_NOT_EXISTS | 商户号格式错误 | 请确认商户号是否有误 |
400 | MCH_NOT_EXISTS | 子商户号格式错误 | 请确认商户号是否有误 |
400 | MCH_NOT_EXISTS | 子商户号为空 | 请填写子商户号 |
400 | PARAM_ERROR | 必填参数为空 | 根据错误提示,传入正确参数 |
400 | PARAM_ERROR | 门店ID格式错误 | 根据错误提示,传入正确参数 |
400 | PARAM_ERROR | userid格式错误 | 根据错误提示,传入正确参数 |
400 | PARAM_ERROR | 手机号码格式错误 | 根据错误提示,传入正确参数 |
400 | PARAM_ERROR | 门店ID为空 | 请填写门店ID |
400 | PARAM_ERROR | 个人微信商家不应填写企业微信ID | 根据错误提示,传入正确参数 |
400 | PARAM_ERROR | 企业微信商家不应填写工号 | 根据错误提示,传入正确参数 |
400 | PARAM_ERROR | 最大资源条数大于10 | 根据错误提示,传入正确参数 |
500 | SYSTEM_ERROR | 系统错误 | 请使用相同参数稍后重新调用 |
500 | SYSTEM_ERROR | 扩展父子商户票据错误 | 请使用相同参数稍后重新调用 |
500 | SYSTEM_ERROR | 调用云函数错误 | 请使用相同参数稍后重新调用 |