微信后端代码
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.

131 lines
6.4 KiB

//package com.ynxbd.wx.servlet;
//
//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.util.UUID;
//
///**
// * @author 张剑峰
// * @version v1.0.0
// * @Project:微信公众号
// * @date 2018年6月4日上午10:44:31
// * @Copyright: 2018云南新八达科技有限公司 All rights reserved.
// */
//@WebServlet("/qr")
//public class QRPayUrlServlet extends HttpServlet {
// private static final Logger log = LoggerFactory.getLogger(QRPayUrlServlet.class);
//
// @Override
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// MDC.remove("ip");
// MDC.put("ip", Global.getIpAddr(request));
//
//
// log.info("收到扫码支付请求2,开始解析...");
//
// String appID = WeChatConfig.getAppId();
// String mchID = WeChatConfig.getMchId();
// String mchKey = WeChatConfig.getMchKey();
//
// String patientId = request.getSession().getAttribute("p1") == null ? "" : request.getSession().getAttribute("p1").toString();
// String mzNum = request.getSession().getAttribute("p2") == null ? "" : request.getSession().getAttribute("p2").toString();
// String recipeId = request.getSession().getAttribute("p3") == null ? "" : request.getSession().getAttribute("p3").toString();
// String fee = request.getSession().getAttribute("p4") == null ? "" : request.getSession().getAttribute("p4").toString();
// String flag = request.getSession().getAttribute("p5") == null ? "" : request.getSession().getAttribute("p5").toString();
//
// if (patientId.equals("") || mzNum.equals("") || recipeId.equals("") || fee.equals("")) {
// log.info(String.format("扫码请求参数无效, patientid=%s,mznum=%s,recipeId=%s,fee=%s", patientId, mzNum, recipeId,
// fee));
// return;
// }
//
// String recipeIds = "[{\"id\":" + recipeId + "}]";
// String recipeIds2 = "[{\"id\":" + "\"" + recipeId + "\"" + "}]";
//
// // 是否重复扫码
// // DBDao dbDao = new DBDao();
// // logger.info("判断是否支付过:" + patientId + "," + mzNum + "," + recipeIds +
// // "," + recipeIds2);
// // if (dbDao.hasPaid(patientId, mzNum, recipeIds, recipeIds2)) {
// // logger.info(String.format("付款码已支付过,失效,失效参数无效,
// // patientid=%s,mznum=%s,recipeId=%s,fee=%s", patientId, mzNum,
// // recipeId, fee));
// // ObjMake.sendMessage(response, "付款码已支付过,失效");
// // return;
// // }
//
// BigDecimal v1 = new BigDecimal(fee);
// BigDecimal v2 = new BigDecimal("100");
// double b = v1.multiply(v2).doubleValue();
// int fFee = (int) b;
//
// // 统一下单
// Unifiedorder unifiedorder = new Unifiedorder();
// unifiedorder.setAppid(WeChatConfig.getAppId());
// unifiedorder.setMch_id(WeChatConfig.getMchId());
// unifiedorder.setNonce_str(UUID.randomUUID().toString().replace("-", ""));
// unifiedorder.setOpenid(request.getSession().getAttribute("openid").toString());
// unifiedorder.setBody("ID:" + patientId + " 扫码支付测试");
// // unifiedorder.setBody("pre-registration");
// unifiedorder.setOut_trade_no(StrUtil.genTradeNo());
// unifiedorder.setTotal_fee(String.valueOf(fFee));// 单位分
// unifiedorder.setSpbill_create_ip("127.0.0.1");// IP
// unifiedorder.setNotify_url(WeChatConfig.getBaseURL() + "PayNotifyServlet");
// unifiedorder.setTrade_type("JSAPI");// JSAPI,NATIVE,APP,MWEB
//
// UnifiedorderResult unifiedorderResult = PayMchAPI.payUnifiedorder(unifiedorder, mchKey);
//
// if (unifiedorderResult.getSign_status() != null && unifiedorderResult.getSign_status()) {
// /*
// * PayBean payBean = new PayBean(); payBean.setMZNum(mzNum);
// * payBean.setOpendID(""); // 获取不到openid
// * payBean.setPatientID(patientId); payBean.setPayMoney(fee);
// * payBean.setRecipeID(recipeId);
// * payBean.setTradeNo(unifiedorder.getOut_trade_no());
// * payBean.setPayWay(1);
// *
// * dbDao.savePayInfo(payBean);
// *
// * MchPayNativeReply reply = new MchPayNativeReply();
// * reply.setAppid(appID); reply.setMch_id(mchID);
// * reply.setNonce_str(UUID.randomUUID().toString().replace("-",
// * "")); reply.setPrepay_id(unifiedorderResult.getPrepay_id());
// * reply.setResult_code("SUCCESS"); reply.setReturn_code("SUCCESS");
// * String string = PayUtil.generateMchPayNativeReplyXML(reply,
// * mchKey); response.getWriter().write(string);
// */
// String json = PayUtil.generateMchPayJsRequestJson(unifiedorderResult.getPrepay_id(), appID, mchKey);
// // 记录交易流水号
// // reservation.setTradeNo(unifiedorder.getOut_trade_no());
// // DBDao dbDao = new DBDao();
// // dbDao.updateReservationAfterUnified(reservation);
// // 将json 传到jsp 页面
// request.setAttribute("json", json);
// request.setAttribute("tradeno", unifiedorder.getOut_trade_no());
// log.info("支付返回的tradeno:" + unifiedorder.getOut_trade_no());
// request.getRequestDispatcher("reservation-pay.jsp").forward(request, response);
// }
// }
//
// protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// doPost(request, response);
// }
//
//}