Search in sources :

Example 41 with Bill

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

the class UnlockKeyBillController method toReSubmitUnlockBillPage.

/**
 * 页面申请信息有误,或者审核拒绝,重新提交
 *
 * @param billId
 * @param certSn
 * @param keySn
 * @param uiModel
 * @return
 */
@RequestMapping("/toReSubmitUnlockBillPage/{billId}")
public String toReSubmitUnlockBillPage(@PathVariable("billId") Long billId, @RequestParam("certSn") String certSn, @RequestParam("keySn") String keySn, Model uiModel) {
    UserCert userCert = userCertService.getUserCertByCertSn(certSn);
    if (null == userCert) {
        uiModel.addAttribute("errorMsg", "无法识别该证书,请检查您插入的key是否正确,证书序列号:" + certSn);
        return ComNames.CLIENTFW_ERRORPAGE;
    }
    // if (null == userCert.getUserinfo() || null == userCert.getEnterprise()) {
    // uiModel.addAttribute("errorMsg", "该证书尚未绑定用户和企业信息");
    // return ComNames.CLIENTFW_ERRORPAGE;
    // }
    Bill bill = billService.getBill(billId);
    if (null == bill) {
        uiModel.addAttribute("errorMsg", "不存在解锁订单");
        return ComNames.CLIENTFW_ERRORPAGE;
    }
    if (!(bill.getBillStatus().equals(ComNames.BILL_STATUS_1) || bill.getBillStatus().equals(ComNames.BILL_STATUS_2) || bill.getBillStatus().equals(ComNames.BILL_STATUS_15))) {
        uiModel.addAttribute("errorMsg", "该订单不处于可以重新提交授权书的状态");
        return ComNames.CLIENTFW_ERRORPAGE;
    }
    uiModel.addAttribute("bill", bill);
    if (!bill.getUnlockUserCert().equals(userCert.getId())) {
        uiModel.addAttribute("errorMsg", "您无权操作该订单");
        return ComNames.CLIENTFW_ERRORPAGE;
    }
    Proxy proxy = proxyService.getProxyByBillId(bill.getId());
    if (null != proxy) {
        uiModel.addAttribute("proxy", proxy);
    }
    Product product = productService.getProduct(bill.getProduct());
    uiModel.addAttribute("product", product);
    uiModel.addAttribute("userCert", userCert);
    return "clientWF/xiugaishouquanshu";
}
Also used : Proxy(com.itrus.portal.db.Proxy) Bill(com.itrus.portal.db.Bill) Product(com.itrus.portal.db.Product) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with Bill

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

the class UnlockKeyBillController method submitUnlockBill.

/**
 * 提交解锁订单
 * @param productId,购买产品的id
 * @param certSn
 * @param keySn
 * @param einvoice
 * @param proxy
 * @param request
 * @return
 */
