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.
120 lines
5.6 KiB
120 lines
5.6 KiB
//package com.ynxbd.wx.servlet;
|
|
//
|
|
//import com.ynxbd.common.bean.PayBean;
|
|
//import com.ynxbd.common.dao.DBDao;
|
|
//import com.ynxbd.api.bean.User;
|
|
//import com.ynxbd.api.utils.StrUtil;
|
|
//import com.ynxbd.api.config.WeChatConfig;
|
|
//import net.sf.json.JSONArray;
|
|
//import org.apache.log4j.Logger;
|
|
//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.http.HttpServlet;
|
|
//import javax.servlet.http.HttpServletRequest;
|
|
//import javax.servlet.http.HttpServletResponse;
|
|
//import java.io.IOException;
|
|
//import java.math.BigDecimal;
|
|
//import java.util.ArrayList;
|
|
//import java.util.List;
|
|
//import java.util.UUID;
|
|
//
|
|
///**
|
|
// * @author 张剑峰
|
|
// * @version v1.0.0
|
|
// * @Project:微信公众号
|
|
// * @date 2017年8月8日下午5:02:58
|
|
// * @Copyright: 2017云南新八达科技有限公司 All rights reserved.
|
|
// */
|
|
//public class PayTest extends HttpServlet {
|
|
//
|
|
// private final static Logger log = Logger.getLogger(PayTest.class);
|
|
//
|
|
// @Override
|
|
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
// User user = (User) request.getSession().getAttribute("user");
|
|
// if (user == null) {
|
|
// log.info("支付信息session获取失败!");
|
|
// return;
|
|
// }
|
|
//
|
|
// String appID = WeChatConfig.getAppId();
|
|
// String mchID = WeChatConfig.getMchId();
|
|
// String mchKey = WeChatConfig.getMchKey();
|
|
//
|
|
// // payPackage 的商品信息
|
|
// String fee = request.getParameter("fee");
|
|
// String patientid = request.getParameter("patientid");
|
|
// String mznum = request.getParameter("mznum");
|
|
// String recipeid = request.getParameter("recipeid");
|
|
// String recipeids = "";
|
|
// JSONArray jobj = JSONArray.fromObject(recipeid);
|
|
// List<String> lstRecipeId = new ArrayList<>();
|
|
// for (int i = 0; i < jobj.size(); i++) {
|
|
// net.sf.json.JSONObject obj = jobj.getJSONObject(i);
|
|
// lstRecipeId.add(obj.get("id").toString());
|
|
// recipeids = recipeid + obj.get("id").toString() + ";";
|
|
// }
|
|
// Unifiedorder unifiedorder = new Unifiedorder();
|
|
// unifiedorder.setAppid(appID);
|
|
// unifiedorder.setMch_id(mchID);
|
|
// unifiedorder.setNonce_str(UUID.randomUUID().toString().replace("-", ""));
|
|
// unifiedorder.setOpenid(user.getOpenid());
|
|
// unifiedorder.setBody("ID:" + patientid + " 诊间支付");
|
|
// // unifiedorder.setBody("pay");
|
|
// 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;
|
|
// // log.info("patientid:" + patientid + " mznum:" + mznum + " recipeid:"
|
|
// // + recipeid + " 实际支付:" + fFee + " 分");
|
|
//
|
|
// unifiedorder.setTotal_fee(String.valueOf(fFee));
|
|
// unifiedorder.setSpbill_create_ip(request.getRemoteAddr());
|
|
// unifiedorder.setNotify_url(WeChatConfig.getBaseURL() + "PayNotifyServlet");
|
|
// unifiedorder.setTrade_type("JSAPI");
|
|
//
|
|
// log.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()) {
|
|
// // log.info("Prepay_id:" + unifiedorderResult.getPrepay_id() + ",
|
|
// // appid:" + unifiedorderResult.getAppid());
|
|
// String json = PayUtil.generateMchPayJsRequestJson(unifiedorderResult.getPrepay_id(), appID, mchKey);
|
|
// PayBean payBean = new PayBean();
|
|
// payBean.setMZNum(mznum);
|
|
// payBean.setOpendID(request.getSession().getAttribute("openid").toString());
|
|
// payBean.setPatientID(patientid);
|
|
// payBean.setPayMoney(fee);
|
|
// payBean.setRecipeID(recipeid);
|
|
// payBean.setTradeNo(unifiedorder.getOut_trade_no());
|
|
// payBean.setPayWay(0);
|
|
// DBDao dbDao = new DBDao();
|
|
// // 统一下单后,预生成订单
|
|
// dbDao.savePayInfo(payBean);
|
|
// request.setAttribute("json", json);
|
|
// request.setAttribute("tradeno", unifiedorder.getOut_trade_no());
|
|
// log.info("savePayInfo,tradeno=" + unifiedorder.getOut_trade_no() + ",json=" + json);
|
|
// request.getRequestDispatcher("pay.jsp").forward(request, response);
|
|
// } else {
|
|
// log.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);
|
|
// }
|
|
//
|
|
//}
|
|
|