You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							213 lines
						
					
					
						
							10 KiB
						
					
					
				
			
		
		
	
	
							213 lines
						
					
					
						
							10 KiB
						
					
					
				| //package com.ynxbd.wx.servlet.remove;
 | |
| //
 | |
| //import com.alibaba.fastjson.JSON;
 | |
| //import com.ynxbd.api.bean.Pay;
 | |
| //import com.ynxbd.api.bean.Recipe;
 | |
| //import com.ynxbd.api.dao.RecipeDao;
 | |
| //import com.ynxbd.api.dao.his.HisRecipeDao;
 | |
| //import com.ynxbd.api.service.HCodeService;
 | |
| //import com.ynxbd.api.utils.DateGenerate;
 | |
| //import com.ynxbd.common.bean.PayInvoiceResponseBean;
 | |
| //import com.ynxbd.api.bean.User;
 | |
| //import com.ynxbd.api.utils.Global;
 | |
| //import com.ynxbd.api.utils.StrUtil;
 | |
| //import com.ynxbd.api.config.WeChatConfig;
 | |
| //import org.slf4j.Logger;
 | |
| //import org.slf4j.LoggerFactory;
 | |
| //import org.slf4j.MDC;
 | |
| //import weixin.popular.api.PayMchAPI;
 | |
| //import weixin.popular.bean.paymch.Unifiedorder;
 | |
| //import weixin.popular.bean.paymch.UnifiedorderResult;
 | |
| //import weixin.popular.util.PayUtil;
 | |
| //
 | |
| //import javax.servlet.ServletException;
 | |
| //import javax.servlet.annotation.WebServlet;
 | |
| //import javax.servlet.http.HttpServlet;
 | |
| //import javax.servlet.http.HttpServletRequest;
 | |
| //import javax.servlet.http.HttpServletResponse;
 | |
| //import java.io.IOException;
 | |
| //import java.math.BigDecimal;
 | |
| //import java.text.SimpleDateFormat;
 | |
| //import java.util.Date;
 | |
| //import java.util.List;
 | |
| //import java.util.UUID;
 | |
| //import java.util.stream.Collectors;
 | |
| //
 | |
| ///**
 | |
| // * [处方单]支付
 | |
| // *
 | |
| // * @author 张剑峰
 | |
| // * @version v1.0.0
 | |
| // * @Project:微信公众号
 | |
| // * @date 2017年8月8日下午5:02:58
 | |
| // * @Copyright: 2017云南新八达科技有限公司 All rights reserved.
 | |
| // */
 | |
| //@WebServlet("/PayServlet")
 | |
| //public class PayServlet extends HttpServlet {
 | |
| //    private static final Logger logger = LoggerFactory.getLogger(PayServlet.class);
 | |
| //
 | |
| //    @Override
 | |
| //    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 | |
| //        MDC.remove("ip");
 | |
| //        MDC.put("ip", Global.getIpAddr(request));
 | |
| //
 | |
| //        User user = (User) request.getSession().getAttribute("user");
 | |
| //        if (user == null) {
 | |
| //            logger.info("支付信息session获取失败!");
 | |
| //            return;
 | |
| //        }
 | |
| //
 | |
| //        String appID = WeChatConfig.getAppId();
 | |
| //        String mchID = WeChatConfig.getMchId();
 | |
| //        String mchKey = WeChatConfig.getMchKey();
 | |
| //
 | |
| //        // payPackage 的商品信息
 | |
| //        String fee = request.getParameter("fee");
 | |
| //        String way = request.getParameter("way");
 | |
| //
 | |
| //        int payWay = 0;
 | |
| //        try {
 | |
| //            payWay = Integer.parseInt(way == null ? "0" : way);
 | |
| //        } catch (Exception e) {
 | |
| //            e.printStackTrace();
 | |
| //        }
 | |
| //
 | |
| //        String openid = request.getSession().getAttribute("openid").toString();
 | |
| //        String patientId = request.getParameter("patientid");
 | |
| //        String treatNum = request.getParameter("mznum");
 | |
| //
 | |
| ////        String recipeid = request.getParameter("recipeid");
 | |
| ////        String detail = request.getParameter("detail") == null ? "" : request.getParameter("detail");
 | |
| //        String recipeIdJson = request.getParameter("json") == null ? "" : request.getParameter("json");
 | |
| //        logger.info(String.format("支付json={%s}", recipeIdJson));
 | |
| //
 | |
