1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package com.ygj.yuemum.controller.pay;
- import com.ygj.yuemum.component.Constant;
- import com.ygj.yuemum.service.pay.CustomerPayService;
- import io.swagger.annotations.Api;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import sun.misc.BASE64Encoder;
- import javax.imageio.ImageIO;
- import java.awt.image.BufferedImage;
- import java.io.ByteArrayOutputStream;
- import java.util.HashMap;
- import java.util.Map;
- @Api(tags = "支付订单相关接口")
- @RestController
- public class CreatePayQrCodeController {
- public static final String RESUMEFILE = Constant.RESUMEFILE;
- @Autowired
- private CustomerPayService customerPayService;
- @RequestMapping(value = "/createPayQrCode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
- @ResponseBody
- public String createPayQrCode(@RequestBody Map<String,String> params) throws Exception {
- String orderNo = params.get("orderNo");
- String channel= params.get("channel");
- float price= Float.parseFloat(params.get("price"));
- float originPrice= Float.parseFloat(params.get("originPrice"));
- String title= params.get("title");
- String productName= params.get("productName");
- Integer productId= Integer.parseInt(params.get("productId"));
- String payment_steps = params.get("payment_steps");
- String out_trade_no = orderNo + "SEQ" + payment_steps;
- BufferedImage bufferedImage = customerPayService.createPayQrCode(out_trade_no,channel,price,originPrice,title,productName,productId);
- //保存一下
- // ByteArrayOutputStream os = new ByteArrayOutputStream();
- // ImageIO.write(bufferedImage, "jpg", os);
- // FileUtils.writeByteArrayToFile(new File(RESUMEFILE+"666.jpg"), os.toByteArray());
- // os.close();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ImageIO.write(bufferedImage, "png", baos);
- byte[] bytes = baos.toByteArray();//转换成字节
- BASE64Encoder encoder = new BASE64Encoder();
- String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串
- png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");
- System.out.println(png_base64);
- Map<String, Object> tableData = new HashMap<>();
- tableData.put("img",png_base64);
- return png_base64;
- }
- }
|