|
| 1 | +// Copyright 2021 Tencent Inc. All rights reserved. |
| 2 | +// |
| 3 | +// APP支付 |
| 4 | +// |
| 5 | +// APP支付API |
| 6 | +// |
| 7 | +// API version: 1.2.3 |
| 8 | + |
| 9 | +// Code generated by WechatPay APIv3 Generator based on [OpenAPI |
| 10 | +// Generator](https://openapi-generator.tech); DO NOT EDIT. |
| 11 | + |
| 12 | +package com.wechat.pay.java.service.partnerpayments.applyments; |
| 13 | + |
| 14 | +import com.wechat.pay.java.core.Config; |
| 15 | +import com.wechat.pay.java.core.exception.HttpException; |
| 16 | +import com.wechat.pay.java.core.exception.MalformedMessageException; |
| 17 | +import com.wechat.pay.java.core.exception.ServiceException; |
| 18 | +import com.wechat.pay.java.core.exception.ValidationException; |
| 19 | +import com.wechat.pay.java.core.http.*; |
| 20 | +import com.wechat.pay.java.service.partnerpayments.app.model.*; |
| 21 | +import com.wechat.pay.java.service.partnerpayments.applyments.model.ApplymentsRequest; |
| 22 | +import com.wechat.pay.java.service.partnerpayments.applyments.model.ApplymentsResponse; |
| 23 | + |
| 24 | +import static com.wechat.pay.java.core.http.UrlEncoder.urlEncode; |
| 25 | +import static com.wechat.pay.java.core.util.GsonUtil.toJson; |
| 26 | +import static java.util.Objects.requireNonNull; |
| 27 | + |
| 28 | +/** AppService服务 */ |
| 29 | +public class ApplymentsService { |
| 30 | + |
| 31 | + private final HttpClient httpClient; |
| 32 | + private final HostName hostName; |
| 33 | + |
| 34 | + private ApplymentsService(HttpClient httpClient, HostName hostName) { |
| 35 | + this.httpClient = requireNonNull(httpClient); |
| 36 | + this.hostName = hostName; |
| 37 | + } |
| 38 | + |
| 39 | + /** AppService构造器 */ |
| 40 | + public static class Builder { |
| 41 | + |
| 42 | + private HttpClient httpClient; |
| 43 | + private HostName hostName; |
| 44 | + |
| 45 | + /** |
| 46 | + * 设置请求配置,以该配置构造默认的httpClient,若未调用httpClient()方法,则必须调用该方法 |
| 47 | + * |
| 48 | + * @param config 请求配置 |
| 49 | + * @return Builder |
| 50 | + */ |
| 51 | + public Builder config(Config config) { |
| 52 | + this.httpClient = new DefaultHttpClientBuilder().config(config).build(); |
| 53 | + |
| 54 | + return this; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * 设置微信支付域名,可选,默认为api.mch.weixin.qq.com |
| 59 | + * |
| 60 | + * @param hostName 微信支付域名 |
| 61 | + * @return Builder |
| 62 | + */ |
| 63 | + public Builder hostName(HostName hostName) { |
| 64 | + this.hostName = hostName; |
| 65 | + return this; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * 设置自定义httpClient,若未调用config(),则必须调用该方法 |
| 70 | + * |
| 71 | + * @param httpClient httpClient |
| 72 | + * @return Builder |
| 73 | + */ |
| 74 | + public Builder httpClient(HttpClient httpClient) { |
| 75 | + this.httpClient = httpClient; |
| 76 | + return this; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * 构造服务 |
| 81 | + * |
| 82 | + * @return AppService |
| 83 | + */ |
| 84 | + public ApplymentsService build() { |
| 85 | + return new ApplymentsService(httpClient, hostName); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * 平台收付通(商户进件) |
| 91 | + * 注意部分参数需要加密 |
| 92 | + * |
| 93 | + * @param request 请求参数 |
| 94 | + * @param wechatpaySerial 【微信支付公钥ID】或【微信支付平台证书序列号】请求参数中的敏感字段,需要使用微信支付公钥加密(推荐),请参考获取微信支付公钥ID说明以及微信支付公钥加密敏感信息指引,也可以使用微信支付平台证书公钥加密,参考获取平台证书序列号、平台证书加密敏感信息指引 |
| 95 | + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 |
| 96 | + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 |
| 97 | + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 |
| 98 | + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 |
| 99 | + */ |
| 100 | + public ApplymentsResponse applyments(ApplymentsRequest request,String wechatpaySerial) { |
| 101 | + String requestPath = |
| 102 | + "https://api.mch.weixin.qq.com/v3/ecommerce/applyments/"; |
| 103 | + |
| 104 | + ApplymentsRequest realRequest = request; |
| 105 | + if (this.hostName != null) { |
| 106 | + requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); |
| 107 | + } |
| 108 | + HttpHeaders headers = new HttpHeaders(); |
| 109 | + headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); |
| 110 | + headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); |
| 111 | + headers.addHeader(Constant.WECHAT_PAY_SERIAL, wechatpaySerial); |
| 112 | + HttpRequest httpRequest = |
| 113 | + new HttpRequest.Builder() |
| 114 | + .httpMethod(HttpMethod.POST) |
| 115 | + .url(requestPath) |
| 116 | + .headers(headers) |
| 117 | + .body(createRequestBody(realRequest)) |
| 118 | + .build(); |
| 119 | + httpClient.execute(httpRequest, ApplymentsResponse.class); |
| 120 | + HttpResponse<ApplymentsResponse> httpResponse = |
| 121 | + httpClient.execute(httpRequest, ApplymentsResponse.class); |
| 122 | + return httpResponse.getServiceResponse(); |
| 123 | + } |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + private RequestBody createRequestBody(Object request) { |
| 128 | + return new JsonRequestBody.Builder().body(toJson(request)).build(); |
| 129 | + } |
| 130 | +} |
0 commit comments