| //        List<Recipe> recipeList = JSON.parseArray(recipeIdJson, Recipe.class); //  "[{\"id\":\"1024616201\",\"fee\":52},{\"id\":\"1024616204\",\"fee\":1200},{\"id\":\"1024616205\",\"fee\":482},{\"id\":\"1024616206\",\"fee\":5.25},{\"id\":\"1024616355\",\"fee\":24},{\"id\":\"1024616356\",\"fee\":35}]";
 | |
| //        List<String> recipeIds = recipeList.stream().map(Recipe::getId).distinct().collect(Collectors.toList());
 | |
| //
 | |
| //        RecipeDao recipeDao = new RecipeDao();
 | |
| //
 | |
| //        if ("0".equals(fee)) {
 | |
| //            String tradeNo = StrUtil.genTradeNo();
 | |
| //            Pay savePay;
 | |
| //            for (Recipe recipeDetail : recipeList) {
 | |
| //                savePay = new Pay();
 | |
| //                savePay.setOpenid(openid);
 | |
| //                savePay.setPatientId(patientId);
 | |
| //                savePay.setTreatNum(treatNum);
 | |
| //                savePay.setoutTradeNo(tradeNo);
 | |
| //                savePay.setPayWay(payWay);
 | |
| //                savePay.setPayMoney(new BigDecimal(recipeDetail.getFee()));
 | |
| //
 | |
| //                savePay.setRecipeId(recipeDetail.getId());
 | |
| //                savePay.setRecipeJson(recipeIdJson);
 | |
| //                savePay.setTradeNo(UUID.randomUUID().toString().replace("-", "")); // 本次his交易流水号);
 | |
| //                recipeDao.insertPay(savePay);
 | |
| //            }
 | |
| //            recipeDao.updatePayAfterNotify(tradeNo, tradeNo);
 | |
| //
 | |
| //
 | |
| //            List<Pay> lstPayBean = new RecipeDao().selectListByOutTradeNo(tradeNo);
 | |
| //            Date day = new Date();
 | |
| //            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 | |
| //            String payTime = df.format(day);
 | |
| //            List<String> lstDate = DateGenerate.getDateAndTime(payTime);
 | |
| //            for (Pay pay : lstPayBean) {
 | |
| //                BigDecimal payMoney = pay.getPayMoney();
 | |
| //                if (payMoney == null) {
 | |
| //                    logger.info("调用his缴费,处方金额为null,跳过处方号:" + pay.getRecipeId());
 | |
| //                    continue;
 | |
| //                }
 | |
| //
 | |
| //                String recipeId = pay.getRecipeId();
 | |
| //
 | |
| //                // HIS缴费
 | |
| //                recipeIds.clear();
 | |
| //                recipeIds.add(recipeId);
 | |
| //                PayInvoiceResponseBean payInvoiceResponseBean = new HisRecipeDao().old_payInvoice(pay.getPatientId(), pay.getTreatNum(),
 | |
| //                        recipeIds, "0", lstDate.get(0), lstDate.get(1),
 | |
| //                        pay.getTradeNo(), "app", tradeNo);
 | |
| //
 | |
| //                if (payInvoiceResponseBean.getResponseCode().equals("0")) {
 | |
| //                    // 更新支付信息
 | |
| //                    logger.info("his缴费成功,更新支付信息:hisTransNo={}", payInvoiceResponseBean.getHISTransNo());
 | |
| //                    pay.setHisTransNo(payInvoiceResponseBean.getHISTransNo());
 | |
| //                    pay.setInvoiceTransNo(payInvoiceResponseBean.getInvoiceTransNo());
 | |
| //                    pay.setBankTransNo(tradeNo);
 | |
| //                    recipeDao.updatePayInfoSingle(pay.getoutTradeNo(), pay.getHisTransNo(), pay.getInvoiceTransNo(), pay.getRecipeId());
 | |
| //
 | |
| //                    // 健康卡数据上报
 | |
| //                    if (pay.getPayWay() == 0) {
 | |
| //                        HCodeService.payNotifyReportHISData(pay.getOpenid(), pay.getPatientId());
 | |
| //                    }
 | |
| //                } else if (payInvoiceResponseBean.getResponseCode().equals("-1")) {
 | |
| //                    recipeDao.updatePayAfterFailSingle(tradeNo, payInvoiceResponseBean.getResponseMessage(), pay.getRecipeId());
 | |
| //                    logger.info("HIS缴费失败,0支付,不退款,HIS返回:" + payInvoiceResponseBean.getResponseCode() + ","
 | |
| //                            + payInvoiceResponseBean.getResponseMessage());
 | |
| //                }
 | |
