101captain
2022-01-06 569b085b71c54aa7675b71df6995147c066d0158
商业街代码提交
3个文件已修改
82 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/entity/McsOrder.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/resources/mapper/McsOrderMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/McsOrderApi.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/entity/McsOrder.java
@@ -90,4 +90,5 @@
    private Date createTime;
    private String merchantName;
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/resources/mapper/McsOrderMapper.xml
@@ -43,8 +43,8 @@
        where t.id =#{id}
    </select>
    <select id="selectPhone" >
        select t1.phone from mcs_order t on t.merchant_id = t1.id where t.id=#{id}
    <select id="selectPhone" resultType="string">
        select t1.phone from mcs_order t left join mcs_merchant t1 on t.merchant_id = t1.id where t.id=#{id}
    </select>
</mapper>
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/McsOrderApi.java
@@ -1,17 +1,27 @@
package com.panzhihua.shop_backstage.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.common.model.dtos.shop.WxPayNotifyOrderDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.microCommercialStreet.McsOrderVO;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.common.utlis.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.XML;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
 * 商业街订单表(McsOrder)表控制层
@@ -98,16 +108,73 @@
    public R sendContent(@RequestParam("id") Long id){
        return communityService.sendContentMcsOrder(id);
    }
    /**
     *微信支付回调
     * @param mcsOrderVO
     * @param
     * @return
     */
    @ApiOperation("微信支付回调")
    @PostMapping("/notify")
    public R notify(@RequestBody McsOrderVO mcsOrderVO){
        return communityService.notifyMcsOrder(mcsOrderVO);
    @PostMapping("wxNotify")
    public void payCallback(HttpServletRequest request, HttpServletResponse response) {
        String inputLine = "";
        String notityXml = "";
        try {
            while ((inputLine = request.getReader().readLine()) != null) {
                notityXml += inputLine;
            }
            // 关闭流
            request.getReader().close();
            // 解析成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")) {
                    McsOrderVO mcsOrderVO = new McsOrderVO();
                    // 订单号
                    String orderTradeNo = resultData.getString("out_trade_no");
                    mcsOrderVO.setOrderNo(orderTradeNo);
                    // 微信支付订单号
                    String wxTradeNo = resultData.getString("transaction_id");
                    mcsOrderVO.setPayNo(wxTradeNo);
                    // 支付完成时间
                    String payTime = resultData.getString("time_end");
                    mcsOrderVO.setPayTime(DateUtils.stringToDate(payTime,DateUtils.ymdhms_format));
                    // 现金支付金额
                    mcsOrderVO.setStatus(1);
                    // 根据订单号修改订单信息
                    communityService.notifyMcsOrder(mcsOrderVO);
                    // 封装 返回值
                    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();
        }
    }
}