九州世界 v1.0版本的 MD5 值为:7e82e48b69a4c36d0bdfb2a8d382d05d
以下内容为反编译后的 MarketingBankPackagesServiceExtension.java 源代码,内容仅作参考
package com.wechat.pay.java.service.marketingbankpackages;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.cipher.PrivacyEncryptor;
import com.wechat.pay.java.core.http.Constant;
import com.wechat.pay.java.core.http.DefaultHttpClientBuilder;
import com.wechat.pay.java.core.http.FileRequestBody;
import com.wechat.pay.java.core.http.HostName;
import com.wechat.pay.java.core.http.HttpClient;
import com.wechat.pay.java.core.http.HttpMethod;
import com.wechat.pay.java.core.http.HttpRequest;
import com.wechat.pay.java.core.http.MediaType;
import com.wechat.pay.java.core.http.UrlEncoder;
import com.wechat.pay.java.core.util.GsonUtil;
import com.wechat.pay.java.core.util.ShaUtil;
import com.wechat.pay.java.service.marketingbankpackages.MarketingBankPackagesService;
import com.wechat.pay.java.service.marketingbankpackages.model.FileMeta;
import com.wechat.pay.java.service.marketingbankpackages.model.ListTaskRequest;
import com.wechat.pay.java.service.marketingbankpackages.model.ListTaskResponse;
import com.wechat.pay.java.service.marketingbankpackages.model.Task;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Objects;
public class MarketingBankPackagesServiceExtension {
private final PrivacyEncryptor encryptor;
private final HttpClient httpClient;
private final MarketingBankPackagesService packagesService;
private MarketingBankPackagesServiceExtension(HttpClient httpClient, HostName hostName, PrivacyEncryptor privacyEncryptor) {
MarketingBankPackagesService.Builder builder = new MarketingBankPackagesService.Builder();
builder.httpClient(httpClient);
if (hostName != null) {
builder.hostName(hostName);
}
this.encryptor = (PrivacyEncryptor) Objects.requireNonNull(privacyEncryptor);
this.httpClient = (HttpClient) Objects.requireNonNull(httpClient);
this.packagesService = builder.build();
}
public static class Builder {
private PrivacyEncryptor encryptor;
private HostName hostName;
private HttpClient httpClient;
public Builder config(Config config) {
this.httpClient = new DefaultHttpClientBuilder().config(config).build();
this.encryptor = config.createEncryptor();
return this;
}
public Builder httpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
public Builder hostName(HostName hostName) {
this.hostName = hostName;
return this;
}
public Builder encryptor(PrivacyEncryptor privacyEncryptor) {
this.encryptor = privacyEncryptor;
return this;
}
public MarketingBankPackagesServiceExtension build() {
return new MarketingBankPackagesServiceExtension(this.httpClient, this.hostName, this.encryptor);
}
}
public ListTaskResponse listTask(ListTaskRequest listTaskRequest) {
return this.packagesService.listTask(listTaskRequest);
}
public Task uploadPackageByFile(String str, String str2, String str3) throws IllegalArgumentException {
File file = new File(str3);
ArrayList<String> arrayList = new ArrayList<>();
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
for (String readLine = bufferedReader.readLine(); readLine != null; readLine = bufferedReader.readLine()) {
arrayList.add(readLine);
}
bufferedReader.close();
return uploadPackage(str, str2, file.getName(), arrayList);
} catch (IOException unused) {
throw new IllegalArgumentException("Upload file, failed to open filePath:" + str3);
}
}
public Task uploadPackage(String str, String str2, String str3, ArrayList<String> arrayList) {
if (arrayList.size() > 5500) {
throw new IllegalArgumentException("Number of lines should not bigger than 5500. fileContentList.size: " + String.valueOf(arrayList.size()));
}
String str4 = "https://api.mch.weixin.qq.com/v3/marketing/bank/packages/" + UrlEncoder.urlEncode(str) + "/tasks";
StringBuilder sb = new StringBuilder();
Iterator<String> it = arrayList.iterator();
while (it.hasNext()) {
sb.append(this.encryptor.encrypt(it.next()));
sb.append("\n");
}
byte[] bytes = sb.toString().getBytes();
String sha256HexString = ShaUtil.getSha256HexString(bytes);
FileMeta fileMeta = new FileMeta();
fileMeta.setFilename(str3);
fileMeta.setSha256(sha256HexString);
fileMeta.setBankType(str2);
return uploadFile(str4, GsonUtil.toJson(fileMeta), str3, bytes);
}
private Task uploadFile(String str, String str2, String str3, byte[] bArr) {
return (Task) this.httpClient.execute(new HttpRequest.Builder().addHeader(Constant.ACCEPT, " */*").addHeader(Constant.WECHAT_PAY_SERIAL, this.encryptor.getWechatpaySerial()).addHeader(Constant.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA.getValue()).httpMethod(HttpMethod.POST).url(str).body(new FileRequestBody.Builder().meta(str2).fileName(str3).file(bArr).build()).build(), Task.class).getServiceResponse();
}
}