CreatePayQrCodeController.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.ygj.yuemum.controller.pay;
  2. import com.ygj.yuemum.component.Constant;
  3. import com.ygj.yuemum.domain.order.YSOrder;
  4. import com.ygj.yuemum.domain.pay.CustomerPay;
  5. import com.ygj.yuemum.domain.pay.PayMents;
  6. import com.ygj.yuemum.service.order.YSOrderService;
  7. import com.ygj.yuemum.service.pay.CustomerPayService;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.models.auth.In;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import sun.misc.BASE64Encoder;
  13. import javax.imageio.ImageIO;
  14. import java.awt.image.BufferedImage;
  15. import java.io.ByteArrayOutputStream;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. @Api(tags = "支付订单相关接口")
  19. @RestController
  20. public class CreatePayQrCodeController {
  21. public static final String RESUMEFILE = Constant.RESUMEFILE;
  22. @Autowired
  23. private CustomerPayService customerPayService;
  24. @Autowired
  25. private YSOrderService ysOrderService;
  26. @RequestMapping(value = "/createPayQrCode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
  27. @ResponseBody
  28. public String createPayQrCode(@RequestBody Map<String,String> params) throws Exception {
  29. String orderNo = params.get("orderNo");
  30. String channel= params.get("channel");
  31. float price= Float.parseFloat(params.get("price"));
  32. float originPrice= Float.parseFloat(params.get("originPrice"));
  33. String title= params.get("title");
  34. String productName= params.get("productName");
  35. Integer productId= Integer.parseInt(params.get("productId"));
  36. String payment_steps = params.get("payment_steps");
  37. String out_trade_no = orderNo + "SEQ" + payment_steps;
  38. //check 本流水号是否已经付过款
  39. CustomerPay customerPay = customerPayService.checkTrade(out_trade_no);
  40. if (customerPay != null) {
  41. //check 订单是否已经支付完成
  42. YSOrder ysOrder = ysOrderService.selectByOdNo(orderNo);
  43. if (ysOrder.getOd_order_pay_amount() == 0) {
  44. return "all";
  45. } else {
  46. out_trade_no = orderNo + "SEQ" + (Integer.parseInt(params.get("payment_steps")) + 1);
  47. }
  48. }
  49. BufferedImage bufferedImage = customerPayService.createPayQrCode(out_trade_no,channel,price,originPrice,title,productName,productId);
  50. //保存一下
  51. // ByteArrayOutputStream os = new ByteArrayOutputStream();
  52. // ImageIO.write(bufferedImage, "jpg", os);
  53. // FileUtils.writeByteArrayToFile(new File(RESUMEFILE+"666.jpg"), os.toByteArray());
  54. // os.close();
  55. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  56. ImageIO.write(bufferedImage, "png", baos);
  57. byte[] bytes = baos.toByteArray();//转换成字节
  58. BASE64Encoder encoder = new BASE64Encoder();
  59. String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串
  60. png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");
  61. System.out.println(png_base64);
  62. Map<String, Object> tableData = new HashMap<>();
  63. tableData.put("img",png_base64);
  64. return png_base64;
  65. }
  66. }