创建支付分订单
更新时间: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 "count" : 2 25 } 26 ], 27 "time_range" : { 28 "start_time" : "20091225091010", 29 "end_time" : "20091225121010", 30 "start_time_remark" : "备注1", 31 "end_time_remark" : "备注2" 32 }, 33 "location" : { 34 "start_location" : "嗨客时尚主题展餐厅", 35 "end_location" : "嗨客时尚主题展餐厅" 36 }, 37 "risk_fund" : { 38 "name" : "DEPOSIT", 39 "amount" : 10000, 40 "description" : "就餐的预估费用" 41 }, 42 "attach" : "Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald", 43 "notify_url" : "https://api.test.com", 44 "need_user_confirm" : false, 45 "device" : { 46 "start_device_id" : "HG123456", 47 "end_device_id" : "HG123456", 48 "materiel_no" : "example_materiel_no" 49 } 50 }' 51
需配合微信支付工具库 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 postDiscountsItem.count = 2L; 61 request.postDiscounts.add(postDiscountsItem); 62 }; 63 request.timeRange = new TimeRange(); 64 request.timeRange.startTime = "20091225091010"; 65 request.timeRange.endTime = "20091225121010"; 66 request.timeRange.startTimeRemark = "备注1"; 67 request.timeRange.endTimeRemark = "备注2"; 68 request.location = new Location(); 69 request.location.startLocation = "嗨客时尚主题展餐厅"; 70 request.location.endLocation = "嗨客时尚主题展餐厅"; 71 request.riskFund = new RiskFund(); 72 request.riskFund.name = "DEPOSIT"; 73 request.riskFund.amount = 10000L; 74 request.riskFund.description = "就餐的预估费用"; 75 request.attach = "Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald"; 76 request.notifyUrl = "https://api.test.com"; 77 request.needUserConfirm = false; 78 request.device = new Device(); 79 request.device.startDeviceId = "HG123456"; 80 request.device.endDeviceId = "HG123456"; 81 request.device.materielNo = "example_materiel_no"; 82 try { 83 CreateServiceOrderResponse response = client.run(request); 84 // TODO: 请求成功,继续业务逻辑 85 System.out.println(response); 86 } catch (WXPayUtility.ApiException e) { 87 // TODO: 请求失败,根据状态码执行不同的逻辑 88 e.printStackTrace(); 89 } 90 } 91 92 public CreateServiceOrderResponse run(CreateServiceOrderRequest request) { 93 String uri = PATH; 94 String reqBody = WXPayUtility.toJson(request); 95 96 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 97 reqBuilder.addHeader("Accept", "application/json"); 98 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 99 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 100 reqBuilder.addHeader("Content-Type", "application/json"); 101 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 102 reqBuilder.method(METHOD, requestBody); 103 Request httpRequest = reqBuilder.build(); 104 105 // 发送HTTP请求 106 OkHttpClient client = new OkHttpClient.Builder().build(); 107 try (Response httpResponse = client.newCall(httpRequest).execute()) { 108 String respBody = WXPayUtility.extractBody(httpResponse); 109 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 110 // 2XX 成功,验证应答签名 111 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 112 httpResponse.headers(), respBody); 113 114 // 从HTTP应答报文构建返回数据 115 return WXPayUtility.fromJson(respBody, CreateServiceOrderResponse.class); 116 } else { 117 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 118 } 119 } catch (IOException e) { 120 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 121 } 122 } 123 124 private final String mchid; 125 private final String certificateSerialNo; 126 private final PrivateKey privateKey; 127 private final String wechatPayPublicKeyId; 128 private final PublicKey wechatPayPublicKey; 129 130 public CreateServiceOrder(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 131 this.mchid = mchid; 132 this.certificateSerialNo = certificateSerialNo; 133 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 134 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 135 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 136 } 137 138 public static class CreateServiceOrderRequest { 139 @SerializedName("out_order_no") 140 public String outOrderNo; 141 142 @SerializedName("appid") 143 public String appid; 144 145 @SerializedName("service_id") 146 public String serviceId; 147 148 @SerializedName("service_introduction") 149 public String serviceIntroduction; 150 151 @SerializedName("post_payments") 152 public List<Payment> postPayments; 153 154 @SerializedName("post_discounts") 155 public List<ServiceOrderCoupon> postDiscounts; 156 157 @SerializedName("time_range") 158 public TimeRange timeRange; 159 160 @SerializedName("location") 161 public Location location; 162 163 @SerializedName("risk_fund") 164 public RiskFund riskFund; 165 166 @SerializedName("attach") 167 public String attach; 168 169 @SerializedName("notify_url") 170 public String notifyUrl; 171 172 @SerializedName("need_user_confirm") 173 public Boolean needUserConfirm; 174 175 @SerializedName("device") 176 public Device device; 177 } 178 179 public static class CreateServiceOrderResponse { 180 @SerializedName("appid") 181 public String appid; 182 183 @SerializedName("mchid") 184 public String mchid; 185 186 @SerializedName("out_order_no") 187 public String outOrderNo; 188 189 @SerializedName("service_id") 190 public String serviceId; 191 192 @SerializedName("service_introduction") 193 public String serviceIntroduction; 194 195 @SerializedName("state") 196 public String state; 197 198 @SerializedName("state_description") 199 public String stateDescription; 200 201 @SerializedName("post_payments") 202 public List<Payment> postPayments; 203 204 @SerializedName("post_discounts") 205 public List<ServiceOrderCoupon> postDiscounts; 206 207 @SerializedName("risk_fund") 208 public RiskFund riskFund; 209 210 @SerializedName("time_range") 211 public TimeRange timeRange; 212 213 @SerializedName("location") 214 public Location location; 215 216 @SerializedName("attach") 217 public String attach; 218 219 @SerializedName("notify_url") 220 public String notifyUrl; 221 222 @SerializedName("order_id") 223 public String orderId; 224 225 @SerializedName("package") 226 public String _package; 227 } 228 229 public static class Payment { 230 @SerializedName("name") 231 public String name; 232 233 @SerializedName("amount") 234 public Long amount; 235 236 @SerializedName("description") 237 public String description; 238 239 @SerializedName("count") 240 public Long count; 241 } 242 243 public static class ServiceOrderCoupon { 244 @SerializedName("name") 245 public String name; 246 247 @SerializedName("description") 248 public String description; 249 250 @SerializedName("amount") 251 public Long amount; 252 253 @SerializedName("count") 254 public Long count; 255 } 256 257 public static class TimeRange { 258 @SerializedName("start_time") 259 public String startTime; 260 261 @SerializedName("end_time") 262 public String endTime; 263 264 @SerializedName("start_time_remark") 265 public String startTimeRemark; 266 267 @SerializedName("end_time_remark") 268 public String endTimeRemark; 269 } 270 271 public static class Location { 272 @SerializedName("start_location") 273 public String startLocation; 274 275 @SerializedName("end_location") 276 public String endLocation; 277 } 278 279 public static class RiskFund { 280 @SerializedName("name") 281 public String name; 282 283 @SerializedName("amount") 284 public Long amount; 285 286 @SerializedName("description") 287 public String description; 288 } 289 290 public static class Device { 291 @SerializedName("start_device_id") 292 public String startDeviceId; 293 294 @SerializedName("end_device_id") 295 public String endDeviceId; 296 297 @SerializedName("materiel_no") 298 public String materielNo; 299 } 300 301} 302
需配合微信支付工具库 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 Count: wxpay_utility.Int64(2), 42 }}, 43 TimeRange: &TimeRange{ 44 StartTime: wxpay_utility.String("20091225091010"), 45 EndTime: wxpay_utility.String("20091225121010"), 46 StartTimeRemark: wxpay_utility.String("备注1"), 47 EndTimeRemark: wxpay_utility.String("备注2"), 48 }, 49 Location: &Location{ 50 StartLocation: wxpay_utility.String("嗨客时尚主题展餐厅"), 51 EndLocation: wxpay_utility.String("嗨客时尚主题展餐厅"), 52 }, 53 RiskFund: &RiskFund{ 54 Name: wxpay_utility.String("DEPOSIT"), 55 Amount: wxpay_utility.Int64(10000), 56 Description: wxpay_utility.String("就餐的预估费用"), 57 }, 58 Attach: wxpay_utility.String("Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald"), 59 NotifyUrl: wxpay_utility.String("https://api.test.com"), 60 NeedUserConfirm: wxpay_utility.Bool(false), 61 Device: &Device{ 62 StartDeviceId: wxpay_utility.String("HG123456"), 63 EndDeviceId: wxpay_utility.String("HG123456"), 64 MaterielNo: wxpay_utility.String("example_materiel_no"), 65 }, 66 } 67 68 response, err := CreateServiceOrder(config, request) 69 if err != nil { 70 fmt.Printf("请求失败: %+v\n", err) 71 // TODO: 请求失败,根据状态码执行不同的处理 72 return 73 } 74 75 // TODO: 请求成功,继续业务逻辑 76 fmt.Printf("请求成功: %+v\n", response) 77} 78 79func CreateServiceOrder(config *wxpay_utility.MchConfig, request *CreateServiceOrderRequest) (response *CreateServiceOrderResponse, err error) { 80 const ( 81 host = "https://api.mch.weixin.qq.com" 82 method = "POST" 83 path = "/v3/payscore/serviceorder" 84 ) 85 86 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 87 if err != nil { 88 return nil, err 89 } 90 reqBody, err := json.Marshal(request) 91 if err != nil { 92 return nil, err 93 } 94 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 95 if err != nil { 96 return nil, err 97 } 98 httpRequest.Header.Set("Accept", "application/json") 99 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 100 httpRequest.Header.Set("Content-Type", "application/json") 101 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 102 if err != nil { 103 return nil, err 104 } 105 httpRequest.Header.Set("Authorization", authorization) 106 107 client := &http.Client{} 108 httpResponse, err := client.Do(httpRequest) 109 if err != nil { 110 return nil, err 111 } 112 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 113 if err != nil { 114 return nil, err 115 } 116 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 117 // 2XX 成功,验证应答签名 118 err = wxpay_utility.ValidateResponse( 119 config.WechatPayPublicKeyId(), 120 config.WechatPayPublicKey(), 121 &httpResponse.Header, 122 respBody, 123 ) 124 if err != nil { 125 return nil, err 126 } 127 response := &CreateServiceOrderResponse{} 128 if err := json.Unmarshal(respBody, response); err != nil { 129 return nil, err 130 } 131 132 return response, nil 133 } else { 134 return nil, wxpay_utility.NewApiException( 135 httpResponse.StatusCode, 136 httpResponse.Header, 137 respBody, 138 ) 139 } 140} 141 142type CreateServiceOrderRequest struct { 143 OutOrderNo *string `json:"out_order_no,omitempty"` 144 Appid *string `json:"appid,omitempty"` 145 ServiceId *string `json:"service_id,omitempty"` 146 ServiceIntroduction *string `json:"service_introduction,omitempty"` 147 PostPayments []Payment `json:"post_payments,omitempty"` 148 PostDiscounts []ServiceOrderCoupon `json:"post_discounts,omitempty"` 149 TimeRange *TimeRange `json:"time_range,omitempty"` 150 Location *Location `json:"location,omitempty"` 151 RiskFund *RiskFund `json:"risk_fund,omitempty"` 152 Attach *string `json:"attach,omitempty"` 153 NotifyUrl *string `json:"notify_url,omitempty"` 154 NeedUserConfirm *bool `json:"need_user_confirm,omitempty"` 155 Device *Device `json:"device,omitempty"` 156} 157 158type CreateServiceOrderResponse struct { 159 Appid *string `json:"appid,omitempty"` 160 Mchid *string `json:"mchid,omitempty"` 161 OutOrderNo *string `json:"out_order_no,omitempty"` 162 ServiceId *string `json:"service_id,omitempty"` 163 ServiceIntroduction *string `json:"service_introduction,omitempty"` 164 State *string `json:"state,omitempty"` 165 StateDescription *string `json:"state_description,omitempty"` 166 PostPayments []Payment `json:"post_payments,omitempty"` 167 PostDiscounts []ServiceOrderCoupon `json:"post_discounts,omitempty"` 168 RiskFund *RiskFund `json:"risk_fund,omitempty"` 169 TimeRange *TimeRange `json:"time_range,omitempty"` 170 Location *Location `json:"location,omitempty"` 171 Attach *string `json:"attach,omitempty"` 172 NotifyUrl *string `json:"notify_url,omitempty"` 173 OrderId *string `json:"order_id,omitempty"` 174 Package *string `json:"package,omitempty"` 175} 176 177type Payment struct { 178 Name *string `json:"name,omitempty"` 179 Amount *int64 `json:"amount,omitempty"` 180 Description *string `json:"description,omitempty"` 181 Count *int64 `json:"count,omitempty"` 182} 183 184type ServiceOrderCoupon struct { 185 Name *string `json:"name,omitempty"` 186 Description *string `json:"description,omitempty"` 187 Amount *int64 `json:"amount,omitempty"` 188 Count *int64 `json:"count,omitempty"` 189} 190 191type TimeRange struct { 192 StartTime *string `json:"start_time,omitempty"` 193 EndTime *string `json:"end_time,omitempty"` 194 StartTimeRemark *string `json:"start_time_remark,omitempty"` 195 EndTimeRemark *string `json:"end_time_remark,omitempty"` 196} 197 198type Location struct { 199 StartLocation *string `json:"start_location,omitempty"` 200 EndLocation *string `json:"end_location,omitempty"` 201} 202 203type RiskFund struct { 204 Name *string `json:"name,omitempty"` 205 Amount *int64 `json:"amount,omitempty"` 206 Description *string `json:"description,omitempty"` 207} 208 209type Device struct { 210 StartDeviceId *string `json:"start_device_id,omitempty"` 211 EndDeviceId *string `json:"end_device_id,omitempty"` 212 MaterielNo *string `json:"materiel_no,omitempty"` 213} 214
应答参数
|
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 "count" : 2 23 } 24 ], 25 "risk_fund" : { 26 "name" : "DEPOSIT", 27 "amount" : 10000, 28 "description" : "就餐的预估费用" 29 }, 30 "time_range" : { 31 "start_time" : "20091225091010", 32 "end_time" : "20091225121010", 33 "start_time_remark" : "备注1", 34 "end_time_remark" : "备注2" 35 }, 36 "location" : { 37 "start_location" : "嗨客时尚主题展餐厅", 38 "end_location" : "嗨客时尚主题展餐厅" 39 }, 40 "attach" : "Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald", 41 "notify_url" : "https://api.test.com", 42 "order_id" : "15646546545165651651", 43 "package" : "DJIOSQPYWDxsjdldeuwhdodwxasd_dDiodnwjh9we" 44} 45
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
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开头的状态码都为系统问题,请使用相同参数稍后重新调用 |