1. 接口规则
为了在保证支付安全的前提下,带给商户简单、一致且易用的开发体验,我们推出了全新的微信支付APIv3接口。该版本API的具体规则请参考APIv3接口规则。
2. 开发准备
2.1. 搭建和配置开发环境
开发者应当依据自身的编程语言来构建并配置相应的开发环境。
2.2. 业务开发配置
1. 登录【微信支付服务商平台】后,通过路径【产品中心—>我的产品—>支付即服务—>产品设置】,即可开通支付即服务,开通后完成产品设置。
2. 【产品设置】页面如下图所示,具体内容包括上传商家logo、选择服务人员名称及选择名片功能模块。
3. 快速接入
3.1. 业务流程图
步骤6: 使用企业微信的商户,通过《服务人员注册API》接口传入服务人员信息进行注册,微信支付返回服务人员ID给到商户,商户需将服务人员注册信息和对应的服务人员ID进行妥善保存。
步骤11: 商户在下单时生成商户订单号,接着调用《服务人员分配API》传入“商户订单号+服务人员ID”,随后按照原有流程和支付接口完成支付即可。
3.2. API接入(含示例代码)
文档展示了如何使用微信支付服务端 SDK 快速接入商家券产品,完成与微信支付对接的部分。
3.2.1. 【服务端】服务人员注册
步骤说明: 商户开发者使用「服务人员注册接口」为商户注册服务人员。
| 注意 调用接口前商家需完成支付即服务产品的开通和设置。若普通服务商为特约商户调用接口,需在特约商户开通并完成产品设置后,与特约商户建立产品授权关系。 |
|
1public void RegSmartGuide() throws Exception{
2
3 HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/smartguide/guides");
4
5 String reqdata = "{"
6 + "\"store_id\":1234,"
7 + "\"corpid\":\"1234567890\","
8 + "\"name\":\"pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==\","
9 + "\"mobile\":\"pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==\","
10 + "\"qr_code\":\"https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx\","
11 + "\"avatar\":\"https://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0\","
12 + "\"group_qrcode\":\"https://p.qpic.cn/wwhead/nMl9ssowtibVGyrmvBiaibzDtp/0\","
13 + "\"userid\":\"robert\""
14 + "}";
15 StringEntity entity = new StringEntity(reqdata,"utf-8");
16 entity.setContentType("application/json");
17 httpPost.setEntity(entity);
18 httpPost.setHeader("Accept", "application/json");
19
20
21 CloseableHttpResponse response = httpClient.execute(httpPost);
22
23 try {
24 int statusCode = response.getStatusLine().getStatusCode();
25 if (statusCode == 200) {
26 System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
27 } else if (statusCode == 204) {
28 System.out.println("success");
29 } else {
30 System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
31 throw new IOException("request failed");
32 }
33 } finally {
34 response.close();
35 }
36}
1try {
2 $resp = $client->request(
3 'POST',
4 'https://api.mch.weixin.qq.com/v3/smartguide/guides',
5 [
6
7 'json' => [
8 "store_id" => 1234,
9 "corpid" => "1234567890",
10 "name" => "pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==",
11 "mobile" => "pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==",
12 "qr_code" => "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx",
13 "avatar" => "https://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
14 "group_qrcode" => "https://p.qpic.cn/wwhead/nMl9ssowtibVGyrmvBiaibzDtp/0",
15 "userid" => "robert",
16 ],
17 'headers' => [ 'Accept' => 'application/json' ]
18 ]
19 );
20 $statusCode = $resp->getStatusCode();
21 if ($statusCode == 200) {
22 echo "success,return body = " . $resp->getBody()->getContents()."\n";
23 } else if ($statusCode == 204) {
24 echo "success";
25 }
26} catch (RequestException $e) {
27
28 echo $e->getMessage()."\n";
29 if ($e->hasResponse()) {
30 echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
31 }
32 return;
33}
34
3.2.2. 【服务端】服务人员分配
步骤说明: 服务人员分配接口用于商户开发者在顾客下单后为顾客分配服务人员使用。
| 注意 调用服务人员分配接口需在完成支付之前,若分配服务人员晚于支付完成,则将无法在支付凭证上出现服务人员名片入口。 |
|
JAVA
1public void AssignGuide() throws Exception{
2
3 HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/smartguide/guides/LLA3WJ6DSZUfiaZDS79FH5Wm5m4X69TBic/assign");
4
5 String reqdata = "{"
6 + "\"out_trade_no\":\"20150806125346\""
7 + "}";
8 StringEntity entity = new StringEntity(reqdata,"utf-8");
9 entity.setContentType("application/json");
10 httpPost.setEntity(entity);
11 httpPost.setHeader("Accept", "application/json");
12
13
14 CloseableHttpResponse response = httpClient.execute(httpPost);
15
16 try {
17 int statusCode = response.getStatusLine().getStatusCode();
18 if (statusCode == 200) {
19 System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
20 } else if (statusCode == 204) {
21 System.out.println("success");
22 } else {
23 System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
24 throw new IOException("request failed");
25 }
26 } finally {
27 response.close();
28 }
29}
30
1try {
2 $resp = $client->request(
3 'POST',
4 'https://api.mch.weixin.qq.com/v3/smartguide/guides/LLA3WJ6DSZUfiaZDS79FH5Wm5m4X69TBic/assign',
5 [
6
7 'json' => [
8 "out_trade_no" => "20150806125346",
9 ],
10 'headers' => [ 'Accept' => 'application/json' ]
11 ]
12 );
13 $statusCode = $resp->getStatusCode();
14 if ($statusCode == 200) {
15 echo "success,return body = " . $resp->getBody()->getContents()."\n";
16 } else if ($statusCode == 204) {
17 echo "success";
18 }
19} catch (RequestException $e) {
20
21 echo $e->getMessage()."\n";
22 if ($e->hasResponse()) {
23 echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
24 }
25 return;
26}
3.2.3. 【服务端】服务人员查询
步骤说明: 服务人员查询接口用于商户开发者查询已注册的服务人员ID等信息。
| 服务人员注册API和查询API请求URL相同,区别主要是在body和query,请注意区分。 |
|
JAVA
1public void QueryGuide() throws Exception{
2
3 HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/smartguide/guides?store_id=1234");
4 httpGet.setHeader("Accept", "application/json");
5
6
7 CloseableHttpResponse response = httpClient.execute(httpGet);
8
9 try {
10 int statusCode = response.getStatusLine().getStatusCode();
11 if (statusCode == 200) {
12 System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
13 } else if (statusCode == 204) {
14 System.out.println("success");
15 } else {
16 System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
17 throw new IOException("request failed");
18 }
19 } finally {
20 response.close();
21 }
22}
1try {
2 $resp = $client->request(
3 'GET',
4 'https://api.mch.weixin.qq.com/v3/smartguide/guides?store_id=1234',
5 [
6 'headers' => [ 'Accept' => 'application/json']
7 ]
8 );
9 $statusCode = $resp->getStatusCode();
10 if ($statusCode == 200) {
11 echo "success,return body = " . $resp->getBody()->getContents()."\n";
12 } else if ($statusCode == 204) {
13 echo "success";
14 }
15} catch (RequestException $e) {
16
17 echo $e->getMessage()."\n";
18 if ($e->hasResponse()) {
19 echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
20 }
21 return;
22}
3.2.4. 【服务端】服务人员信息更新
步骤说明: 服务人员信息更新接口用于商户开发者为商户更新门店服务人员的姓名、头像等信息。
| 注意 个人微信商家、企业微信商家均支持服务人员信息更新。 |
|
JAVA
1public void UpdateGuide() throws Exception{
2
3 HttpPatch httpPatch = new HttpPatch("https://api.mch.weixin.qq.com/v3/smartguide/guides/LLA3WJ6DSZUfiaZDS79FH5Wm5m4X69TBic");
4
5 String reqdata = "{"
6 + "\"name\":\"pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==\","
7 + "\"mobile\":\"pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==\","
8 + "\"qr_code\":\"https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx\","
9 + "\"avatar\":\"https://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0\","
10 + "\"group_qrcode\":\"https://p.qpic.cn/wwhead/nMl9ssowtibVGyrmvBiaibzDtp/0\""
11 + "}";
12 StringEntity entity = new StringEntity(reqdata,"utf-8");
13 entity.setContentType("application/json");
14 httpPatch.setEntity(entity);
15 httpPatch.setHeader("Accept", "application/json");
16
17
18 CloseableHttpResponse response = httpClient.execute(httpPatch);
19
20 try {
21 int statusCode = response.getStatusLine().getStatusCode();
22 if (statusCode == 200) {
23 System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
24 } else if (statusCode == 204) {
25 System.out.println("success");
26 } else {
27 System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
28 throw new IOException("request failed");
29 }
30 } finally {
31 response.close();
32 }
33}
1try {
2 $resp = $client->request(
3 'PATCH',
4 'https://api.mch.weixin.qq.com/v3/smartguide/guides/LLA3WJ6DSZUfiaZDS79FH5Wm5m4X69TBic',
5 [
6
7 'json' => [
8 "name" => "pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==",
9 "mobile" => "pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==",
10 "qr_code" => "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx",
11 "avatar" => "https://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
12 "group_qrcode" => "https://p.qpic.cn/wwhead/nMl9ssowtibVGyrmvBiaibzDtp/0",
13 ],
14 'headers' => [ 'Accept' => 'application/json' ]
15 ]
16 );
17 $statusCode = $resp->getStatusCode();
18 if ($statusCode == 200) {
19 echo "success,return body = " . $resp->getBody()->getContents()."\n";
20 } else if ($statusCode == 204) {
21 echo "success";
22 }
23} catch (RequestException $e) {
24
25 echo $e->getMessage()."\n";
26 if ($e->hasResponse()) {
27 echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
28 }
29 return;
30}
4. 常见问题
Q:企业微信的corpid如何获取?
A:获取corpid可进入企业微信的管理后台,查找路径:【我的企业->企业信息→查看“企业ID”】(需要有管理员权限)。
Q:注册服务人员时必须传入门店ID吗?在哪里找这个门店ID
A:是的,注册时必须传入门店ID。该门店ID是微信支付门店系统的编码,查找路径:【登录商户平台->营销中心→门店管理】,门店管理页面下的门店编号即为需要填写的门店ID(该门店信息与企业微信的门店系统无关)。
若未创建门店,则需创建门店并通过腾讯地图审核后,方可使用门店ID进行注册。
Q:调用服务人员分配接口是在支付前还是支付后?
A:支付前。建议当商家生成当前交易的“商户订单号”时,通过“服务人员分配API”将“服务人员ID+商户订单号”传给微信支付,并按照原有流程引导用户完成支付即可。若分配服务人员晚于支付完成,则将无法在支付凭证上出现服务人员名片入口。
Q:服务人员分配应该采取什么样的分配机制?
A:使用服务人员分配API进行分配时,服务人员的分配机制由商家内部闭环,可以灵活掌控。在支付前调用分配接口时,商家可自行决定分配哪名服务人员,商家可选择随机分配、按时间段分配,或为某笔订单指定特定服务人员的分配方式(例如在线下门店支付时,可分配当前为该顾客提供服务的服务人员)。使用免开发版本时,商户号下的所有订单将随机分配给不同服务人员,商家可通过小程序调整服务人员分配的时间段,但是不能针对不同订单分配特定的服务人员。
Q:为什么打开了免开发版本的自动分配按钮,支付凭证下还是没有出现服务人员的名片入口?
A:打开自动分配按钮时,还需为服务人员设置分配规则,只有设置了规则的服务人员才会被分配到指定时间段的订单中。若未给服务人员设置分配规则,则该服务人员不会实现自动分配。