package com.ruoyi.other;
|
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.other.RuoYiOtherApplication;
|
import com.ruoyi.other.util.MyQrCodeUtil;
|
import com.ruoyi.other.util.ObsUploadUtil;
|
import com.ruoyi.other.util.QRCodeUtil;
|
import com.ruoyi.other.util.UUIDUtil;
|
import com.ruoyi.other.util.payment.wx.WechatPayService;
|
import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
|
import org.junit.jupiter.api.Test;
|
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import javax.imageio.ImageIO;
|
import java.awt.image.BufferedImage;
|
import java.io.IOException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.Map;
|
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RuoYiOtherApplication.class)
|
public class RuoYiOtherApplicationTests {
|
@Resource
|
private WechatPayService wechatPayService;
|
@Test
|
public void contextLoads() throws Exception {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
|
Map<String,String> r = wechatPayService.unifiedOrder(code, "0.01", "积分充值", "/other/wx/integralCallback");
|
System.err.println(r);
|
String codeUrl = r.get("code_url");
|
MyQrCodeUtil.createCodeToFile(codeUrl);
|
BufferedImage blueImage = QRCodeUtil.createImage(codeUrl);
|
MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG");
|
String s = ObsUploadUtil.obsUpload(blueFile);
|
System.err.println(s);
|
|
}
|
public static MultipartFile convert(BufferedImage bufferedImage, String fileName) throws IOException {
|
// 将 BufferedImage 转换为字节数组
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ImageIO.write(bufferedImage, "png", baos);
|
byte[] bytes = baos.toByteArray();
|
|
// 创建 ByteArrayResource
|
ByteArrayResource resource = new ByteArrayResource(bytes);
|
|
// 创建 MockMultipartFile
|
MockMultipartFile multipartFile = new MockMultipartFile(
|
"file",
|
fileName,
|
"image/png",
|
resource.getInputStream()
|
);
|
|
return multipartFile;
|
}
|
}
|