H5下单
更新时间:2025.03.31用户在商户H5页面选择微信支付后,商户需调用该接口在微信支付下单,生成用于调起支付的H5支付链接(h5_url)。
接口说明
支持商户:【普通商户】
请求方式:【POST】/v3/pay/transactions/h5
请求域名:【主域名】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 包体参数
appid 必填 string(32)
【公众账号ID】APPID是微信开放平台(移动应用)或微信公众平台(小程序、公众号)为开发者的应用程序提供的唯一标识。此处,可以填写这三种类型中的任意一种APPID,但请确保该appid与mchid有绑定关系。详见:普通商户模式开发必要参数说明。
mchid 必填 string(32)
【商户号】是由微信支付系统生成并分配给每个商户的唯一标识符。商户号获取方式请参考:普通商户模式开发必要参数说明。
description 必填 string(127)
【商品描述】商品信息描述,用户微信账单的商品字段中可见(可参考H5支付示例说明-账单示意图),商户需传递能真实代表商品信息的描述,不能超过127个字符。
out_trade_no 必填 string(32)
【商户订单号】商户系统内部订单号,要求6-32个字符内,只能是数字、大小写字母_-|* 且在同一个商户号下唯一。
time_expire 选填 string(64)
【交易结束时间】
1、定义:支付结束时间是指用户能够完成该笔订单支付的最后时限,并非订单关闭的时间。超过此时间后,用户将无法对该笔订单进行支付。如需关闭订单,请调用关闭订单API接口。
2、格式要求:支付结束时间需遵循rfc3339标准格式:yyyy-MM-DDTHH:mm:ss+TIMEZONE
。yyyy-MM-DD
表示年月日;T
字符用于分隔日期和时间部分;HH:mm:ss
表示具体的时分秒;TIMEZONE
表示时区(例如,+08:00
对应东八区时间,即北京时间)。
示例:2015-05-20T13:29:35+08:00
表示北京时间2015年5月20日13点29分35秒。
3、注意事项:
time_expire
参数仅在用户首次下单时可设置,且不允许后续修改,尝试修改将导致错误。若用户实际进行支付的时间超过了订单设置的支付结束时间,商户需使用新的商户订单号下单,生成新的订单供用户进行支付。若未超过支付结束时间,则可使用原参数重新请求下单接口,以获取当前订单最新的
h5_url
进行支付。支付结束时间不能早于下单时间后1分钟,若设置的支付结束时间早于该时间,系统将自动调整为下单时间后1分钟作为支付结束时间
attach 选填 string(128)
【商户数据包】商户在创建订单时可传入自定义数据包,该数据对用户不可见,用于存储订单相关的商户自定义信息,其总长度限制在128字符以内。支付成功后查询订单API和支付成功回调通知均会将此字段返回给商户,并且该字段还会体现在交易账单。
notify_url 必填 string(255)
【商户回调地址】商户接收支付成功回调通知的地址,创单时传入,需按照notify_url填写注意事项规范填写。
goods_tag 选填 string(32)
【订单优惠标记】代金券在创建时可以配置多个订单优惠标记,标记的内容由创券商户自定义设置。详细参考:创建代金券批次API。
如果代金券有配置订单优惠标记,则必须在该参数传任意一个配置的订单优惠标记才能使用券。
如果代金券没有配置订单优惠标记,则可以不传该参数。
示例:
如有两个活动,活动A设置了两个优惠标记:WXG1、WXG2;活动B设置了两个优惠标记:WXG1、WXG3;
下单时优惠标记传WXG2,则订单参与活动A的优惠;
下单时优惠标记传WXG3,则订单参与活动B的优惠;
下单时优惠标记传共同的WXG1,则订单参与活动A、B两个活动的优惠;
support_fapiao 选填 boolean
【电子发票入口开放标识】 传入true时,支付成功消息和支付详情页将出现开票入口。需要在微信支付商户平台或微信公众平台开通电子发票功能,传此字段才可生效。 详细参考:电子发票介绍
true:是
false:否
amount 必填 object
【订单金额】订单金额信息
属性 | |
total 必填 integer 【总金额】 订单总金额,单位为分,整型。 currency 选填 string(16) 【货币类型】符合ISO 4217标准的三位字母代码,固定传:CNY,代表人民币。 |
detail 选填 object
【优惠功能】 优惠功能
属性 | |||||
cost_price 选填 integer 【订单原价】 1、商户侧一张小票订单可能被分多次支付,订单原价用于记录整张小票的交易金额。 2、当订单原价与支付金额不相等,则不享受优惠。 3、该字段主要用于防止同一张小票分多次支付,以享受多次优惠的情况,正常支付订单不必上传此参数。 invoice_id 选填 string(32) 【商品小票ID】 商家小票ID goods_detail 选填 array[object] 【单品列表】 单品列表信息 条目个数限制:【1,6000】
|
scene_info 必填 object
【场景信息】 场景信息
属性 | |||||||||
payer_client_ip 必填 string(45) 【用户终端IP】 用户的客户端IP,支持IPv4和IPv6两种格式的IP地址。 device_id 选填 string(32) 【商户端设备号】 商户端设备号(门店号或收银设备ID)。 store_info 选填 object 【商户门店信息】 商户门店信息
h5_info 必填 object 【H5场景信息】
|
settle_info 选填 object
【结算信息】 结算信息
属性 | |
profit_sharing 选填 boolean 【分账标识】订单的分账标识在下单时设置,传入 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/pay/transactions/h5 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "appid" : "wxd678efh567hg6787", 8 "mchid" : "1230000109", 9 "description" : "Image形象店-深圳腾大-QQ公仔", 10 "out_trade_no" : "1217752501201407033233368018", 11 "time_expire" : "2018-06-08T10:34:56+08:00", 12 "attach" : "自定义数据说明", 13 "notify_url" : " https://www.weixin.qq.com/wxpay/pay.php", 14 "goods_tag" : "WXG", 15 "support_fapiao" : false, 16 "amount" : { 17 "total" : 100, 18 "currency" : "CNY" 19 }, 20 "detail" : { 21 "cost_price" : 608800, 22 "invoice_id" : "微信123", 23 "goods_detail" : [ 24 { 25 "merchant_goods_id" : "1246464644", 26 "wechatpay_goods_id" : "1001", 27 "goods_name" : "iPhoneX 256G", 28 "quantity" : 1, 29 "unit_price" : 528800 30 } 31 ] 32 }, 33 "scene_info" : { 34 "payer_client_ip" : "14.23.150.211", 35 "device_id" : "013467007045764", 36 "store_info" : { 37 "id" : "0001", 38 "name" : "腾讯大厦分店", 39 "area_code" : "440305", 40 "address" : "广东省深圳市南山区科技中一道10000号" 41 }, 42 "h5_info" : { 43 "type" : "iOS", 44 "app_name" : "王者荣耀", 45 "app_url" : "https://pay.qq.com", 46 "bundle_id" : "com.tencent.wzryiOS", 47 "package_name" : "com.tencent.tmgp.sgame" 48 } 49 }, 50 "settle_info" : { 51 "profit_sharing" : false 52 } 53 }' 54
需配合微信支付工具库 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 * H5下单 24 */ 25public class H5Prepay { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/pay/transactions/h5"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 H5Prepay client = new H5Prepay( 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 DirectAPIv3H5PrepayRequest request = new DirectAPIv3H5PrepayRequest(); 41 request.appid = "wxd678efh567hg6787"; 42 request.mchid = "1230000109"; 43 request.description = "Image形象店-深圳腾大-QQ公仔"; 44 request.outTradeNo = "1217752501201407033233368018"; 45 request.timeExpire = "2018-06-08T10:34:56+08:00"; 46 request.attach = "自定义数据说明"; 47 request.notifyUrl = " https://www.weixin.qq.com/wxpay/pay.php"; 48 request.goodsTag = "WXG"; 49 request.supportFapiao = false; 50 request.amount = new CommonAmountInfo(); 51 request.amount.total = 100L; 52 request.amount.currency = "CNY"; 53 request.detail = new CouponInfo(); 54 request.detail.costPrice = 608800L; 55 request.detail.invoiceId = "微信123"; 56 request.detail.goodsDetail = new ArrayList<>(); 57 { 58 GoodsDetail goodsDetailItem = new GoodsDetail(); 59 goodsDetailItem.merchantGoodsId = "1246464644"; 60 goodsDetailItem.wechatpayGoodsId = "1001"; 61 goodsDetailItem.goodsName = "iPhoneX 256G"; 62 goodsDetailItem.quantity = 1L; 63 goodsDetailItem.unitPrice = 528800L; 64 request.detail.goodsDetail.add(goodsDetailItem); 65 }; 66 request.sceneInfo = new H5ReqSceneInfo(); 67 request.sceneInfo.payerClientIp = "14.23.150.211"; 68 request.sceneInfo.deviceId = "013467007045764"; 69 request.sceneInfo.storeInfo = new StoreInfo(); 70 request.sceneInfo.storeInfo.id = "0001"; 71 request.sceneInfo.storeInfo.name = "腾讯大厦分店"; 72 request.sceneInfo.storeInfo.areaCode = "440305"; 73 request.sceneInfo.storeInfo.address = "广东省深圳市南山区科技中一道10000号"; 74 request.sceneInfo.h5Info = new H5Info(); 75 request.sceneInfo.h5Info.type = "iOS"; 76 request.sceneInfo.h5Info.appName = "王者荣耀"; 77 request.sceneInfo.h5Info.appUrl = "https://pay.qq.com"; 78 request.sceneInfo.h5Info.bundleId = "com.tencent.wzryiOS"; 79 request.sceneInfo.h5Info.packageName = "com.tencent.tmgp.sgame"; 80 request.settleInfo = new SettleInfo(); 81 request.settleInfo.profitSharing = false; 82 try { 83 DirectAPIv3H5PrepayResponse 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 DirectAPIv3H5PrepayResponse run(DirectAPIv3H5PrepayRequest 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, DirectAPIv3H5PrepayResponse.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 H5Prepay(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 DirectAPIv3H5PrepayRequest { 139 @SerializedName("appid") 140 public String appid; 141 142 @SerializedName("mchid") 143 public String mchid; 144 145 @SerializedName("description") 146 public String description; 147 148 @SerializedName("out_trade_no") 149 public String outTradeNo; 150 151 @SerializedName("time_expire") 152 public String timeExpire; 153 154 @SerializedName("attach") 155 public String attach; 156 157 @SerializedName("notify_url") 158 public String notifyUrl; 159 160 @SerializedName("goods_tag") 161 public String goodsTag; 162 163 @SerializedName("support_fapiao") 164 public Boolean supportFapiao; 165 166 @SerializedName("amount") 167 public CommonAmountInfo amount; 168 169 @SerializedName("detail") 170 public CouponInfo detail; 171 172 @SerializedName("scene_info") 173 public H5ReqSceneInfo sceneInfo; 174 175 @SerializedName("settle_info") 176 public SettleInfo settleInfo; 177 } 178 179 public static class DirectAPIv3H5PrepayResponse { 180 @SerializedName("h5_url") 181 public String h5Url; 182 } 183 184 public static class CommonAmountInfo { 185 @SerializedName("total") 186 public Long total; 187 188 @SerializedName("currency") 189 public String currency; 190 } 191 192 public static class CouponInfo { 193 @SerializedName("cost_price") 194 public Long costPrice; 195 196 @SerializedName("invoice_id") 197 public String invoiceId; 198 199 @SerializedName("goods_detail") 200 public List<GoodsDetail> goodsDetail; 201 } 202 203 public static class H5ReqSceneInfo { 204 @SerializedName("payer_client_ip") 205 public String payerClientIp; 206 207 @SerializedName("device_id") 208 public String deviceId; 209 210 @SerializedName("store_info") 211 public StoreInfo storeInfo; 212 213 @SerializedName("h5_info") 214 public H5Info h5Info; 215 } 216 217 public static class SettleInfo { 218 @SerializedName("profit_sharing") 219 public Boolean profitSharing; 220 } 221 222 public static class GoodsDetail { 223 @SerializedName("merchant_goods_id") 224 public String merchantGoodsId; 225 226 @SerializedName("wechatpay_goods_id") 227 public String wechatpayGoodsId; 228 229 @SerializedName("goods_name") 230 public String goodsName; 231 232 @SerializedName("quantity") 233 public Long quantity; 234 235 @SerializedName("unit_price") 236 public Long unitPrice; 237 } 238 239 public static class StoreInfo { 240 @SerializedName("id") 241 public String id; 242 243 @SerializedName("name") 244 public String name; 245 246 @SerializedName("area_code") 247 public String areaCode; 248 249 @SerializedName("address") 250 public String address; 251 } 252 253 public static class H5Info { 254 @SerializedName("type") 255 public String type; 256 257 @SerializedName("app_name") 258 public String appName; 259 260 @SerializedName("app_url") 261 public String appUrl; 262 263 @SerializedName("bundle_id") 264 public String bundleId; 265 266 @SerializedName("package_name") 267 public String packageName; 268 } 269 270} 271
需配合微信支付工具库 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 "time" 11) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 15 config, err := wxpay_utility.CreateMchConfig( 16 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 17 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 18 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &DirectApiv3H5PrepayRequest{ 28 Appid: wxpay_utility.String("wxd678efh567hg6787"), 29 Mchid: wxpay_utility.String("1230000109"), 30 Description: wxpay_utility.String("Image形象店-深圳腾大-QQ公仔"), 31 OutTradeNo: wxpay_utility.String("1217752501201407033233368018"), 32 TimeExpire: wxpay_utility.Time(time.Now()), 33 Attach: wxpay_utility.String("自定义数据说明"), 34 NotifyUrl: wxpay_utility.String(" https://www.weixin.qq.com/wxpay/pay.php"), 35 GoodsTag: wxpay_utility.String("WXG"), 36 SupportFapiao: wxpay_utility.Bool(false), 37 Amount: &CommonAmountInfo{ 38 Total: wxpay_utility.Int64(100), 39 Currency: wxpay_utility.String("CNY"), 40 }, 41 Detail: &CouponInfo{ 42 CostPrice: wxpay_utility.Int64(608800), 43 InvoiceId: wxpay_utility.String("微信123"), 44 GoodsDetail: []GoodsDetail{GoodsDetail{ 45 MerchantGoodsId: wxpay_utility.String("1246464644"), 46 WechatpayGoodsId: wxpay_utility.String("1001"), 47 GoodsName: wxpay_utility.String("iPhoneX 256G"), 48 Quantity: wxpay_utility.Int64(1), 49 UnitPrice: wxpay_utility.Int64(528800), 50 }}, 51 }, 52 SceneInfo: &H5ReqSceneInfo{ 53 PayerClientIp: wxpay_utility.String("14.23.150.211"), 54 DeviceId: wxpay_utility.String("013467007045764"), 55 StoreInfo: &StoreInfo{ 56 Id: wxpay_utility.String("0001"), 57 Name: wxpay_utility.String("腾讯大厦分店"), 58 AreaCode: wxpay_utility.String("440305"), 59 Address: wxpay_utility.String("广东省深圳市南山区科技中一道10000号"), 60 }, 61 H5Info: &H5Info{ 62 Type: wxpay_utility.String("iOS"), 63 AppName: wxpay_utility.String("王者荣耀"), 64 AppUrl: wxpay_utility.String("https://pay.qq.com"), 65 BundleId: wxpay_utility.String("com.tencent.wzryiOS"), 66 PackageName: wxpay_utility.String("com.tencent.tmgp.sgame"), 67 }, 68 }, 69 SettleInfo: &SettleInfo{ 70 ProfitSharing: wxpay_utility.Bool(false), 71 }, 72 } 73 74 response, err := H5Prepay(config, request) 75 if err != nil { 76 fmt.Printf("请求失败: %+v\n", err) 77 // TODO: 请求失败,根据状态码执行不同的处理 78 return 79 } 80 81 // TODO: 请求成功,继续业务逻辑 82 fmt.Printf("请求成功: %+v\n", response) 83} 84 85func H5Prepay(config *wxpay_utility.MchConfig, request *DirectApiv3H5PrepayRequest) (response *DirectApiv3H5PrepayResponse, err error) { 86 const ( 87 host = "https://api.mch.weixin.qq.com" 88 method = "POST" 89 path = "/v3/pay/transactions/h5" 90 ) 91 92 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 93 if err != nil { 94 return nil, err 95 } 96 reqBody, err := json.Marshal(request) 97 if err != nil { 98 return nil, err 99 } 100 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 101 if err != nil { 102 return nil, err 103 } 104 httpRequest.Header.Set("Accept", "application/json") 105 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 106 httpRequest.Header.Set("Content-Type", "application/json") 107 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 108 if err != nil { 109 return nil, err 110 } 111 httpRequest.Header.Set("Authorization", authorization) 112 113 client := &http.Client{} 114 httpResponse, err := client.Do(httpRequest) 115 if err != nil { 116 return nil, err 117 } 118 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 119 if err != nil { 120 return nil, err 121 } 122 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 123 // 2XX 成功,验证应答签名 124 err = wxpay_utility.ValidateResponse( 125 config.WechatPayPublicKeyId(), 126 config.WechatPayPublicKey(), 127 &httpResponse.Header, 128 respBody, 129 ) 130 if err != nil { 131 return nil, err 132 } 133 response := &DirectApiv3H5PrepayResponse{} 134 if err := json.Unmarshal(respBody, response); err != nil { 135 return nil, err 136 } 137 138 return response, nil 139 } else { 140 return nil, wxpay_utility.NewApiException( 141 httpResponse.StatusCode, 142 httpResponse.Header, 143 respBody, 144 ) 145 } 146} 147 148type DirectApiv3H5PrepayRequest struct { 149 Appid *string `json:"appid,omitempty"` 150 Mchid *string `json:"mchid,omitempty"` 151 Description *string `json:"description,omitempty"` 152 OutTradeNo *string `json:"out_trade_no,omitempty"` 153 TimeExpire *time.Time `json:"time_expire,omitempty"` 154 Attach *string `json:"attach,omitempty"` 155 NotifyUrl *string `json:"notify_url,omitempty"` 156 GoodsTag *string `json:"goods_tag,omitempty"` 157 SupportFapiao *bool `json:"support_fapiao,omitempty"` 158 Amount *CommonAmountInfo `json:"amount,omitempty"` 159 Detail *CouponInfo `json:"detail,omitempty"` 160 SceneInfo *H5ReqSceneInfo `json:"scene_info,omitempty"` 161 SettleInfo *SettleInfo `json:"settle_info,omitempty"` 162} 163 164type DirectApiv3H5PrepayResponse struct { 165 H5Url *string `json:"h5_url,omitempty"` 166} 167 168type CommonAmountInfo struct { 169 Total *int64 `json:"total,omitempty"` 170 Currency *string `json:"currency,omitempty"` 171} 172 173type CouponInfo struct { 174 CostPrice *int64 `json:"cost_price,omitempty"` 175 InvoiceId *string `json:"invoice_id,omitempty"` 176 GoodsDetail []GoodsDetail `json:"goods_detail,omitempty"` 177} 178 179type H5ReqSceneInfo struct { 180 PayerClientIp *string `json:"payer_client_ip,omitempty"` 181 DeviceId *string `json:"device_id,omitempty"` 182 StoreInfo *StoreInfo `json:"store_info,omitempty"` 183 H5Info *H5Info `json:"h5_info,omitempty"` 184} 185 186type SettleInfo struct { 187 ProfitSharing *bool `json:"profit_sharing,omitempty"` 188} 189 190type GoodsDetail struct { 191 MerchantGoodsId *string `json:"merchant_goods_id,omitempty"` 192 WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"` 193 GoodsName *string `json:"goods_name,omitempty"` 194 Quantity *int64 `json:"quantity,omitempty"` 195 UnitPrice *int64 `json:"unit_price,omitempty"` 196} 197 198type StoreInfo struct { 199 Id *string `json:"id,omitempty"` 200 Name *string `json:"name,omitempty"` 201 AreaCode *string `json:"area_code,omitempty"` 202 Address *string `json:"address,omitempty"` 203} 204 205type H5Info struct { 206 Type *string `json:"type,omitempty"` 207 AppName *string `json:"app_name,omitempty"` 208 AppUrl *string `json:"app_url,omitempty"` 209 BundleId *string `json:"bundle_id,omitempty"` 210 PackageName *string `json:"package_name,omitempty"` 211} 212
应答参数
200 OK
h5_url 必填 string(256)
【支付跳转链接】 h5_url为拉起微信支付收银台的中间页面,商户的H5页面内可通过访问该URL来拉起微信客户端,完成支付,h5_url的有效期为5分钟。超过有效期则需要重新请求下单接口以获取新的h5_url。
应答示例
200 OK
1{ 2 "h5_url" : "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx2016121516420242444321ca0631331346&package=1405458241" 3} 4
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则检查传入的参数 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题排查 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | APPID_MCHID_NOT_MATCH | AppID和mch_id不匹配 | 请确认AppID和mch_id是否匹配,查询指引参考:查询商户号绑定的APPID |
400 | INVALID_REQUEST | 无效请求 | 请根据接口返回的详细信息检查 |
400 | MCH_NOT_EXISTS | 商户号不存在 | 请检查商户号是否正确,商户号获取方式请参考:普通商户模式开发必要参数说明 |
403 | NO_AUTH | 商户无权限 | 请商户前往商户平台申请此接口相关权限,参考:权限申请 |
403 | OUT_TRADE_NO_USED | 商户订单号重复 | 请核实商户订单号是否重复提交,不同的订单需要使用不同的商户订单号 |
403 | RULE_LIMIT | 业务规则限制 | 因业务规则限制请求频率,请查看接口返回的详细信息 |
429 | FREQUENCY_LIMITED | 频率超限 | 请降低请求接口频率 |