Search in sources :

Example 16 with OnPayInfo

use of com.itrus.portal.db.OnPayInfo in project portal by ixinportal.

the class PayExtraBillWebController method generatePayInfo.

private void generatePayInfo(Long userId, String orderNo, String payid, String money) throws Exception {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus s = transactionManager.getTransaction(def);
    try {
        ExtraBill bill = extraBillService.getExtraBillByBillId(orderNo);
        OnPayInfo payInfo;
        if (bill.getOnPayInfo() == null) {
            payInfo = new OnPayInfo();
            payInfo.setOnlinePay(Long.parseLong(payid));
            payInfo.setPaySum(Double.parseDouble(money));
            payInfo.setPayStatus(0);
            payInfo.setDyTime(new Date());
            payInfo.setName(String.valueOf(userId));
            sqlSession.insert("com.itrus.portal.db.OnPayInfoMapper.insert", payInfo);
            sqlSession.flushStatements();
            if (payInfo.getId() == null) {
                throw new Exception(orderNo + "生成支付记录报错。");
            }
            bill.setOnPayInfo(payInfo.getId());
            extraBillService.updateByPrimaryKeySelective(bill);
        } else {
            payInfo = sqlSession.selectOne("com.itrus.portal.db.OnPayInfoMapper.selectByPrimaryKey", bill.getOnPayInfo());
            payInfo.setOnlinePay(Long.parseLong(payid));
            payInfo.setPaySum(Double.parseDouble(money));
            payInfo.setDyTime(new Date());
            payInfo.setName(String.valueOf(userId));
            sqlSession.update("com.itrus.portal.db.OnPayInfoMapper.updateByPrimaryKeySelective", payInfo);
        }
        transactionManager.commit(s);
    } catch (Exception e) {
        LogUtil.syslog(sqlSession, "在线支付_增值订单", orderNo + "在线支付生成支付记录错误:" + e.toString());
        throw new Exception(orderNo + "在线支付_增值订单生成支付记录错误:" + e.toString());
    } finally {
        if (!s.isCompleted()) {
            transactionManager.rollback(s);
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OnPayInfo(com.itrus.portal.db.OnPayInfo) ExtraBill(com.itrus.portal.db.ExtraBill) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date)

Example 17 with OnPayInfo

use of com.itrus.portal.db.OnPayInfo in project portal by ixinportal.

the class PayExtraBillWebController method updatePayInfo.

private void updatePayInfo(String billId, Long payConfigId, String transactionId, String payType, String payTime) throws Exception {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus s = null;
    try {
        s = transactionManager.getTransaction(def);
        ExtraBill bill = extraBillService.getExtraBillByBillId(billId);
        if (null == bill) {
            return;
        }
        bill.setBillStatus(ComNames.EXTRA_BILL_STATUS_3);
        bill.setPayTime(new Date(Long.parseLong(payTime)));
        extraBillService.updateByPrimaryKeySelective(bill);
        OnPayInfo payInfo = sqlSession.selectOne("com.itrus.portal.db.OnPayInfoMapper.selectByPrimaryKey", bill.getOnPayInfo());
        payInfo.setPayStatus(1);
        payInfo.setWcTime(bill.getPayTime());
        payInfo.setPayNo(transactionId);
        OnlinePayExample ope = new OnlinePayExample();
        OnlinePayExample.Criteria opc = ope.createCriteria();
        opc.andPayConfigEqualTo(payConfigId);
        // 1支付宝
        opc.andWayEqualTo((Integer.parseInt(payType) == 0 ? 1 : 2));
        // 2微信
        OnlinePay onlinePay = sqlSession.selectOne("com.itrus.portal.db.OnlinePayMapper.selectByExample", ope);
        payInfo.setOnlinePay(onlinePay.getId());
        sqlSession.update("com.itrus.portal.db.OnPayInfoMapper.updateByPrimaryKeySelective", payInfo);
        transactionManager.commit(s);
    } catch (Exception e) {
        LogUtil.syslog(sqlSession, "在线支付_增值订单", billId + "回调更新数据库错误:" + e.toString());
        throw new Exception(billId + "回调增值订单更新数据库错误:" + e.toString());
    } finally {
        if (null != s && !s.isCompleted()) {
            transactionManager.rollback(s);
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OnPayInfo(com.itrus.portal.db.OnPayInfo) OnlinePayExample(com.itrus.portal.db.OnlinePayExample) ExtraBill(com.itrus.portal.db.ExtraBill) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date) OnlinePay(com.itrus.portal.db.OnlinePay)

Example 18 with OnPayInfo

use of com.itrus.portal.db.OnPayInfo in project portal by ixinportal.

the class PayWebController method pay.

/**
 * 测试的接口
 * @param request
 * @param response
 */
@RequestMapping(produces = "text/html")
public void pay(HttpServletRequest request, HttpServletResponse response) {
    URL = request.getParameter("url");
    // 应用appid
    String appid = request.getParameter("appid");
    // 应用秘钥
    APP_SECRET_KEY = request.getParameter("appSecretKey");
    String payid = request.getParameter("payid");
    // 订单号
    String orderNo = request.getParameter("orderNo");
    // 订单号
    String money = request.getParameter("money");
    String spbill_create_ip = request.getParameter("spbill_create_ip");
    String attach = request.getParameter("attach");
    String requestURI = request.getRequestURI();
    String requestURL = request.getRequestURL().toString();
    int indexOfURI = requestURL.indexOf(requestURI);
    StringBuffer notifySB = new StringBuffer();
    StringBuffer returnSB = new StringBuffer();
    // 回调url
    String notifyStr = request.getContextPath() + "/web/pay/notifyUrl";
    // 页面跳转url
    String returnStr = request.getContextPath() + "/web/pay/returnUrl";
    notifySB.append(requestURL.substring(0, indexOfURI)).append(notifyStr);
    returnSB.append(requestURL.substring(0, indexOfURI)).append(returnStr);
    // 异步回调url
    String notify_url = notifySB.toString();
    // 页面跳转url
    String return_url = returnSB.toString();
    // 交易类型    all 获取在平台开通的支付方式 ,  alipay:支付宝 ,wechat:微信,unionPay 银联,thirdPay 第三方付款
    String pay_type = request.getParameter("pay_type");
    // 描述  商品的标题/交易标题/订单标题/订单关键字等。该参数最长为128个汉字。
    String describe = request.getParameter("body");
    // 随机字符串
    String nonce_str = PayUtil.getNonceStr();
    SortedMap<String, String> packageParams = new TreeMap<String, String>();
    packageParams.put("appid", appid);
    packageParams.put("nonce_str", nonce_str);
    packageParams.put("body", describe);
    packageParams.put("out_trade_no", orderNo);
    packageParams.put("total_fee", money.toString());
    packageParams.put("spbill_create_ip", spbill_create_ip);
    packageParams.put("notify_url", notify_url);
    packageParams.put("return_url", return_url);
    packageParams.put("pay_type", pay_type);
    packageParams.put("attach", attach);
    RequestHandler reqHandler = new RequestHandler(null, null);
    reqHandler.init(null, null, APP_SECRET_KEY);
    String sign = reqHandler.createSign(packageParams);
    String xmlParam = "<xml><appid>" + appid + "</appid>" + "<nonce_str>" + nonce_str + "</nonce_str><sign>" + sign + "</sign>" + "<body><![CDATA[" + describe.trim() + "]]></body>" + "<out_trade_no>" + orderNo + "</out_trade_no><total_fee>" + money + "</total_fee>" + "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip><notify_url>" + notify_url + "</notify_url><return_url>" + return_url + "</return_url><pay_type>" + pay_type + "</pay_type><attach>" + attach + "</attach></xml>";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(URL);
    // DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    // def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    // TransactionStatus s = transactionManager.getTransaction(def);
    String jsonStr = null;
    try {
        httppost.setEntity(new StringEntity(xmlParam, "UTF-8"));
        HttpResponse respon = httpclient.execute(httppost);
        jsonStr = EntityUtils.toString(respon.getEntity(), "UTF-8");
        if (jsonStr.indexOf("FAIL") != -1) {
            PayUtil.showJsp(response, SytemUtil.getContextUrl(request) + "/web/pay/returnUrl1");
            return;
        } else if (jsonStr.indexOf("SUCCESS") != -1) {
            Map m = PayUtil.parseXmlToList2(jsonStr);
            String contextUrl = (String) m.get("redirect_url");
            String sign01 = (String) m.get("sign");
            // 必须进行验签,否则存在支付风险
            boolean result01 = PayUtil.validate(sign01, m, APP_SECRET_KEY);
            if (result01) {
                SortedMap<String, String> pk = new TreeMap<String, String>();
                pk.put("redirect_url", contextUrl);
                String encryString = PayUtil.getEncryString(pk, APP_SECRET_KEY);
                BillExample be = new BillExample();
                BillExample.Criteria bc = be.createCriteria();
                bc.andBillIdEqualTo(orderNo);
                Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByExample", be);
                OnPayInfo payInfo;
                HttpSession session = request.getSession();
                UserInfo userInfo = (UserInfo) session.getAttribute("webuserInfo");
                if (bill.getOnPayInfo() == null) {
                    payInfo = new OnPayInfo();
                    payInfo.setOnlinePay(Long.parseLong(payid));
                    payInfo.setPaySum(Double.parseDouble(money));
                    payInfo.setPayStatus(0);
                    payInfo.setDyTime(new Date());
                    payInfo.setName(String.valueOf(userInfo.getId()));
                    sqlSession.insert("com.itrus.portal.db.OnPayInfoMapper.insert", payInfo);
                    sqlSession.flushStatements();
                    bill.setOnPayInfo(payInfo.getId());
                    sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", bill);
                } else {
                    payInfo = sqlSession.selectOne("com.itrus.portal.db.OnPayInfoMapper.selectByPrimaryKey", bill.getOnPayInfo());
                    payInfo.setOnlinePay(Long.parseLong(payid));
                    payInfo.setPaySum(Double.parseDouble(money));
                    payInfo.setDyTime(new Date());
                    payInfo.setName(String.valueOf(userInfo.getId()));
                    sqlSession.update("com.itrus.portal.db.OnPayInfoMapper.updateByPrimaryKeySelective", payInfo);
                }
                // transactionManager.commit(s);
                response.sendRedirect(contextUrl + "&sign=" + encryString);
            }
            return;
        }
    } catch (Exception e) {
        LogUtil.syslog(sqlSession, "在线支付", orderNo + "在线支付错误:" + e.toString() + xmlParam + jsonStr);
        e.printStackTrace();
    }
// finally{
// if (!s.isCompleted()) {
// transactionManager.rollback(s);
// }
// }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpSession(javax.servlet.http.HttpSession) HttpResponse(org.apache.http.HttpResponse) UserInfo(com.itrus.portal.db.UserInfo) TreeMap(java.util.TreeMap) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Date(java.util.Date) StringEntity(org.apache.http.entity.StringEntity) BillExample(com.itrus.portal.db.BillExample) OnPayInfo(com.itrus.portal.db.OnPayInfo) RequestHandler(com.utils.payUtils.RequestHandler) SortedMap(java.util.SortedMap) Bill(com.itrus.portal.db.Bill) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with OnPayInfo

use of com.itrus.portal.db.OnPayInfo in project portal by ixinportal.

the class PayWebController method notifyUrl.

/**
 * 客户服务器回调页面
 * [callback]<xml>
 *     <nonce_str><![CDATA[1639324264]]></nonce_str>
 *     <out_trade_no><![CDATA[TWCX20160629144115177012]]></out_trade_no>
 *     <return_code><![CDATA[SUCCESS]]></return_code>
 *     <return_msg><![CDATA[姣浠瀹氦骀]]></return_msg>
 *     <total_fee><![CDATA[0.01]]></total_fee>
 *     <transaction_id><![CDATA[2016071521001004860279928780]]></transaction_id>
 *     <sign>321D99F194DE952B6699C3E23361C06C</sign>
 *     <nonce_str>1639324264</nonce_str>
 * </xml>
 *
 * @param request
 * @param response
 * @return
 */
@RequestMapping(value = "/notifyUrl")
public String notifyUrl(HttpServletRequest request, HttpServletResponse response) {
    String line = null;
    String notifyXml = "";
    // DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    // def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    // TransactionStatus s = null;
    Map<String, String> m = null;
    try {
        if ((line = request.getReader().readLine()) != null) {
            notifyXml += line;
        }
        m = PayUtil.parseXmlToList2(notifyXml);
        String sign = m.get("sign");
        PayConfigExample pce = new PayConfigExample();
        PayConfigExample.Criteria pcc = pce.createCriteria();
        pcc.andAppIdEqualTo(m.get("appid"));
        PayConfig pc = sqlSession.selectOne("com.itrus.portal.db.PayConfigMapper.selectByExample", pce);
        APP_SECRET_KEY = pc.getSecretKey();
        boolean validate = PayUtil.validate(sign, m, APP_SECRET_KEY);
        if (validate) {
            if (("SUCCESS").equals(m.get("return_code"))) {
                // m.get("return_msg");//返回信息
                // m.get("out_trade_no");//交易订单号
                // s = transactionManager.getTransaction(def);
                BillExample be = new BillExample();
                BillExample.Criteria bc = be.createCriteria();
                bc.andBillIdEqualTo(m.get("out_trade_no"));
                Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByExample", be);
                bill.setBillStatus(3);
                bill.setPayTime(new Date());
                sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", bill);
                OnPayInfo payInfo = sqlSession.selectOne("com.itrus.portal.db.OnPayInfoMapper.selectByPrimaryKey", bill.getOnPayInfo());
                payInfo.setPayStatus(1);
                payInfo.setWcTime(bill.getPayTime());
                payInfo.setPayNo(m.get("transaction_id"));
                OnlinePayExample ope = new OnlinePayExample();
                OnlinePayExample.Criteria opc = ope.createCriteria();
                opc.andPayConfigEqualTo(pc.getId());
                // 1支付宝 2微信
                opc.andWayEqualTo((Integer.parseInt(m.get("pay_type")) == 0 ? 2 : 1));
                OnlinePay onlinePay = sqlSession.selectOne("com.itrus.portal.db.OnlinePayMapper.selectByExample", ope);
                payInfo.setOnlinePay(onlinePay.getId());
                // payInfo.setComment(m.get("return_msg"));
                sqlSession.update("com.itrus.portal.db.OnPayInfoMapper.updateByPrimaryKeySelective", payInfo);
                // transactionManager.commit(s);
                // 标示成功接收到
                PayUtil.sendToCFT(response, "SUCCESS");
            // m.get("total_fee");//金额
            // m.get("attach");//附加数据 在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
            } else if (("FAIL").equals(m.get("return_code"))) {
                // 第三方返回支付失败的情况
                PayUtil.sendToCFT(response, "SUCCESS");
                LogUtil.syslog(sqlSession, "在线支付", m.get("out_trade_no") + "回调错误:[callback FAIL]FAIL" + notifyXml);
            } else {
                // 标示没接收到
                PayUtil.sendToCFT(response, "FAIL");
                LogUtil.syslog(sqlSession, "在线支付", m.get("out_trade_no") + "回调错误:[callback FAIL]" + notifyXml);
            }
        // if("FAIL".equals(m.get("result_code"))) {
        // m.get("err_code");//错误码 有:SYSTEMERROR\SIGNERROR\LACK_PARAMS\PARAMS_ERROR\WECHAT_EMPTY\WECHAT_SIGNERROR\ALI_EMPTY\ALI_SIGNERROR
        // m.get("err_code_des");//错误描述 有:系统错误\平台签名失败\缺少参数\参数不合规范或域名不匹配\微信报文为空\微信签名错误\支付宝报文为空\支付宝验签失败
        // }
        }
    // for (Entry<String, String> s : m.entrySet()) {
    // System.out.println(s.getKey()+"#################"+s.getValue());
    // }
    } catch (Exception e) {
        LogUtil.syslog(sqlSession, "在线支付", m.get("out_trade_no") + "回调错误:" + e.toString() + notifyXml);
        log.error(m.get("out_trade_no") + "[callback FAIL]" + e.toString());
        e.printStackTrace();
    }
    // }
    return null;
}
Also used : PayConfig(com.itrus.portal.db.PayConfig) OnlinePayExample(com.itrus.portal.db.OnlinePayExample) PayConfigExample(com.itrus.portal.db.PayConfigExample) Date(java.util.Date) BillExample(com.itrus.portal.db.BillExample) OnPayInfo(com.itrus.portal.db.OnPayInfo) Bill(com.itrus.portal.db.Bill) OnlinePay(com.itrus.portal.db.OnlinePay) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with OnPayInfo

use of com.itrus.portal.db.OnPayInfo in project portal by ixinportal.

the class DoUnlockKeyController method toUnlockFailPage.

@RequestMapping("/toUnlockFailPage/{billId}")
public String toUnlockFailPage(@PathVariable("billId") Long billId, Model uiModel) {
    Bill bill = billService.getBill(billId);
    UserInfo userInfo = userInfoService.getUserInfoById(bill.getUniqueId());
    Proxy proxy = proxyService.getProxyByBillId(bill.getId());
    OnPayInfo onPayInfo = onPayInfoService.selectByPrimaryKey(bill.getOnPayInfo());
    UserCert userCert = userCertService.selectByPrimaryKey(bill.getUnlockUserCert());
    uiModel.addAttribute("mPhone", userInfo.getmPhone());
    uiModel.addAttribute("userCert", userCert);
    uiModel.addAttribute("bill", bill);
    uiModel.addAttribute("onPayInfo", onPayInfo);
    uiModel.addAttribute("proxy", proxy);
    uiModel.addAttribute("keySn", userCert.getKeySn());
    uiModel.addAttribute("certSn", userCert.getCertSn());
    return "clientFW/jiesuoyichang";
}
Also used : Proxy(com.itrus.portal.db.Proxy) OnPayInfo(com.itrus.portal.db.OnPayInfo) Bill(com.itrus.portal.db.Bill) UserInfo(com.itrus.portal.db.UserInfo) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OnPayInfo (com.itrus.portal.db.OnPayInfo)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 UserInfo (com.itrus.portal.db.UserInfo)16 Enterprise (com.itrus.portal.db.Enterprise)14 OnlinePay (com.itrus.portal.db.OnlinePay)12 ExtraBill (com.itrus.portal.db.ExtraBill)9 PayInfo (com.itrus.portal.db.PayInfo)9 HttpSession (javax.servlet.http.HttpSession)9 Bill (com.itrus.portal.db.Bill)8 Map (java.util.Map)8 ExtraProduct (com.itrus.portal.db.ExtraProduct)7 Product (com.itrus.portal.db.Product)7 HashMap (java.util.HashMap)7 DigitalCert (com.itrus.portal.db.DigitalCert)6 Einvoice (com.itrus.portal.db.Einvoice)6 ExtraProductSpec (com.itrus.portal.db.ExtraProductSpec)6 OpenBankInfo (com.itrus.portal.db.OpenBankInfo)6 PayInfoExample (com.itrus.portal.db.PayInfoExample)6 ReviewLog (com.itrus.portal.db.ReviewLog)6 Date (java.util.Date)6