@RequestMapping("/submitUnlockBill")
@ResponseBody
public Map<String, Object> submitUnlockBill(@RequestParam("productId") Long productId, @RequestParam("certSn") String certSn, @RequestParam("keySn") String keySn, @RequestParam("keyType") String keyType, @RequestParam("enterpriseName") String enterpriseName, @RequestParam("reqCode") String reqCode, @ModelAttribute("einvoice") Einvoice einvoice, @ModelAttribute("userInfo") UserInfo userInfo, @ModelAttribute("enterprise") Enterprise enterprise, @ModelAttribute("proxy") Proxy proxy, HttpServletRequest request) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("retCode", 0);
    HttpSession session = request.getSession();
    UserCert userCert = userCertService.getUserCertByCertSn(certSn);
    if (StringUtils.isBlank(keySn)) {
        retMap.put("retMsg", "key序列号不能为空");
        return retMap;
    }
    if (StringUtils.isBlank(reqCode)) {
        retMap.put("retMsg", "解锁请求码不能为空");
        return retMap;
    }
    if (null == userCert) {
        retMap.put("retMsg", "该证书未注册,请您先注册");
        return retMap;
    }
    if (StringUtils.isBlank(userCert.getKeySn()) || !keySn.equals(userCert.getKeySn())) {
        userCert.setKeySn(keySn);
        userCertService.updateByPrimaryKeySelective(userCert);
    }
    UserInfo webUserInfo = null;
    if (null == userInfo || StringUtils.isBlank(userInfo.getmPhone())) {
        retMap.put("retMsg", "用户信息不完整,请重新提交");
        return retMap;
    } else {
        webUserInfo = userInfoService.getUserInfoByMphone(userInfo.getmPhone());
    }
    if (null == webUserInfo) {
        retMap.put("retMsg", "手机号:" + userInfo.getmPhone() + ", 尚未注册或者校验通过,请检查您输入的手机号是否正确!");
        return retMap;
    }
    Enterprise enterpriseByName = enterpriseService.getEntByName(enterpriseName);
    if (null == enterpriseByName) {
        // 若新提交的企业信息为null或者信息不全,则提示
        if (null == enterprise || StringUtils.isBlank(enterprise.getEnterpriseName()) || null == enterprise.getEnterpriseNature() || StringUtils.isBlank(enterprise.getEnterpriseSn())) {
            retMap.put("retMsg", "企业信息不完整,请重新提交");
            return retMap;
        } else {
            // 保存新增的企业信息
            enterprise = enterpriseService.saveOrUpdateEnterprise(enterprise);
            // 添加企业-代理人关联关系
            UserinfoEnterprise userinfoEnterprise = userInfoEnterpriseServiceImpl.selectOne(enterprise.getId(), webUserInfo.getId());
            if (null == userinfoEnterprise) {
                userInfoEnterpriseServiceImpl.saveUserInfoEnterprise(webUserInfo.getId(), enterprise.getId());
            }
        }
    } else {
        enterprise = enterpriseByName;
    }
    Product product = productService.getProduct(productId);
    if (null == product) {
        retMap.put("retMsg", "您选择的产品不存在");
        return retMap;
    }
    if (null == product.getKeyUnlockType()) {
        retMap.put("retMsg", "您选择的产品不属于解锁产品,请重新选择");
        return retMap;
    }
    if (null == userCert.getUserinfo() && product.getKeyUnlockType().equals(ComNames.KEY_UNLOCK_TYPE_1)) {
        retMap.put("retMsg", "未绑定用户的证书,不能购买自助解锁产品");
        return retMap;
    }
    Bill billOld = billService.getBillWaitingForUnlock(userCert.getId());
    if (null != billOld) {
        retMap.put("retMsg", "当前证书尚有未解锁的订单,请先在原订单解锁,订单号:" + billOld.getBillId());
        return retMap;
    }
    Project project = projectService.selectByPrimaryKey(product.getProject());
    DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
    dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(dtd);
    try {
        if (StringUtils.isNotBlank(userInfo.getEmail()) && StringUtils.isBlank(webUserInfo.getEmail())) {
            webUserInfo.setEmail(userInfo.getEmail());
            userInfoService.updateUserInfo(webUserInfo);
        }
        if (StringUtils.isNotBlank(einvoice.getName()) && null != einvoice.geteReiceipt()) {
            einvoice = EinvoiceService.saveEInvoice(webUserInfo.getId(), einvoice);
        }
        Bill bill = null;
        // 生成订单
        double billSum = product.getPrice();
        bill = billService.saveBill(webUserInfo.getId(), enterprise.getId(), product.getId(), null, null, null == einvoice.getId() ? null : einvoice.getId(), null, product.getProject(), 1, billSum, webUserInfo.getId(), ComNames.BILL_STATUS_1);
        bill.setBillId(UniqueIDUtils.genBilUID(bill));
        bill.setUnlockUserCert(userCert.getId());
        sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
        keyUnlockService.insert(bill.getId(), project.getId(), keySn, certSn, enterpriseName, keyType, "ENROLL", product.getKeyUnlockType() == 1 ? 1 : 2, reqCode);
        sqlSession.flushStatements();
        if (null != proxy && StringUtils.isNotBlank(proxy.getImgFile())) {
            // 保存授权书
            proxy = proxyService.saveProxy(enterprise.getId(), webUserInfo.getUniqueId(), bill.getId(), webUserInfo.getId(), proxy, project);
        }
        transactionManager.commit(status);
        retMap.put("billId", bill.getId());
        retMap.put("retCode", 1);
        // 将用户信息放入session中,避免支付出错
        session.setAttribute(ComNames.WEB_USER_INFO, webUserInfo);
        // 记录日志
        LogUtil.userlog(sqlSession, project.getId(), "购买解锁产品", webUserInfo.getmPhone() + "购买了" + product.getName(), "未知", "", null == webUserInfo.getUniqueId() ? null : webUserInfo.getUniqueId());
        return retMap;
    } catch (Exception e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        UserLog userlog = new UserLog();
        userlog.setProject(project.getId());
        userlog.setType("购买解锁产品");
        userlog.setInfo("url:submitUnlockBill,详细错误:" + e.getMessage());
        userlog.setHostId("未知");
        userlog.setSn(null == webUserInfo.getUniqueId() ? null : webUserInfo.getUniqueId());
        LogUtil.userlog(sqlSession, userlog);
        retMap.put("retMsg", "服务端出现未知错误,请联系管理员");
        return retMap;
    } finally {
        if (!status.isCompleted()) {
            transactionManager.rollback(status);
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) Product(com.itrus.portal.db.Product) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) UserLog(com.itrus.portal.db.UserLog) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Project(com.itrus.portal.db.Project) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) Enterprise(com.itrus.portal.db.Enterprise) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) Bill(com.itrus.portal.db.Bill) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 43 with Bill

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

