mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨【微信支付】增加商户上传反馈图片API,并修复消费者投诉2.0里查询投诉协商历史的接口问题
This commit is contained in:
parent
f1977f53fd
commit
40f10de24b
@ -67,7 +67,7 @@ public class NegotiationHistoryResult implements Serializable {
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("complaint_media_list")
|
||||
private List<ComplaintDetailResult.ComplaintMedia> complaintMediaList;
|
||||
private List<ComplaintMedia> complaintMediaList;
|
||||
|
||||
@Data
|
||||
public static class ComplaintMedia implements Serializable {
|
||||
@ -97,7 +97,7 @@ public class NegotiationHistoryResult implements Serializable {
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("media_url")
|
||||
private String mediaUrl;
|
||||
private List<String> mediaUrl;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
package com.github.binarywang.wxpay.service;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.complaint.*;
|
||||
import com.github.binarywang.wxpay.bean.media.ImageUploadResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@ -129,4 +133,31 @@ public interface ComplaintService {
|
||||
*/
|
||||
void complete(CompleteRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户上传反馈图片API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_10.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/merchant-service/images/upload
|
||||
* </pre>
|
||||
*
|
||||
* @param imageFile 需要上传的图片文件
|
||||
* @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:BB04A5DEEFEA18D4F2554C1EDD3B610B.bmp
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
ImageUploadResult uploadResponseImage(File imageFile) throws WxPayException, IOException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户上传反馈图片API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_10.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/merchant-service/images/upload
|
||||
* </pre>
|
||||
*
|
||||
* @param inputStream 需要上传的图片文件流
|
||||
* @param fileName 需要上传的图片文件名
|
||||
* @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:BB04A5DEEFEA18D4F2554C1EDD3B610B.bmp
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
ImageUploadResult uploadResponseImage(InputStream inputStream, String fileName) throws WxPayException, IOException;
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,20 @@
|
||||
package com.github.binarywang.wxpay.service.impl;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.complaint.*;
|
||||
import com.github.binarywang.wxpay.bean.media.ImageUploadResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.ComplaintService;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.v3.WechatPayUploadHttpPost;
|
||||
import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -34,7 +39,7 @@ public class ComplaintServiceImpl implements ComplaintService {
|
||||
List<ComplaintDetailResult> data = complaintResult.getData();
|
||||
for (ComplaintDetailResult complaintDetailResult : data) {
|
||||
// 对手机号进行解密操作
|
||||
if(complaintDetailResult.getPayerPhone() != null) {
|
||||
if (complaintDetailResult.getPayerPhone() != null) {
|
||||
String payerPhone = RsaCryptoUtil.decryptOAEP(complaintDetailResult.getPayerPhone(), this.payService.getConfig().getPrivateKey());
|
||||
complaintDetailResult.setPayerPhone(payerPhone);
|
||||
}
|
||||
@ -49,7 +54,7 @@ public class ComplaintServiceImpl implements ComplaintService {
|
||||
String response = this.payService.getV3(url);
|
||||
ComplaintDetailResult result = GSON.fromJson(response, ComplaintDetailResult.class);
|
||||
// 对手机号进行解密操作
|
||||
if(result.getPayerPhone() != null) {
|
||||
if (result.getPayerPhone() != null) {
|
||||
String payerPhone = RsaCryptoUtil.decryptOAEP(result.getPayerPhone(), this.payService.getConfig().getPrivateKey());
|
||||
result.setPayerPhone(payerPhone);
|
||||
}
|
||||
@ -107,4 +112,41 @@ public class ComplaintServiceImpl implements ComplaintService {
|
||||
this.payService.postV3(url, GSON.toJson(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageUploadResult uploadResponseImage(File imageFile) throws WxPayException, IOException {
|
||||
String url = String.format("%s/v3/merchant-service/images/upload", this.payService.getPayBaseUrl());
|
||||
|
||||
try (FileInputStream s1 = new FileInputStream(imageFile)) {
|
||||
String sha256 = DigestUtils.sha256Hex(s1);
|
||||
try (InputStream s2 = new FileInputStream(imageFile)) {
|
||||
WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url))
|
||||
.withImage(imageFile.getName(), sha256, s2)
|
||||
.build();
|
||||
String result = this.payService.postV3(url, request);
|
||||
return ImageUploadResult.fromJson(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageUploadResult uploadResponseImage(InputStream inputStream, String fileName) throws WxPayException, IOException {
|
||||
String url = String.format("%s/v3/merchant-service/images/upload", this.payService.getPayBaseUrl());
|
||||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
|
||||
//文件大小不能超过2M
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = inputStream.read(buffer)) > -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
bos.flush();
|
||||
byte[] data = bos.toByteArray();
|
||||
String sha256 = DigestUtils.sha256Hex(data);
|
||||
WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url))
|
||||
.withImage(fileName, sha256, new ByteArrayInputStream(data))
|
||||
.build();
|
||||
String result = this.payService.postV3(url, request);
|
||||
return ImageUploadResult.fromJson(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.github.binarywang.wxpay.service.impl;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.complaint.*;
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.*;
|
||||
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
||||
import com.github.binarywang.wxpay.bean.media.ImageUploadResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.testbase.ApiTestModule;
|
||||
@ -13,6 +12,8 @@ import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@ -152,4 +153,21 @@ public class ComplaintServiceImplTest {
|
||||
this.payService.getComplaintsService().complete(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户上传反馈图片API
|
||||
* @throws WxPayException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void testUploadResponseImage() throws WxPayException, IOException {
|
||||
String filePath="你的图片文件的路径地址";
|
||||
// String filePath="WxJava/images/banners/wiki.jpg";
|
||||
|
||||
File file = new File(filePath);
|
||||
|
||||
ImageUploadResult imageUploadResult = this.payService.getComplaintsService().uploadResponseImage(file);
|
||||
imageUploadResult.getMediaId();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user