yanghui
2022-11-17 b30e1a48f2bc5f65a0efd2e69e090fed2d7a627c
springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxCallbackApi.java
@@ -21,9 +21,8 @@
import io.swagger.annotations.ApiOperation;
import com.panzhihua.common.service.community.ComBatteryCommodityOrderFeign;
import org.json.XML;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@@ -61,7 +60,7 @@
    @PostMapping("wxNotify")
    public void payCallback(HttpServletRequest request, HttpServletResponse response) {
        log.info("微信支付回调start");
        log.error("微信支付回调start");
        String inputLine = "";
        String notityXml = "";
        try {
@@ -70,7 +69,7 @@
            }
            // 关闭流
            request.getReader().close();
            log.info("微信回调内容信息:" + notityXml);
            log.error("微信回调内容信息:" + notityXml);
            // 解析成Json
            org.json.JSONObject xmlJson = XML.toJSONObject(notityXml);
            if (StringUtils.isNotEmpty(xmlJson.toString())) {
@@ -187,6 +186,21 @@
            String desString=MyAESUtil.Decrypt(aesMap.get("aesString"),"Ryo7M3n8loC5Abcd");
            Map<String,String> desMap= (Map) JSON.parse(desString);
            return userService.uuPush(desMap.get("washer_mobile"),desMap.get("phone"),desMap.get("washer_name"),Integer.parseInt(desMap.get("order_status")));
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail("推送失败");
        }
    }
    @ApiOperation("ws洗车推送")
    @PostMapping("/wsPush")
    public R wsPush(@RequestBody String aesString){
        try {
            Map<String, String> aesMap= (Map<String, String>) JSON.parse(aesString);
            String desString=MyAESUtil.Decrypt(aesMap.get("aesString"),"Ryo7M3n8loC5Abcd");
            Map<String,String> desMap= (Map) JSON.parse(desString);
            return userService.wsPush(desMap.get("washer_mobile"),desMap.get("phone"),desMap.get("washer_name"),Integer.parseInt(desMap.get("order_status")));
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail("推送失败");
@@ -329,4 +343,79 @@
        buffer.append("</xml>");
        return buffer.toString();
    }
    @GetMapping("/settle")
    public R settle(String settleDate){
        return R.ok(umfPayUtil.settle(settleDate));
    }
    @PostMapping("flowerWxNotify")
    public void flowerWxNotify(HttpServletRequest request, HttpServletResponse response) {
        log.error("微信支付回调start");
        String inputLine = "";
        String notityXml = "";
        try {
            while ((inputLine = request.getReader().readLine()) != null) {
                notityXml += inputLine;
            }
            // 关闭流
            request.getReader().close();
            log.error("微信回调内容信息:" + notityXml);
            // 解析成Json
            org.json.JSONObject xmlJson = XML.toJSONObject(notityXml);
            if (StringUtils.isNotEmpty(xmlJson.toString())) {
                JSONObject resultData = JSON.parseObject(xmlJson.get("xml").toString());
                // 成功支付订单
                if (resultData.getString("result_code").equals("SUCCESS")
                        && resultData.getString("return_code").equals("SUCCESS")) {
                    WxPayNotifyOrderDTO notifyOrderDTO = new WxPayNotifyOrderDTO();
                    // 订单号
                    String orderTradeNo = resultData.getString("out_trade_no");
                    notifyOrderDTO.setOrderTradeNo(orderTradeNo);
                    // 微信支付订单号
                    String wxTradeNo = resultData.getString("transaction_id");
                    notifyOrderDTO.setWxTradeNo(wxTradeNo);
                    // 订单金额
                    String totalFee = resultData.getString("total_fee");
                    notifyOrderDTO.setTotalFee(totalFee);
                    // 支付完成时间
                    String payTime = resultData.getString("time_end");
                    notifyOrderDTO.setPayTime(payTime);
                    // 现金支付金额
                    String cashFee = resultData.getString("cash_fee");
                    notifyOrderDTO.setCashFee(cashFee);
                    // 根据订单号修改订单信息
                    communityService.wxOrderPayNotify(notifyOrderDTO);
                    // 封装 返回值
                    StringBuffer buffer = new StringBuffer();
                    buffer.append("<xml>");
                    buffer.append("<return_code>SUCCESS</return_code>");
                    buffer.append("<return_msg>OK</return_msg>");
                    buffer.append("</xml>");
                    // 给微信服务器返回 成功标示 否则会一直询问 咱们服务器 是否回调成功
                    PrintWriter writer = response.getWriter();
                    // 返回
                    writer.print(buffer.toString());
                } else {// 未成功支付订单
                    // 封装 返回值
                    StringBuffer buffer = new StringBuffer();
                    buffer.append("<xml>");
                    buffer.append("<return_code>FAIL</return_code>");
                    buffer.append("<return_msg>FAIL</return_msg>");
                    buffer.append("</xml>");
                    // 给微信服务器返回 成功标示 否则会一直询问 咱们服务器 是否回调成功
                    PrintWriter writer = response.getWriter();
                    // 返回
                    writer.print(buffer.toString());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}