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