package com.example.xiaoshiweixinback.controller; import com.alibaba.fastjson.JSONObject; import com.example.xiaoshiweixinback.business.common.Constants; import com.example.xiaoshiweixinback.business.common.Response; import com.example.xiaoshiweixinback.business.common.base.Records; import com.example.xiaoshiweixinback.business.utils.JsonUtils; import com.example.xiaoshiweixinback.business.utils.LoginUtils; import com.example.xiaoshiweixinback.entity.weixinPay.*; import com.example.xiaoshiweixinback.service.OrderService; import com.example.xiaoshiweixinback.service.VipService; import com.example.xiaoshiweixinback.service.weixinpay.AuthorizationService; import com.example.xiaoshiweixinback.service.weixinpay.WeixinPayService; import io.swagger.v3.oas.annotations.Operation; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.compress.utils.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.nio.charset.StandardCharsets; @RequestMapping(Constants.XIAOSHI_WEIXINBACK + "/weixinpay") @RestController public class PayController { @Autowired private WeixinPayService weixinPayService; @Autowired private AuthorizationService authorizationService; @Autowired private OrderService orderService; @Operation(summary = "回调成功") @PostMapping("/success") private String success(@RequestBody WeiXinSuccessDTO weiXinSuccessDTO) throws IOException { try { WeiXinSuccessDTO.Resource resource = weiXinSuccessDTO.getResource(); WeixinSuccessVO weixinSuccessVO = authorizationService.decryptMessage(resource.getAssociated_data(), resource.getNonce(), resource.getCiphertext()); String tradeNo = weixinSuccessVO.getOut_trade_no(); orderService.payBack(tradeNo); } catch (Exception e) { return ""; } return "success"; } @Operation(summary = "下单并获取订单信息") @PostMapping("/getPayTickets") private Response getPayTickets(@RequestBody WeiXinPayDTO weiXinPayDTO) { Records records = new Records(); try { GetPayTicketVO getPayTicketVO = weixinPayService.getPayTickets(weiXinPayDTO); records.setData(getPayTicketVO); } catch (Exception e) { e.printStackTrace(); } return Response.success(records); } @Operation(summary = "回调成功") @PostMapping("/testAuthorization") private String testAuthorization() { try { String associatedData = "transaction"; String nonce = "yxul9eBG7PQp"; String ciphertext = "UivUAmQ3r289Wv1q3Hbi7CmnQseCD6EHmuAE1301YMFU41IPkE/98NsTBb7pygTK7dc1Z4AS05sxlHcUMSeJB5KXn7H3l9vfvW538WhoxbbmBqafH9hTUT32A0dUz9LB4Kuw7yqyJl2af70VaZ7O/XDlYR0wAzNFLjsfvJMx0hEIGQQVnuBuCgkZitI5vwvBZN8WIuFdldGqjbRDcCUe7NHVAho2Ph+PRuSbocO7ijtbqoVS8NHfTKVl23bDrHoopuAH/7W6UGX6BD2QMBk4FTm3HmGO0TPmIxrgwIkDz91HyZ3mNmc3A4Fd4p7y7XqOfABGcaSzb0ZY0M2o/gmIDCXS9l3ZY0Rz8D4eo7ddWLeK5hdwWQmVIMqNh+bqt0OEA9KiYFWqfqU9G2DTZbd6r3MYPAAm7NTacu+/iI9mittq0DfsGn66MFGL8WFqMQCpUP9CqsCHQPxnCW80s7m1YJBL5SA8SwogvnIz5FK6bad+own1JCQmuwsmqNkdcnAr48u6OesmUa/OFdOSL+pb1UDaea5O4K/Zp/GhmUFC4JNpreBoZS4SYhs5OTfdgiKV4wEBjrz4"; WeixinSuccessVO weixinSuccessVO = authorizationService.decryptMessage(associatedData, nonce, ciphertext); System.out.println(weixinSuccessVO); return "a"; } catch (Exception e) { e.printStackTrace(); } return "success"; } }