the class UnlockKeyBillController method zhifuPage.

/**
 * 3进入支付页面
 *
 * @param billId
 * @param request
 * @param uiModel
 * @return
 */
@RequestMapping("/zhifu/{billId}")
public String zhifuPage(@PathVariable("billId") Long billId, @RequestParam(value = "certSn", required = false) String certSn, @RequestParam(value = "keySn", required = false) String keySn, @RequestParam(value = "enterpriseName", required = false) String enterpriseName, HttpServletRequest request, Model uiModel) {
    HttpSession session = request.getSession();
    String ip = request.getRemoteAddr();
    uiModel.addAttribute("ip", ip);
    Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", billId);
    if (null == bill) {
        return "resourceNotFound";
    }
    // 产品
    Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct());
    if (null == product) {
        // 产品不存在
        uiModel.addAttribute("errorMsg", "您购买的产品不存在");
        return ComNames.CLIENTFW_ERRORPAGE;
    }
    if (null == product.getOnpay() && StringUtils.isBlank(product.getPay()) && bill.getBillSum().equals(0.00)) {
        // 跳转到订单支付成功页面,并将订单状态设置为3已支付 待审核
        if (null != product.getKeyUnlockType()) {
            bill = unLockKeyBillService.updateBillStatusWhileHasPay(bill, product);
        } else {
            bill.setBillStatus(ComNames.BILL_STATUS_3);
        }
        sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
        session.setAttribute("webbill", bill);
        if (null != product.getKeyUnlockType()) {
            UserCert userCert = userCertService.selectByPrimaryKey(bill.getUnlockUserCert());
            Enterprise enterprise = enterpriseService.getEnterpriseById(bill.getEnterprise());
            return "redirect:/doUnlockKey/toUnlockKeyPage?" + "billId=" + billId + "&certSn=" + userCert.getCertSn() + "&keySn=" + userCert.getKeySn() + "&enterpriseName=" + enterprise.getEnterpriseName();
        } else {
            return "redirect:/billClient";
        }
    }
    // 获取产品对应的线上支付服务
    if (product.getOnpay() != null && product.getOnpay() != "") {
        List<Long> onlinepays = new ArrayList<Long>();
        String[] onpay = (product.getOnpay()).split(",");
        // 过滤掉不是服务型客户的在线支付
        onpay = onlinePayService.removeOnlinePayWithOutClientFw(onpay);
        Map<Integer, String> map = new HashMap<Integer, String>();
        for (int i = 0; i < onpay.length; i++) {
            OnlinePay op = sqlSession.selectOne("com.itrus.portal.db.OnlinePayMapper.selectByPrimaryKey", onpay[i]);
            map.put(op.getSort(), onpay[i]);
        }
        Set<Integer> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        for (int i = (onpay.length - 1); i >= 0; i--) {
            String a = map.get(obj[i]);
            onlinepays.add(Long.parseLong(a));
        }
        Map<Long, OnlinePay> opMap = sqlSession.selectMap("com.itrus.portal.db.OnlinePayMapper.selectByExample", "id");
        uiModel.addAttribute("opMap", opMap);
        uiModel.addAttribute("onlinepays", onlinepays);
        Map<Long, PayConfig> pcMap = sqlSession.selectMap("com.itrus.portal.db.PayConfigMapper.selectByExample", "id");
        uiModel.addAttribute("pcMap", pcMap);
    }
    // 获取产品对应的银行汇款服务
    if (!StringUtils.isBlank(product.getPay())) {
        Transfer transfer = sqlSession.selectOne("com.itrus.portal.db.TransferMapper.selectByPrimaryKey", Long.parseLong(product.getPay()));
        uiModel.addAttribute("transfer", transfer);
    }
    if (null != product.getTransferNotes()) {
        product.setTransferNotes(product.getTransferNotes().replace("\r\n", "<br/><span ></span>"));
    }
    // 解锁订单,返回keysn,certsn,enterprisename
    if (null != product.getKeyUnlockType() && (StringUtils.isBlank(keySn) || StringUtils.isBlank(certSn) || StringUtils.isBlank(enterpriseName))) {
        Enterprise enterprise = enterpriseService.getEnterpriseById(bill.getEnterprise());
        enterpriseName = enterprise.getEnterpriseName();
        UserCert userCert = userCertService.selectByPrimaryKey(bill.getUnlockUserCert());
        if (null != userCert && StringUtils.isNotBlank(userCert.getKeySn())) {
            keySn = userCert.getKeySn();
        }
        if (null != userCert && StringUtils.isNotBlank(userCert.getCertSn())) {
            certSn = userCert.getCertSn();
        }
    }
    uiModel.addAttribute("product", product);
    uiModel.addAttribute("certSn", certSn);
    uiModel.addAttribute("keySn", keySn);
    uiModel.addAttribute("enterpriseName", enterpriseName);
    session.setAttribute("webbill", bill);
    if (null != product.getCert()) {
        // 产品关联的数字证书
        DigitalCert digitalCert = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product.getCert());
        // 用于获取产品期限(数字证书的期限)
        uiModel.addAttribute("digitalCert", digitalCert);
    }
    return "clientFW/pay";
}
Also used : PayConfig(com.itrus.portal.db.PayConfig) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) Product(com.itrus.portal.db.Product) DigitalCert(com.itrus.portal.db.DigitalCert) Bill(com.itrus.portal.db.Bill) Enterprise(com.itrus.portal.db.Enterprise) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) Transfer(com.itrus.portal.db.Transfer) UserCert(com.itrus.portal.db.UserCert) OnlinePay(com.itrus.portal.db.OnlinePay) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with Bill

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

