创建支付分订单
更新时间:2025.03.06当用户申请使用服务时,商户可通过此接口申请创建微信支付分订单,创单成功后,订单状态state为CREATED已创建。
注:该接口支持原参重入,相同参数重复调用可以返回成功。
接口说明
支持商户:【普通商户】
请求方式:【POST】/v3/payscore/serviceorder
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Content-Type 必填 string
请设置为application/json
body 包体参数
out_order_no 必填 string(32)
【商户服务订单号】商户系统内部服务订单号,要求32个字符内,只能是数字、大小写字母_-| 且在同一个商户号下唯一。需要开发者特别注意,该参数不可用于申请退款接口中的 out_trade_no 参数。
appid 必填 string(32)
【公众账号ID】是微信开放平台和微信公众平台为开发者的应用程序(APP、小程序、公众号)提供的一个唯一标识。 开发者需要先在微信开放平台或微信公众平台中申请ID,然后在商户平台中绑定,详见直连商户与AppID账号关联管理。完结订单和取消订单需要和创单传入的appid保持一致。
service_id 必填 string(32)
【服务ID】商户支付分服务的唯一标识,由32位数字组成。支付分产品权限审核通过后,微信支付运营会向商户提供该ID。
service_introduction 必填 string(20)
【服务信息】用于介绍本订单所提供的服务 ,长度不能超过20个字符(汉字、数字、字母、特殊符号都按照1个字符计算)。
post_payments 选填 array[Payment]
【后付费项目】用于展示订单后付费项目明细,最多100条,商户需要按照所属行业规程传参,详见post_payments(后付费项目)字段传参说明
属性 | |
name 必填 string(20) 【付费名称】不能超过20个字符,需严格按照post_payments(后付费项目)字段传参说明传参。 amount 选填 integer 【付费金额】付费项目金额,整型,大于等于0(等于0时表示不需要扣费),单位为分。需严格按照post_payments(后付费项目)字段传参说明传参。 description 选填 string(30) 【付费说明】对付费项目的详细说明,不超过30个字符,需严格按照post_payments(后付费项目)字段传参说明传参。 count 选填 integer 【付费数量】后付费项目的数量,为整型,数量范围为[1,100]。相同的后付费项目建议合并计算amount和count |
post_discounts 选填 array[ServiceOrderCoupon]
【商户优惠】用于展示订单优惠项目明细,最多30条,完结订单时传的收款总金额需满足计算条件(收款总金额=后付费项目amount和-优惠项目amount和)
属性 | |
name 必填 string(20) 【优惠名称】用于描述优惠项目,不超过20个字符,同一单多个优惠项目名称不可重复。 description 必填 string(30) 【优惠说明】用于描述优惠项目使用条件,不超过30个字符。 count 选填 integer 【优惠数量】整型,数量范围为[1,100],用于描述优惠项目使用数量,例如用户使用了两张同一活动优惠券,则count填2。 |
time_range 必填 object
【服务时间段】用于描述订单的服务开始和结束时间。
属性 | |
start_time 必填 string(14) 【服务开始时间】 end_time 选填 string(14) 【服务结束时间】 start_time_remark 选填 string(20) 【服务开始时间备注】当有传入服务开始时间时,可添加备注说明,不超过20个字符。 end_time_remark 选填 string(20) 【服务结束时间备注】当有传入服务结束时间时,可添加备注说明,不超过20个字符。 |
location 选填 object
【服务位置】用于描述用户使用服务的地理位置
属性 | |
start_location 选填 string(20) 【服务开始地点】用户开始使用服务的地点,不超过20个字符。 end_location 选填 string(20) 【服务结束地点】用户结束使用服务的地点,不超过20个字符。 |
risk_fund 必填 object
【服务风险金】本笔订单的风险金额描述
属性 | |
name 必填 string(30) 【风险名称】 amount 必填 integer 【风险金额】这笔订单的风险金额,风险金额大小会影响评估,理论上金额越高评估通过率越低,商户按照实际场景传入即可,评估不通过是正常风控拦截。 description 选填 string(30) 【风险说明】用于描述说明该风险金,不能超过30字符。 |
attach 选填 string(256)
【商户数据包】商户在创建订单时传入的自定义数据包,用户不可见。用于存放订单的商户自定义数据,需要先进行urlencode编码,总长度不超过256字符。确认订单回调和支付成功回调时会回传该字段给商户。
notify_url 必填 string(255)
【商户回调地址】商户接收确认订单回调通知和支付成功回调通知的地址,创单时传入,需按照notify-url填写注意事项规范填写。
need_user_confirm 选填 boolean
【是否需要用户确认】固定传true或者不传(不传默认是true)。
device 选填 object
【设备信息】
属性 | |
start_device_id 选填 string(50) 【服务开始的设备ID】 某一设备在商户对应服务ID下的唯一标识,由商户自行填写,建议采用设备SN值。售货机、充电宝、充电桩等无人自助设备行业必传。 end_device_id 选填 string(50) 【服务结束的设备ID】 某一设备在商户对应服务ID下的唯一标识,由商户自行填写,建议采用设备SN值。售货机、充电宝、充电桩等无人自助设备行业必传。 materiel_no 选填 string(100) 【物料编码】 若商家参与政策,则商家填写行业侧给到商家的物料码(字母+数字的形式);若商家未参与政策,则商家填写URL链接。 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/payscore/serviceorder \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "out_order_no" : "1234323JKHDFE1243252", 8 "appid" : "wxd678efh567hg6787", 9 "service_id" : "2002000000000558128851361561536", 10 "service_introduction" : "某某酒店", 11 "post_payments" : [ 12 { 13 "name" : "就餐费用", 14 "amount" : 40000, 15 "description" : "就餐人均100元", 16 "count" : 4 17 } 18 ], 19 "post_discounts" : [ 20 { 21 "name" : "满20减1元", 22 "description" : "不与其他优惠叠加", 23 "amount" : 100 24 } 25 ], 26 "time_range" : { 27 "start_time" : "20091225091010", 28 "end_time" : "20091225121010", 29 "start_time_remark" : "备注1", 30 "end_time_remark" : "备注2" 31 }, 32 "location" : { 33 "start_location" : "嗨客时尚主题展餐厅", 34 "end_location" : "嗨客时尚主题展餐厅" 35 }, 36 "risk_fund" : { 37 "name" : "DEPOSIT", 38 "amount" : 10000, 39 "description" : "就餐的预估费用" 40 }, 41 "attach" : "Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald", 42 "notify_url" : "https://api.test.com", 43 "need_user_confirm" : false, 44 "device" : { 45 "start_device_id" : "HG123456", 46 "end_device_id" : "HG123456", 47 "materiel_no" : "example_materiel_no" 48 } 49 }' 50
需配合微信支付工具库 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 CreateServiceOrder { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/payscore/serviceorder"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 CreateServiceOrder client = new CreateServiceOrder( 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 CreateServiceOrderRequest request = new CreateServiceOrderRequest(); 41 request.outOrderNo = "1234323JKHDFE1243252"; 42 request.appid = "wxd678efh567hg6787"; 43 request.serviceId = "2002000000000558128851361561536"; 44 request.serviceIntroduction = "某某酒店"; 45 request.postPayments = new ArrayList<>(); 46 { 47 Payment postPaymentsItem = new Payment(); 48 postPaymentsItem.name = "就餐费用"; 49 postPaymentsItem.amount = 40000L; 50 postPaymentsItem.description = "就餐人均100元"; 51 postPaymentsItem.count = 4L; 52 request.postPayments.add(postPaymentsItem); 53 }; 54 request.postDiscounts = new ArrayList<>(); 55 { 56 ServiceOrderCoupon postDiscountsItem = new ServiceOrderCoupon(); 57 postDiscountsItem.name = "满20减1元"; 58 postDiscountsItem.description = "不与其他优惠叠加"; 59 postDiscountsItem.amount = 100L; 60 request.postDiscounts.add(postDiscountsItem); 61 }; 62 request.timeRange = new TimeRange(); 63 request.timeRange.startTime = "20091225091010"; 64 request.timeRange.endTime = "20091225121010"; 65 request.timeRange.startTimeRemark = "备注1"; 66 request.timeRange.endTimeRemark = "备注2"; 67 request.location = new Location(); 68 request.location.startLocation = "嗨客时尚主题展餐厅"; 69 request.location.endLocation = "嗨客时尚主题展餐厅"; 70 request.riskFund = new RiskFund(); 71 request.riskFund.name = "DEPOSIT"; 72 request.riskFund.amount = 10000L; 73 request.riskFund.description = "就餐的预估费用"; 74 request.attach = "Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald"; 75 request.notifyUrl = "https://api.test.com"; 76 request.needUserConfirm = false; 77 request.device = new Device(); 78 request.device.startDeviceId = "HG123456"; 79 request.device.endDeviceId = "HG123456"; 80 request.device.materielNo = "example_materiel_no"; 81 try { 82 CreateServiceOrderResponse response = client.run(request); 83 // TODO: 请求成功,继续业务逻辑 84 System.out.println(response); 85 } catch (WXPayUtility.ApiException e) { 86 // TODO: 请求失败,根据状态码执行不同的逻辑 87 e.printStackTrace(); 88 } 89 } 90 91 public CreateServiceOrderResponse run(CreateServiceOrderRequest request) { 92 String uri = PATH; 93 String reqBody = WXPayUtility.toJson(request); 94 95 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 96 reqBuilder.addHeader("Accept", "application/json"); 97 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 98 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 99 reqBuilder.addHeader("Content-Type", "application/json"); 100 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 101 reqBuilder.method(METHOD, requestBody); 102 Request httpRequest = reqBuilder.build(); 103 104 // 发送HTTP请求 105 OkHttpClient client = new OkHttpClient.Builder().build(); 106 try (Response httpResponse = client.newCall(httpRequest).execute()) { 107 String respBody = WXPayUtility.extractBody(httpResponse); 108 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 109 // 2XX 成功,验证应答签名 110 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 111 httpResponse.headers(), respBody); 112 113 // 从HTTP应答报文构建返回数据 114 return WXPayUtility.fromJson(respBody, CreateServiceOrderResponse.class); 115 } else { 116 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 117 } 118 } catch (IOException e) { 119 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 120 } 121 } 122 123 private final String mchid; 124 private final String certificateSerialNo; 125 private final PrivateKey privateKey; 126 private final String wechatPayPublicKeyId; 127 private final PublicKey wechatPayPublicKey; 128 129 public CreateServiceOrder(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 130 this.mchid = mchid; 131 this.certificateSerialNo = certificateSerialNo; 132 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 133 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 134 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 135 } 136 137 public static class CreateServiceOrderRequest { 138 @SerializedName("out_order_no") 139 public String outOrderNo; 140 141 @SerializedName("appid") 142 public String appid; 143 144 @SerializedName("service_id") 145 public String serviceId; 146 147 @SerializedName("service_introduction") 148 public String serviceIntroduction; 149 150 @SerializedName("post_payments") 151 public List<Payment> postPayments; 152 153 @SerializedName("post_discounts") 154 public List<ServiceOrderCoupon> postDiscounts; 155 156 @SerializedName("time_range") 157 public TimeRange timeRange; 158 159 @SerializedName("location") 160 public Location location; 161 162 @SerializedName("risk_fund") 163 public RiskFund riskFund; 164 165 @SerializedName("attach") 166 public String attach; 167 168 @SerializedName("notify_url") 169 public String notifyUrl; 170 171 @SerializedName("need_user_confirm") 172 public Boolean needUserConfirm; 173 174 @SerializedName("device") 175 public Device device; 176 } 177 178 public static class CreateServiceOrderResponse { 179 @SerializedName("appid") 180 public String appid; 181 182 @SerializedName("mchid") 183 public String mchid; 184 185 @SerializedName("out_order_no") 186 public String outOrderNo; 187 188 @SerializedName("service_id") 189 public String serviceId; 190 191 @SerializedName("service_introduction") 192 public String serviceIntroduction; 193 194 @SerializedName("state") 195 public String state; 196 197 @SerializedName("state_description") 198 public String stateDescription; 199 200 @SerializedName("post_payments") 201 public List<Payment> postPayments; 202 203 @SerializedName("post_discounts") 204 public List<ServiceOrderCoupon> postDiscounts; 205 206 @SerializedName("risk_fund") 207 public RiskFund riskFund; 208 209 @SerializedName("time_range") 210 public TimeRange timeRange; 211 212 @SerializedName("location") 213 public Location location; 214 215 @SerializedName("attach") 216 public String attach; 217 218 @SerializedName("notify_url") 219 public String notifyUrl; 220 221 @SerializedName("order_id") 222 public String orderId; 223 224 @SerializedName("package") 225 public String _package; 226 } 227 228 public static class Payment { 229 @SerializedName("name") 230 public String name; 231 232 @SerializedName("amount") 233 public Long amount; 234 235 @SerializedName("description") 236 public String description; 237 238 @SerializedName("count") 239 public Long count; 240 } 241 242 public static class ServiceOrderCoupon { 243 @SerializedName("name") 244 public String name; 245 246 @SerializedName("description") 247 public String description; 248 249 @SerializedName("amount") 250 public Long amount; 251 } 252 253 public static class TimeRange { 254 @SerializedName("start_time") 255 public String startTime; 256 257 @SerializedName("end_time") 258 public String endTime; 259 260 @SerializedName("start_time_remark") 261 public String startTimeRemark; 262 263 @SerializedName("end_time_remark") 264 public String endTimeRemark; 265 } 266 267 public static class Location { 268 @SerializedName("start_location") 269 public String startLocation; 270 271 @SerializedName("end_location") 272 public String endLocation; 273 } 274 275 public static class RiskFund { 276 @SerializedName("name") 277 public String name; 278 279 @SerializedName("amount") 280 public Long amount; 281 282 @SerializedName("description") 283 public String description; 284 } 285 286 public static class Device { 287 @SerializedName("start_device_id") 288 public String startDeviceId; 289 290 @SerializedName("end_device_id") 291 public String endDeviceId; 292 293 @SerializedName("materiel_no") 294 public String materielNo; 295 } 296 297} 298
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/merchant/4015119334 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 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 := &CreateServiceOrderRequest{ 27 OutOrderNo: wxpay_utility.String("1234323JKHDFE1243252"), 28 Appid: wxpay_utility.String("wxd678efh567hg6787"), 29 ServiceId: wxpay_utility.String("2002000000000558128851361561536"), 30 ServiceIntroduction: wxpay_utility.String("某某酒店"), 31 PostPayments: []Payment{Payment{ 32 Name: wxpay_utility.String("就餐费用"), 33 Amount: wxpay_utility.Int64(40000), 34 Description: wxpay_utility.String("就餐人均100元"), 35 Count: wxpay_utility.Int64(4), 36 }}, 37 PostDiscounts: []ServiceOrderCoupon{ServiceOrderCoupon{ 38 Name: wxpay_utility.String("满20减1元"), 39 Description: wxpay_utility.String("不与其他优惠叠加"), 40 Amount: wxpay_utility.Int64(100), 41 }}, 42 TimeRange: &TimeRange{ 43 StartTime: wxpay_utility.String("20091225091010"), 44 EndTime: wxpay_utility.String("20091225121010"), 45 StartTimeRemark: wxpay_utility.String("备注1"), 46 EndTimeRemark: wxpay_utility.String("备注2"), 47 }, 48 Location: &Location{ 49 StartLocation: wxpay_utility.String("嗨客时尚主题展餐厅"), 50 EndLocation: wxpay_utility.String("嗨客时尚主题展餐厅"), 51 }, 52 RiskFund: &RiskFund{ 53 Name: wxpay_utility.String("DEPOSIT"), 54 Amount: wxpay_utility.Int64(10000), 55 Description: wxpay_utility.String("就餐的预估费用"), 56 }, 57 Attach: wxpay_utility.String("Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald"), 58 NotifyUrl: wxpay_utility.String("https://api.test.com"), 59 NeedUserConfirm: wxpay_utility.Bool(false), 60 Device: &Device{ 61 StartDeviceId: wxpay_utility.String("HG123456"), 62 EndDeviceId: wxpay_utility.String("HG123456"), 63 MaterielNo: wxpay_utility.String("example_materiel_no"), 64 }, 65 } 66 67 response, err := CreateServiceOrder(config, request) 68 if err != nil { 69 fmt.Printf("请求失败: %+v\n", err) 70 // TODO: 请求失败,根据状态码执行不同的处理 71 return 72 } 73 74 // TODO: 请求成功,继续业务逻辑 75 fmt.Printf("请求成功: %+v\n", response) 76} 77 78func CreateServiceOrder(config *wxpay_utility.MchConfig, request *CreateServiceOrderRequest) (response *CreateServiceOrderResponse, err error) { 79 const ( 80 host = "https://api.mch.weixin.qq.com" 81 method = "POST" 82 path = "/v3/payscore/serviceorder" 83 ) 84 85 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 86 if err != nil { 87 return nil, err 88 } 89 reqBody, err := json.Marshal(request) 90 if err != nil { 91 return nil, err 92 } 93 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 94 if err != nil { 95 return nil, err 96 } 97 httpRequest.Header.Set("Accept", "application/json") 98 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 99 httpRequest.Header.Set("Content-Type", "application/json") 100 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 101 if err != nil { 102 return nil, err 103 } 104 httpRequest.Header.Set("Authorization", authorization) 105 106 client := &http.Client{} 107 httpResponse, err := client.Do(httpRequest) 108 if err != nil { 109 return nil, err 110 } 111 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 112 if err != nil { 113 return nil, err 114 } 115 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 116 // 2XX 成功,验证应答签名 117 err = wxpay_utility.ValidateResponse( 118 config.WechatPayPublicKeyId(), 119 config.WechatPayPublicKey(), 120 &httpResponse.Header, 121 respBody, 122 ) 123 if err != nil { 124 return nil, err 125 } 126 response := &CreateServiceOrderResponse{} 127 if err := json.Unmarshal(respBody, response); err != nil { 128 return nil, err 129 } 130 131 return response, nil 132 } else { 133 return nil, wxpay_utility.NewApiException( 134 httpResponse.StatusCode, 135 httpResponse.Header, 136 respBody, 137 ) 138 } 139} 140 141type CreateServiceOrderRequest struct { 142 OutOrderNo *string `json:"out_order_no,omitempty"` 143 Appid *string `json:"appid,omitempty"` 144 ServiceId *string `json:"service_id,omitempty"` 145 ServiceIntroduction *string `json:"service_introduction,omitempty"` 146 PostPayments []Payment `json:"post_payments,omitempty"` 147 PostDiscounts []ServiceOrderCoupon `json:"post_discounts,omitempty"` 148 TimeRange *TimeRange `json:"time_range,omitempty"` 149 Location *Location `json:"location,omitempty"` 150 RiskFund *RiskFund `json:"risk_fund,omitempty"` 151 Attach *string `json:"attach,omitempty"` 152 NotifyUrl *string `json:"notify_url,omitempty"` 153 NeedUserConfirm *bool `json:"need_user_confirm,omitempty"` 154 Device *Device `json:"device,omitempty"` 155} 156 157type CreateServiceOrderResponse struct { 158 Appid *string `json:"appid,omitempty"` 159 Mchid *string `json:"mchid,omitempty"` 160 OutOrderNo *string `json:"out_order_no,omitempty"` 161 ServiceId *string `json:"service_id,omitempty"` 162 ServiceIntroduction *string `json:"service_introduction,omitempty"` 163 State *string `json:"state,omitempty"` 164 StateDescription *string `json:"state_description,omitempty"` 165 PostPayments []Payment `json:"post_payments,omitempty"` 166 PostDiscounts []ServiceOrderCoupon `json:"post_discounts,omitempty"` 167 RiskFund *RiskFund `json:"risk_fund,omitempty"` 168 TimeRange *TimeRange `json:"time_range,omitempty"` 169 Location *Location `json:"location,omitempty"` 170 Attach *string `json:"attach,omitempty"` 171 NotifyUrl *string `json:"notify_url,omitempty"` 172 OrderId *string `json:"order_id,omitempty"` 173 Package *string `json:"package,omitempty"` 174} 175 176type Payment struct { 177 Name *string `json:"name,omitempty"` 178 Amount *int64 `json:"amount,omitempty"` 179 Description *string `json:"description,omitempty"` 180 Count *int64 `json:"count,omitempty"` 181} 182 183type ServiceOrderCoupon struct { 184 Name *string `json:"name,omitempty"` 185 Description *string `json:"description,omitempty"` 186 Amount *int64 `json:"amount,omitempty"` 187} 188 189type TimeRange struct { 190 StartTime *string `json:"start_time,omitempty"` 191 EndTime *string `json:"end_time,omitempty"` 192 StartTimeRemark *string `json:"start_time_remark,omitempty"` 193 EndTimeRemark *string `json:"end_time_remark,omitempty"` 194} 195 196type Location struct { 197 StartLocation *string `json:"start_location,omitempty"` 198 EndLocation *string `json:"end_location,omitempty"` 199} 200 201type RiskFund struct { 202 Name *string `json:"name,omitempty"` 203 Amount *int64 `json:"amount,omitempty"` 204 Description *string `json:"description,omitempty"` 205} 206 207type Device struct { 208 StartDeviceId *string `json:"start_device_id,omitempty"` 209 EndDeviceId *string `json:"end_device_id,omitempty"` 210 MaterielNo *string `json:"materiel_no,omitempty"` 211} 212
应答参数
|
appid 必填 string(32)
【公众账号ID】是微信开放平台和微信公众平台为开发者的应用程序(APP、小程序、公众号)提供的一个唯一标识。 开发者需要先在微信开放平台或微信公众平台中申请ID,然后在商户平台中绑定,详见直连商户与AppID账号关联管理。完结订单和取消订单需要和创单传入的appid保持一致。
mchid 必填 string(32)
【商户号】调用支付分创单接口提交的商户号,商户号需开通支付分产品权限,且与appid有绑定关系,详见直连商户与AppID账号关联管理。
out_order_no 必填 string(32)
【商户服务订单号】商户系统内部服务订单号,要求32个字符内,只能是数字、大小写字母_-| 且在同一个商户号下唯一。需要开发者特别注意,该参数不可用于申请退款接口中的 out_trade_no 参数。
service_id 必填 string(32)
【服务ID】商户支付分服务的唯一标识,由32位数字组成。支付分产品权限审核通过后,微信支付运营会向商户提供该ID。
service_introduction 必填 string(20)
【服务信息】用于介绍本订单所提供的服务 ,长度不能超过20个字符(汉字、数字、字母、特殊符号都按照1个字符计算)。
state 必填 string(32)
【服务订单状态】表示支付分订单状态
CREATED:商户已创建服务订单
DOING:服务订单进行中
DONE:服务订单完成(终态)
REVOKED:商户取消服务订单(终态)
EXPIRED:服务订单已失效,"商户已创建服务订单"状态超过30天未变动,则订单失效(终态)
该状态需结合collection.state字段和state_description字段一起判断,具体可参考支付分订单状态流转图。
state_description 选填 string
【订单状态说明】此参数用于对服务订单处于DOING状态时的附加说明,非DOIING状态将不会返回该参数。具体状态如下:
USER_CONFIRM:用户已确认状态,表示用户成功确认订单后所处状态。
MCH_COMPLETE:商户已完结状态,指商户调用完结接口成功后至扣款成功前的状态。
该状态需结合collection.state字段和state字段一起判断,具体可参考支付分订单状态流转图。
post_payments 选填 array[object]
【后付费项目】用于展示订单后付费项目明细,商户需要按照所属行业规程传参,详见post_payments(后付费项目)字段传参说明
属性 | |
name 选填 string(20) 【付费名称】不能超过20个字符,需严格按照post_payments(后付费项目)字段传参说明传参。 amount 选填 integer 【付费金额】付费项目金额,整型,大于等于0(等于0时表示不需要扣费),单位为分。需严格按照post_payments(后付费项目)字段传参说明传参。 description 选填 string(30) 【付费说明】对付费项目的详细说明,不超过30个字符,需严格按照post_payments(后付费项目)字段传参说明传参。 count 选填 integer 【付费数量】后付费项目的数量,为整型。相同的后付费项目建议合并计算amount和count |
post_discounts 选填 array[object]
【后付费商户优惠】用于展示订单优惠项目明细,最多30条,完结订单时传的收款总金额需满足计算条件(收款总金额=后付费项目amount和-优惠项目amount和)
属性 | |
name 选填 string(20) 【优惠名称】用于描述优惠项目,不超过20个字符,同一单多个优惠项目名称不可重复。 description 选填 string(30) 【优惠说明】用于描述优惠项目使用条件,不超过30个字符。 amount 选填 integer 【优惠金额】优惠金额 count 选填 integer 【优惠数量】整型,用于描述优惠项目使用数量,例如用户使用了两张同一活动优惠券,则count填2。 |
risk_fund 选填 object
【服务风险金】本笔订单的风险金额描述
属性 | |
name 必填 string(30) 【风险名称】 amount 必填 integer 【风险金额】 description 选填 string(30) 【风险说明】用于描述说明该风险金,不能超过30字符。 |
time_range 选填 object
【服务时间段】用于描述订单的服务开始和结束时间。
属性 | |
start_time 选填 string(14) 【服务开始时间】 end_time 选填 string(14) 【服务结束时间】 start_time_remark 选填 string(20) 【服务开始时间备注】当有传入服务开始时间时,可添加备注说明,不超过20个字符。 end_time_remark 选填 string(20) 【服务结束时间备注】当有传入服务结束时间时,可添加备注说明,不超过20个字符。 |
location 选填 object
【服务位置】服务使用的开始位置和结束位置
属性 | |
start_location 选填 string(20) 【服务开始地点】用户开始使用服务的地点,不超过20个字符。 end_location 选填 string(20) 【服务结束地点】用户结束使用服务的地点,不超过20个字符。 |
attach 选填 string(256)
【商户数据包】商户在创建订单时传入的自定义数据包,用户不可见。用于存放订单的商户自定义数据,需要先进行urlencode编码,总长度不超过256字符。确认订单回调和支付成功回调时会回传该字段给商户。
notify_url 选填 string(256)
【商户回调地址】商户接收确认订单回调通知和支付成功回调通知(的地址,创单时传入,需按照notify-url填写注意事项规范填写。
order_id 必填 string(64)
【微信支付服务订单号】支付分订单在微信侧的唯一标识,31位数字,开头由1000000000+年月日组成。
package 必填 string(300)
【跳转微信侧小程序订单数据】创建支付分订单成功后返回,用于拉起支付分小程序确认订单页面,由数字大小写字母_-符号组成,不超过300字符。
应答示例
200 OK
1{ 2 "appid" : "wxd678efh567hg6787", 3 "mchid" : "1230000109", 4 "out_order_no" : "1234323JKHDFE1243252", 5 "service_id" : "2002000000000558128851361561536", 6 "service_introduction" : "某某酒店", 7 "state" : "CREATED", 8 "state_description" : "MCH_COMPLETE", 9 "post_payments" : [ 10 { 11 "name" : "就餐费用", 12 "amount" : 40000, 13 "description" : "就餐人均100元", 14 "count" : 4 15 } 16 ], 17 "post_discounts" : [ 18 { 19 "name" : "满20减1元", 20 "description" : "不与其他优惠叠加", 21 "amount" : 100 22 } 23 ], 24 "risk_fund" : { 25 "name" : "DEPOSIT", 26 "amount" : 10000, 27 "description" : "就餐的预估费用" 28 }, 29 "time_range" : { 30 "start_time" : "20091225091010", 31 "end_time" : "20091225121010", 32 "start_time_remark" : "备注1", 33 "end_time_remark" : "备注2" 34 }, 35 "location" : { 36 "start_location" : "嗨客时尚主题展餐厅", 37 "end_location" : "嗨客时尚主题展餐厅" 38 }, 39 "attach" : "Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald", 40 "notify_url" : "https://api.test.com", 41 "order_id" : "15646546545165651651", 42 "package" : "DJIOSQPYWDxsjdldeuwhdodwxasd_dDiodnwjh9we" 43} 44
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_ORDER_STATE | 单据状态错误 | 确认操作是否符合流程 |
400 | INVALID_REQUEST | 请求参数符合参数格式,但不符合业务规则 | 请确认相同单号是否使用了不同的参数 |
400 | ORDER_CANCELED | 单据已取消 | 当前状态无需操作 |
400 | ORDER_DONE | 订单已完成 | 当前状态无需操作 |
403 | NO_AUTH | 商户信息不合法 | 登录商户平台核对,传入正确信息 |
404 | ORDER_NOT_ EXIST | 订单不存在 | 确认入参,传入正确单据 |
429 | FREQUENCY_LIMITED | 频率超限 | 请求量不要超过接口调用频率限制 |
500 | SYSTEM_ERROR | 系统错误 | 5开头的状态码都为系统问题,请使用相同参数稍后重新调用 |