| //            }
 | |
| //            request.getRequestDispatcher("pay-info.html").forward(request, response);
 | |
| //        } else {
 | |
| //            Unifiedorder unifiedorder = new Unifiedorder();
 | |
| //            unifiedorder.setAppid(appID);
 | |
| //            unifiedorder.setMch_id(mchID);
 | |
| //            unifiedorder.setNonce_str(UUID.randomUUID().toString().replace("-", ""));
 | |
| //            unifiedorder.setOpenid(user.getOpenid());
 | |
| //            unifiedorder.setBody("PID:" + patientId + " 门诊号:" + treatNum + " 诊间支付");
 | |
| //            unifiedorder.setOut_trade_no(StrUtil.genTradeNo());
 | |
| //
 | |
| //            // 此处使用Float或者Double转换金额会因为精度问题丢失1分钱,使用BigDecimal来转换
 | |
| //            /* int fFee = (int)(Float.valueOf(fee) * 100); */
 | |
| //            BigDecimal v1 = new BigDecimal(fee);
 | |
| //            BigDecimal v2 = new BigDecimal("100");
 | |
| //            double b = v1.multiply(v2).doubleValue();
 | |
| //            int fFee = (int) b;
 | |
| //
 | |
| //            unifiedorder.setTotal_fee(String.valueOf(fFee));
 | |
| //            unifiedorder.setSpbill_create_ip(request.getRemoteAddr());
 | |
| //            unifiedorder.setNotify_url(WeChatConfig.getBaseURL() + "PayNotifyServlet");
 | |
| //            unifiedorder.setTrade_type("JSAPI");
 | |
| //
 | |
| //            logger.info(unifiedorder.getAppid() + "," + unifiedorder.getMch_id() + "," + unifiedorder.getNonce_str() + ","
 | |
| //                    + unifiedorder.getBody() + "," + unifiedorder.getOut_trade_no() + "," + unifiedorder.getTotal_fee()
 | |
| //                    + "," + unifiedorder.getSpbill_create_ip() + "," + unifiedorder.getNotify_url() + ","
 | |
| //                    + unifiedorder.getTrade_type());
 | |
| //
 | |
| //            // 调用支付
 | |
| //            UnifiedorderResult unifiedorderResult = PayMchAPI.payUnifiedorder(unifiedorder, mchKey);
 | |
| //
 | |
| //            if (unifiedorderResult.getSign_status() != null && unifiedorderResult.getSign_status()) {
 | |
| //                String outTradeNo = unifiedorder.getOut_trade_no();
 | |
| //                String json = PayUtil.generateMchPayJsRequestJson(unifiedorderResult.getPrepay_id(), appID, mchKey);
 | |
| //
 | |
| //                Pay savePayInfo;
 | |
| //                for (Recipe recipeItem : recipeList) {
 | |
| //                    savePayInfo = new Pay();
 | |
| //                    savePayInfo.setOpenid(openid);
 | |
| //                    savePayInfo.setPatientId(patientId);
 | |
| //                    savePayInfo.setTreatNum(treatNum);
 | |
| //                    savePayInfo.setoutTradeNo(outTradeNo);
 | |
| //                    savePayInfo.setPayWay(payWay);
 | |
| //                    savePayInfo.setPayMoney(new BigDecimal(recipeItem.getFee()));
 | |
| //                    savePayInfo.setRecipeId(recipeItem.getId());
 | |
| //                    savePayInfo.setRecipeJson(recipeIdJson);
 | |
| //                    savePayInfo.setTradeNo(UUID.randomUUID().toString().replace("-", "")); // 本次his交易流水号);
 | |
| //                    recipeDao.insertPay(savePayInfo);
 | |
| //                }
 | |
| //
 | |
| //                request.setAttribute("json", json);
 | |
| //                request.setAttribute("tradeno", outTradeNo);
 | |
| //
 | |
| //                logger.info("savePayInfo,trade_no=" + outTradeNo + ",json=" + json);
 | |
| //                request.getRequestDispatcher("pay.jsp").forward(request, response);
 | |
| //            } else {
 | |
| //                logger.info("统一下单返回:" + unifiedorderResult.getSign_status() + "err_code=" + unifiedorderResult.getErr_code() + ",err_des=" + unifiedorderResult.getErr_code_des());
 | |
| //            }
 | |
| //        }
 | |
| //    }
 | |
| //
 | |
| //
 | |
| //    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 | |
| //        doPost(request, response);
 | |
| //    }
 | |
| //
 | |
| //}
 | |
| 
 |