the class APIService method search.

/**
 * 查询企业认证审核结果
 *
 * @param authHmac
 *            hmac签名值,采用HmacSHA1算法
 * @param appId
 *            应用标识
 * @param orderNumber
 *            申请流水号
 * @return status:message 1 审核通过,0 待审核,-1 审核拒绝:原因
 */
@PostMapping(value = "/auth/search")
@ResponseBody
public Map<String, Object> search(@RequestHeader("Content-Signature") String authHmac, @RequestParam("appId") String appId, @RequestParam("orderNumber") String orderNumber, HttpServletRequest request) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("status", -2);
    // 验证参数是否完整
    if (StringUtils.isEmpty(authHmac) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(orderNumber)) {
        result.put("message", "提交的参数信息不完整");
        return result;
    }
    // 获取对应订单
    Bill bill = billService.getBillByOrderNumber(orderNumber);
    if (bill == null) {
        result.put("message", "申请流水号不存在");
        return result;
    }
    // 得到应用信息 改成service
    Map<String, ApplicationInfo> appInfoMap = CacheCustomer.getAPP_INFO_MAP();
    ApplicationInfo applicationInfo = appInfoMap.get(appId);
    if (applicationInfo == null) {
        ApplicationInfoExample applicationInfoExample = new ApplicationInfoExample();
        ApplicationInfoExample.Criteria appInfoExampleCriteria = applicationInfoExample.createCriteria();
        appInfoExampleCriteria.andAppIdEqualTo(appId);
        applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", applicationInfoExample);
    }
    if (applicationInfo == null) {
        result.put("message", "应用标识不存在");
        return result;
    }
    if (!applicationInfo.getAccessIp().contains(request.getRemoteAddr()) && "1".equals(applicationInfo.getIsIpStatus())) {
        result.put("status", -1);
        result.put("message", "没有此服务权限");
        log.error("APIService_AccsessIp : " + request.getRemoteAddr());
        return result;
    }
    // 验证hmac有效性
    try {
        String macVal = CertService.hmacSha1(applicationInfo.getSecretKey().getBytes(), (appId + orderNumber).getBytes("utf-8"));
        // sc.getAddressKey()), false);
        if (!authHmac.equals("HMAC-SHA1 " + macVal)) {
            result.put("status", -2);
            result.put("message", "服务密钥错误");
            return result;
        }
    } catch (Exception e) {
        result.put("status", -3);
        result.put("message", "Hmac验证错误");
        e.printStackTrace();
        return result;
    }
    if (bill.getBillStatus().equals(ComNames.BILL_STATUS_1)) {
        result.put("status", 1);
        result.put("message", "待支付");
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_2)) {
        result.put("status", 2);
        result.put("message", "提交银行汇款凭证后,将在下一个工作日确认到款,请耐心等待!");
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_3)) {
        result.put("status", 3);
        result.put("message", "您的订单已进入审核期,将在2个工作日(不含周末和节假日)完成审核," + "审核结果将以短信的形式发送至您的手机,请耐心等候,如有其它问题请拨打客服热线。");
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_4)) {
        result.put("status", 4);
        result.put("message", bill.getCancelReason());
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_5)) {
        result.put("status", 5);
        result.put("message", "您的订单已通过实名认证审核,将在5个工作日(不含周末和节假日)完成制作并发货," + "请耐心等候,如有其它问题请拨打客服热线。");
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_6)) {
        result.put("status", 6);
        result.put("message", "您的订单已通过实名认证审核,将在5个工作日(不含周末和节假日)完成制作并发货," + "请耐心等候,如有其它问题请拨打客服热线。");
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_7)) {
        result.put("status", 7);
        result.put("message", "您的订单已通过实名认证审核,将在5个工作日(不含周末和节假日)完成制作并发货," + "请耐心等候,如有其它问题请拨打客服热线。");
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_8)) {
        result.put("status", 8);
        result.put("message", "已完成");
    } else if (bill.getBillStatus().equals(9)) {
        result.put("status", 9);
        result.put("message", bill.getCancelReason());
    } else if (bill.getBillStatus().equals(ComNames.BILL_STATUS_10)) {
        result.put("status", 10);
        result.put("message", "送审中");
    } else {
        result.put("message", "服务端出现未知错误,请联系管理员");
    }
    /*
		 * if(bill.getBillStatus().equals(3)){ result.put("status", 0);
		 * result.put("message", "待审核"); }else
		 * if(bill.getBillStatus().equals(4)){ result.put("status", -1);
		 * result.put("message", "审核拒绝:"+bill.getCancelReason()); }else
		 * if(bill.getBillStatus().equals(5)){ result.put("status", 1);
		 * result.put("message", "审核通过"); }else{ result.put("message",
		 * "服务端出现未知错误,请联系管理员"); }
		 */
    return result;
}
Also used : ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) HashMap(java.util.HashMap) Bill(com.itrus.portal.db.Bill) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) JSONObject(com.alibaba.fastjson.JSONObject) JSONException(org.json.JSONException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 45 with Bill

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

the class APIService method lookup.

/**
 * 证书查询接口
 * @param authHmac
 * @param appId
 * @param billId
 * @param request
 * @return
 */
@PostMapping(value = "/cert/search")
@ResponseBody
public Map<String, Object> lookup(@RequestHeader("Content-Signature") String authHmac, @RequestParam(value = "appId", required = true) String appId, @RequestParam(value = "billId", required = true) String billId, HttpServletRequest request) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("status", 0);
    log.error("appId=" + appId + "billId=" + billId);
    // 验证参数是否完整
    if (StringUtils.isEmpty(authHmac) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(billId)) {
        result.put("status", 0);
        result.put("message", "提交的参数信息不完整");
        return result;
    }
    // 得到应用信息 改成service
    Map<String, ApplicationInfo> appInfoMap = CacheCustomer.getAPP_INFO_MAP();
    ApplicationInfo applicationInfo = appInfoMap.get(appId);
    if (applicationInfo == null) {
        ApplicationInfoExample applicationInfoExample = new ApplicationInfoExample();
        ApplicationInfoExample.Criteria appInfoExampleCriteria = applicationInfoExample.createCriteria();
        appInfoExampleCriteria.andAppIdEqualTo(appId);
        applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", applicationInfoExample);
    }
    if (applicationInfo == null) {
        result.put("message", "应用标识不存在");
        return result;
    }
    if (!applicationInfo.getAccessIp().contains(request.getRemoteAddr()) && "1".equals(applicationInfo.getIsIpStatus())) {
        result.put("status", -1);
        result.put("message", "没有此服务权限");
        log.error("APIService_AccsessIp : " + request.getRemoteAddr());
        return result;
    }
    // 验证hmac有效性
    try {
        String macVal = CertService.hmacSha1(applicationInfo.getSecretKey().getBytes(), (appId + billId).getBytes("utf-8"));
        if (!authHmac.equals("HMAC-SHA1 " + macVal)) {
            result.put("status", -2);
            result.put("message", "服务密钥错误");
            return result;
        }
    } catch (Exception e) {
        result.put("status", -3);
        result.put("message", "Hmac验证错误");
        e.printStackTrace();
        return result;
    }
    BillExample billExample = new BillExample();
    BillExample.Criteria criteria = billExample.or();
    criteria.andBillIdEqualTo(billId);
    Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByExample", billExample);
    if (bill == null) {
        result.put("message", "没有此订单");
        return result;
    }
    Product product = productService.getProduct(bill.getProduct());
    DigitalCert dcert = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product.getCert());
    List<String> listcert = new ArrayList<String>();
    if ("3".equals(dcert.getCertType())) {
        Integer uidIdx = 1;
        // 用户已经下载过了,再次下载
        boolean downLoadFlag = bill.getBillStatus().equals(ComNames.BILL_STATUS_6) || bill.getBillStatus().equals(ComNames.BILL_STATUS_7) || bill.getBillStatus().equals(ComNames.BILL_STATUS_8);
        if (downLoadFlag) {
            // 根据订单号,找到订单对应的证书信息
            CertBuf certBuf = sqlSession.selectOne("com.itrus.portal.db.CertBufMapper.selectPfxCertByBillId", bill.getId());
            listcert.add(certBuf.getPfxCert());
            result.put("status", 1);
            result.put("pfxData", listcert);
        } else {
            // 用户未下载过,第一次下载
            if (bill.getBillStatus().equals(ComNames.BILL_STATUS_13)) {
                // 查询项目产品
                // Product product = productService.getProduct(bill.getProduct());
                // 企业
                Enterprise enterprise = enterpriseService.getEnterpriseById(bill.getEnterprise());
                // 获取产品、RA配置
                RaAccount ra = raAccountService.getRaAccount(product.getRa());
                // 证书配置
                DigitalCert digitalcert = digitalCertService.getDigitalCert(product.getCert());
                // 下载证书
                String autoidType = "";
                Integer autoidValue = 0;
                String pfxCert = "";
                // 用户ID,用来最终匹配公钥证书和密钥对
                String userid = bill.getBillId() + (Math.random() * 1000 + 9000);
                // TODO 20170410pfx私钥证书保护密码:需要根据产品配置的密码或获取
                String certPass = product.getPassword();
                // 产生CSR证书请求
                String certReqBuf = "";
                // 算法
                String algorithm = digitalCertService.getAlgorithm(digitalcert);
                // 下载证书
                CertInfo racertinfo = null;
                try {
                    certReqBuf = GenUtil.GenP10(userid, "", algorithm);
                    racertinfo = downLoadCertService.downLoadCert(product, ra, bill, digitalcert, uidIdx, certReqBuf, autoidType, autoidValue);
                    // pfxCert = GenUtil.GenPFX(userid, certPass,
                    // racertinfo.getCertSignBuf(), false);
                    // pfxCert = GenUtil2.GenPFX(userid, certPass, racertinfo.getCertSignBuf(), pfxCert, false, enterprise.getEnterpriseName());
                    pfxCert = GenUtil.GenPFX(userid, certPass, racertinfo.getCertSignBuf(), false, enterprise.getEnterpriseName());
                    // 保存证书
                    downLoadCertService.savePfxCertInfo(racertinfo, bill, ra.getId(), uidIdx, "", autoidType, autoidValue, pfxCert);
                    listcert.add(pfxCert);
                    result.put("status", 1);
                    result.put("pfxData", listcert);
                } catch (Exception e) {
                    result.put("status", -1);
                    result.put("message", "pfx证书下载错误" + e.getMessage());
                }
            }
        }
    } else {
        List<UserCert> certlist = userCertService.getUserCertByBill(bill.getId(), null);
        for (UserCert uc : certlist) {
            CertBuf cb = sqlSession.selectOne("com.itrus.portal.db.CertBufMapper.selectByPrimaryKey", uc.getCertBuf());
            listcert.add(cb.getCertBuf());
        }
        if (listcert.size() > 0) {
            result.put("status", 1);
            result.put("cerData", listcert);
        } else {
            result.put("message", "没有查找到相应证书");
        }
    }
    return result;
}
Also used : CertInfo(cn.topca.tca.ra.service.CertInfo) ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) HashMap(java.util.HashMap) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) ArrayList(java.util.ArrayList) Product(com.itrus.portal.db.Product) JSONException(org.json.JSONException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) DigitalCert(com.itrus.portal.db.DigitalCert) BillExample(com.itrus.portal.db.BillExample) RaAccount(com.itrus.portal.db.RaAccount) Bill(com.itrus.portal.db.Bill) CertBuf(com.itrus.portal.db.CertBuf) Enterprise(com.itrus.portal.db.Enterprise) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) JSONObject(com.alibaba.fastjson.JSONObject) UserCert(com.itrus.portal.db.UserCert) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Bill (com.itrus.portal.db.Bill)74 HashMap (java.util.HashMap)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)42 Product (com.itrus.portal.db.Product)39 UserInfo (com.itrus.portal.db.UserInfo)32 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)27 Enterprise (com.itrus.portal.db.Enterprise)26 UserCert (com.itrus.portal.db.UserCert)22 JSONObject (com.alibaba.fastjson.JSONObject)21 Date (java.util.Date)20 ArrayList (java.util.ArrayList)19 BillExample (com.itrus.portal.db.BillExample)18 IOException (java.io.IOException)18 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)16 DigitalCert (com.itrus.portal.db.DigitalCert)15 Map (java.util.Map)12 TransactionStatus (org.springframework.transaction.TransactionStatus)10 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)10 OnPayInfo (com.itrus.portal.db.OnPayInfo)9 Proxy (com.itrus.portal.db.Proxy)9