@Override public String onCallBack() { HttpServletRequest request = ThreadContextHolder.getHttpRequest(); HttpServletResponse response = ThreadContextHolder.getHttpResponse(); Map<String, String> params = this.getConfigParams(); String key = params.get("tenpaykey"); // "8934e7d15453e97507ef794cf7b0519d"; // 创建PayResponseHandler实例 PayResponseHandler resHandler = new PayResponseHandler(request, response); resHandler.setKey(key); // 判断签名 if (resHandler.isTenpaySign()) { // 交易单号 String transaction_id = resHandler.getParameter("transaction_id"); // 金额金额,以分为单位 String total_fee = resHandler.getParameter("total_fee"); // 支付结果 String pay_result = resHandler.getParameter("pay_result"); if ("0".equals(pay_result)) { // ------------------------------ // 处理业务开始 // ------------------------------ // 注意交易单不要重复处理 // 注意判断返回金额 // ------------------------------ // 处理业务完毕 // ------------------------------ // 调用doShow, 打印meta值跟js代码,告诉财付通处理成功,并在用户浏览器显示$show页面. String strHtml = "<html><head>\r\n" + "<meta name=\"TENCENT_ONLINE_PAYMENT\" content=\"China TENCENT\">\r\n" + "</head><body></body></html>"; return strHtml; } else { // 当做不成功处理 System.out.println("支付失败"); } } else { System.out.println("认证签名失败"); // String debugInfo = resHandler.getDebugInfo(); // System.out.println("debugInfo:" + debugInfo); } return null; }
/* */ public void onAfterOrderCreate(Order order, List<CartItem> itemList, String sessionid) /* */ { /* 41 */ IUserService userService = UserServiceFactory.getUserService(); /* 42 */ Member member = userService.getCurrentMember(); /* 43 */ if (member != null) /* */ { /* 46 */ EopSite site = EopContext.getContext().getCurrentSite(); /* */ /* 48 */ HttpServletRequest request = ThreadContextHolder.getHttpRequest(); /* */ /* 50 */ String domain = RequestUtil.getDomain(); /* */ /* 52 */ EmailModel emailModel = new EmailModel(); /* 53 */ emailModel.getData().put("username", member.getUname()); /* 54 */ emailModel.getData().put("sn", order.getSn()); /* 55 */ emailModel .getData() .put("createtime", DateUtil.toString(order.getCreate_time(), "yyyy-MM-dd HH:mm:ss")); /* 56 */ emailModel.getData().put("sitename", site.getSitename()); /* 57 */ emailModel.getData().put("logo", site.getLogofile()); /* 58 */ emailModel.getData().put("domain", domain); /* */ /* 60 */ emailModel.setTitle("订单提交成功--" + site.getSitename()); /* 61 */ emailModel.setTo(member.getEmail()); /* 62 */ emailModel.setTemplate("order_create_email_template.html"); /* 63 */ this.mailMessageProducer.send(emailModel); /* */ } /* */ }
protected void display(Map<String, String> params) { HttpServletRequest request = ThreadContextHolder.getHttpRequest(); List<Nav> navList = (List<Nav>) request.getAttribute("site_nav_list"); navList = navList == null ? new ArrayList<Nav>() : navList; this.putData("navList", navList); request.removeAttribute("site_nav_list"); }
@Override protected void display(Map<String, String> params) { String pager = params.get("pager"); // on开启,off关闭 pager = StringUtil.isEmpty(pager) ? "on" : pager; Integer modelid = Integer.valueOf(params.get("modelid")); String pageSizeParam = params.get("pagesize"); int pageSize = StringUtil.isEmpty(pageSizeParam) ? 20 : Integer.valueOf(pageSizeParam); HttpServletRequest request = ThreadContextHolder.getHttpRequest(); String pageParam = request.getParameter("page"); int pageNo = StringUtil.isEmpty(pageParam) ? 1 : Integer.valueOf(pageParam); String showchilds = params.get("showchild"); // 是否显示子站数据 yes/no boolean showchild = showchilds == null ? false : (showchilds.trim().toUpperCase().equals("YES")); if ("on".equals(pager)) { Page dataPage = dataManager.search(pageNo, pageSize, modelid); List dataList = (List) dataPage.getResult(); this.putData("dataList", dataList); SearchPagerHtmlBuilder pagerHtmlBuilder = new SearchPagerHtmlBuilder(pageNo, dataPage.getTotalCount(), pageSize); String pagerHtml = pagerHtmlBuilder.buildPageHtml(); this.putData("pager", pagerHtml); } else { List dataList = dataManager.search(modelid); this.putData("dataList", dataList); this.putData("pager", "<!--不分页-->"); } }
/** * 获取servlet上下文件的Configuration * * @param pageFolder * @return */ public static Configuration getServletCfg(String pageFolder) { Configuration cfg = new Configuration(); cfg.setServletContextForTemplateLoading( ThreadContextHolder.getHttpRequest().getSession().getServletContext(), pageFolder); cfg.setObjectWrapper(new DefaultObjectWrapper()); return cfg; }
/* */ @Transactional(propagation = Propagation.REQUIRED) /* */ public Integer add(EopSite site, String domain) { /* 121 */ WebSessionContext sessonContext = ThreadContextHolder.getSessionContext(); /* */ /* 123 */ EopUser user = (EopUser) sessonContext.getAttribute("eop_user_key"); /* */ /* 125 */ return add(user, site, domain); /* */ }
private Integer getIntParam(String name) { try { HttpServletRequest httpRequest = ThreadContextHolder.getHttpRequest(); return Integer.valueOf(httpRequest.getParameter(name)); } catch (RuntimeException e) { e.printStackTrace(); return null; } }
private Integer getArticleId() { HttpServletRequest httpRequest = ThreadContextHolder.getHttpRequest(); String url = RequestUtil.getRequestUrl(httpRequest); if (url.startsWith("/widget")) return 0; String article_id = this.paseArticleId(url); return Integer.valueOf(article_id); }
/* */ public void add(Cart cart) /* */ { /* 64 */ HttpServletRequest request = ThreadContextHolder.getHttpRequest(); /* 65 */ String havespec = request.getParameter("havespec"); /* */ /* 67 */ if ("1".equals(havespec)) { /* 68 */ int productid = StringUtil.toInt(request.getParameter("productid"), true); /* 69 */ List specList = this.specManager.getProSpecList(productid); /* 70 */ if ((specList != null) && (!specList.isEmpty())) /* */ { /* 72 */ String specstr = JSONArray.fromObject(specList).toString(); /* 73 */ cart.setAddon(specstr); /* */ } /* */ } /* */ }
/* */ public String onReturn() /* */ { /* 107 */ HttpServletRequest request = ThreadContextHolder.getHttpRequest(); /* 108 */ String ordersn = request.getParameter("ordersn"); /* */ try /* */ { /* 111 */ paySuccess(ordersn, "" + DateUtil.getDateline()); /* */ } catch (RuntimeException e) { /* 113 */ if (this.logger.isDebugEnabled()) { /* 114 */ this.logger.debug(e.getMessage(), e); /* */ } /* 116 */ return e.getMessage(); /* */ } /* */ /* 119 */ return ordersn; /* */ }
/* */ public String onCallBack() /* */ { /* 36 */ HttpServletRequest request = ThreadContextHolder.getHttpRequest(); /* 37 */ String ordersn = request.getParameter("ordersn"); /* */ try /* */ { /* 40 */ paySuccess(ordersn, "" + DateUtil.getDateline()); /* */ } catch (RuntimeException e) { /* 42 */ if (this.logger.isDebugEnabled()) { /* 43 */ this.logger.debug(e.getMessage(), e); /* */ } /* 45 */ return e.getMessage(); /* */ } /* */ /* 48 */ return "支付成功"; /* */ }
/** * 覆写数据保存事件默认响应<br> * 逻辑为以name为字段为字段名,值为request.getParameter(fieldname); */ @Override public void onSave(Map article, DataField field) { HttpServletRequest request = ThreadContextHolder.getHttpRequest(); String value = request.getParameter(field.getEnglish_name()); if (value != null) { // 替换静态服务器域名为本地标识串(fs:) value = value.replaceAll( EopSetting.IMG_SERVER_DOMAIN + EopContext.getContext().getContextPath() + "/attachment/", EopSetting.FILE_STORE_PREFIX + "/attachment/"); } article.put(field.getEnglish_name(), value); }
/** * 初始化为出厂设置 * * @return */ public String initData() { try { // 校验验证码 WebSessionContext<UserContext> sessonContext = ThreadContextHolder.getSessionContext(); Object realCode = sessonContext.getAttribute(ValidCodeServlet.SESSION_VALID_CODE + "initdata"); if (!vcode.equals(realCode)) { this.json = "{result:0,message:'验证码输入错误'}"; return this.JSON_MESSAGE; } siteManager.initData(); this.json = "{result:1}"; } catch (RuntimeException e) { this.json = "{result:0,message:'" + e.getMessage() + "'}"; } return this.JSON_MESSAGE; }
protected void display(Map<String, String> params) { // this.setPageFolder("/widgets/cart"); this.setPageName("pay"); HttpServletRequest httpRequest = ThreadContextHolder.getHttpRequest(); String url = RequestUtil.getRequestUrl(httpRequest); String[] actions = this.getAction(url); if (null == actions) { this.showError("参数不正确"); } else { String action = actions[0]; String pluginid = actions[1]; if ("to".equals(action)) { this.pay(); } else if ("callback".equals(action)) { this.callback(pluginid); } else if ("return".equals(action)) { this.payReturn(pluginid); } } }
private Configuration getCfg() { if (cfg == null) { cfg = FreeMarkerUtil.getCfg(); } pathPrefix = pathPrefix == null ? "" : pathPrefix; if (pageFolder == null) { // 默认使用挂件所在文件夹 // System.out.println(" folder null use "+ this.clazz.getName() ); cfg.setClassForTemplateLoading(this.clazz, pathPrefix); } else { // System.out.println(" folder not null use "+ pageFolder); cfg.setServletContextForTemplateLoading( ThreadContextHolder.getHttpRequest().getSession().getServletContext(), pageFolder); } cfg.setObjectWrapper(new DefaultObjectWrapper()); cfg.setDefaultEncoding("UTF-8"); cfg.setLocale(java.util.Locale.CHINA); cfg.setEncoding(java.util.Locale.CHINA, "UTF-8"); return cfg; }
@Override public String onReturn() { Map<String, String> cfgparams = paymentManager.getConfigParams(this.getId()); HttpServletRequest request = ThreadContextHolder.getHttpRequest(); this.logger.info("返回来的body" + request.getParameter("body")); String key = cfgparams.get("key"); String partner = cfgparams.get("partner"); String encoding = cfgparams.get("return_encoding"); // 获取支付宝GET过来反馈信息 Map<String, String> params = new HashMap<String, String>(); Map requestParams = request.getParameterMap(); for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) { String name = (String) iter.next(); String[] values = (String[]) requestParams.get(name); String valueStr = ""; for (int i = 0; i < values.length; i++) { valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ","; } // 乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化 if (!StringUtil.isEmpty(encoding)) { valueStr = StringUtil.to(valueStr, encoding); } params.put(name, valueStr); } // 获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表(以下仅供参考)// String trade_no = request.getParameter("trade_no"); // 支付宝交易号 String order_no = request.getParameter("out_trade_no"); // 获取订单号 String total_fee = request.getParameter("total_fee"); // 获取总金额 String subject = request.getParameter("subject"); // 商品名称、订单名称 if (!StringUtil.isEmpty(encoding)) { subject = StringUtil.to(subject, encoding); } String body = ""; if (request.getParameter("body") != null) { body = request.getParameter("body"); // 商品描述、订单备注、描述 if (!StringUtil.isEmpty(encoding)) { body = StringUtil.to(body, encoding); } } String buyer_email = request.getParameter("buyer_email"); // 买家支付宝账号 String receive_name = ""; // 收货人姓名 if (request.getParameter("receive_name") != null) { receive_name = request.getParameter("receive_name"); if (!StringUtil.isEmpty(encoding)) { receive_name = StringUtil.to(receive_name, encoding); } } String receive_address = ""; // 收货人地址 if (request.getParameter("receive_address") != null) { receive_address = request.getParameter("receive_address"); if (!StringUtil.isEmpty(encoding)) { receive_address = StringUtil.to(receive_address, encoding); } } String receive_zip = ""; // 收货人邮编 if (request.getParameter("receive_zip") != null) { receive_zip = request.getParameter("receive_zip"); if (!StringUtil.isEmpty(encoding)) { receive_zip = StringUtil.to(receive_zip, encoding); } } String receive_phone = ""; // 收货人电话 if (request.getParameter("receive_phone") != null) { receive_phone = request.getParameter("receive_phone"); if (!StringUtil.isEmpty(encoding)) { receive_phone = StringUtil.to(receive_phone, encoding); } } String receive_mobile = ""; // 收货人手机 if (request.getParameter("receive_mobile") != null) { receive_mobile = request.getParameter("receive_mobile"); if (!StringUtil.isEmpty(encoding)) { receive_mobile = StringUtil.to(receive_mobile, encoding); } } String trade_status = request.getParameter("trade_status"); // 交易状态 // 获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表(以上仅供参考)// // 计算得出通知验证结果 boolean verify_result = AlipayNotify.returnverify(params, key, partner); if (verify_result) { // 验证成功 ////////////////////////////////////////////////////////////////////////////////////////// // 请在这里加上商户的业务逻辑程序代码 // ——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— if (trade_status.equals("WAIT_SELLER_SEND_GOODS")) { // 判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) // 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 // 如果有做过处理,不执行商户的业务程序 } if (trade_status.equals("TRADE_FINISHED")) { // 判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) // 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 // 如果有做过处理,不执行商户的业务程序 } this.paySuccess(order_no); return order_no; // ——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ////////////////////////////////////////////////////////////////////////////////////////// } else { throw new RuntimeException("验证失败"); } }
@Override public String onCallBack() { HttpServletRequest request = ThreadContextHolder.getHttpRequest(); Map<String, String> configparams = this.getConfigParams(); String partner = configparams.get("partner"); // partner合作伙伴id(必须填写) String key = configparams.get("key"); // partner 的对应交易安全校验码(必须填写) String encoding = configparams.get("callback_encoding"); // 获取支付宝POST过来反馈信息 Map<String, String> params = new HashMap<String, String>(); Map requestParams = request.getParameterMap(); for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) { String name = (String) iter.next(); String[] values = (String[]) requestParams.get(name); String valueStr = ""; for (int i = 0; i < values.length; i++) { valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ","; } if (!StringUtil.isEmpty(encoding)) { valueStr = StringUtil.to(valueStr, encoding); } params.put(name, valueStr); } // 获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表(以下仅供参考)// String trade_no = request.getParameter("trade_no"); // 支付宝交易号 String order_no = request.getParameter("out_trade_no"); // 获取订单号 String total_fee = request.getParameter("price"); // 获取总金额 String subject = request.getParameter("subject"); // 商品名称、订单名称 if (!StringUtil.isEmpty(encoding)) { subject = StringUtil.to(subject, encoding); } String body = ""; if (request.getParameter("body") != null) { body = request.getParameter("body"); // 商品描述、订单备注、描述 if (!StringUtil.isEmpty(encoding)) { body = StringUtil.to(body, encoding); } } String buyer_email = request.getParameter("buyer_email"); // 买家支付宝账号 String receive_name = ""; // 收货人姓名 if (request.getParameter("receive_name") != null) { receive_name = request.getParameter("receive_name"); if (!StringUtil.isEmpty(encoding)) { receive_name = StringUtil.to(receive_name, encoding); } } String receive_address = ""; // 收货人地址 if (request.getParameter("receive_address") != null) { receive_address = request.getParameter("receive_address"); if (!StringUtil.isEmpty(encoding)) { receive_address = StringUtil.to(receive_address, encoding); } } String receive_zip = ""; // 收货人邮编 if (request.getParameter("receive_zip") != null) { receive_zip = request.getParameter("receive_zip"); if (!StringUtil.isEmpty(encoding)) { receive_zip = StringUtil.to(receive_zip, encoding); } } String receive_phone = ""; // 收货人电话 if (request.getParameter("receive_phone") != null) { receive_phone = request.getParameter("receive_phone"); if (!StringUtil.isEmpty(encoding)) { receive_phone = StringUtil.to(receive_phone, encoding); } } String receive_mobile = ""; // 收货人手机 if (request.getParameter("receive_mobile") != null) { receive_mobile = request.getParameter("receive_mobile"); if (!StringUtil.isEmpty(encoding)) { receive_mobile = StringUtil.to(receive_mobile, encoding); } } String trade_status = request.getParameter("trade_status"); // 交易状态 // 获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表(以上仅供参考)// if (AlipayNotify.callbackverify(params, key, partner)) { // 验证成功 ////////////////////////////////////////////////////////////////////////////////////////// // 请在这里加上商户的业务逻辑程序代码 this.paySuccess(order_no); // ——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— this.logger.info("异步校验订单[" + order_no + "]成功"); if (trade_status.equals("WAIT_BUYER_PAY")) { // 该判断表示买家已在支付宝交易管理中产生了交易记录,但没有付款 // 判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) // 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 // 如果有做过处理,不执行商户的业务程序 return ("success"); // 请不要修改或删除 } else if (trade_status.equals("WAIT_SELLER_SEND_GOODS")) { // 该判断表示买家已在支付宝交易管理中产生了交易记录且付款成功,但卖家没有发货 // 判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) // 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 // 如果有做过处理,不执行商户的业务程序 return ("success"); // 请不要修改或删除 } else if (trade_status.equals("WAIT_BUYER_CONFIRM_GOODS")) { // 该判断表示卖家已经发了货,但买家还没有做确认收货的操作 // 判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) // 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 // 如果有做过处理,不执行商户的业务程序 return ("success"); // 请不要修改或删除 } else if (trade_status.equals("TRADE_FINISHED")) { // 该判断表示买家已经确认收货,这笔交易完成 // 判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) // 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 // 如果有做过处理,不执行商户的业务程序 return ("success"); // 请不要修改或删除 } else { return ("success"); // 请不要修改或删除 } // ——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ////////////////////////////////////////////////////////////////////////////////////////// } else { // 验证失败 return ("fail"); } }
@Override public String onPay(PayCfg payCfg, Order order) { Map<String, String> params = paymentManager.getConfigParams(this.getId()); HttpServletRequest request = ThreadContextHolder.getHttpRequest(); HttpServletResponse response = ThreadContextHolder.getHttpResponse(); /* String show_url = this.getShowUrl(order); String notify_url = this.getCallBackUrl(payCfg); String return_url =this.getReturnUrl(payCfg); */ //////////////////////////////////// 请求参数////////////////////////////////////// // 商户号 String bargainor_id = params.get("tenpaybid"); // 密钥 String key = params.get("tenpaykey"); // 回调通知URL String return_url = this.getCallBackUrl(payCfg); // 当前时间 yyyyMMddHHmmss String currTime = TenpayUtil.getCurrTime(); // 8位日期 String strDate = currTime.substring(0, 8); // 6位时间 String strTime = currTime.substring(8, currTime.length()); // 四位随机数 String strRandom = TenpayUtil.buildRandom(4) + ""; // 10位序列号,可以自行调整。 String strReq = strTime + strRandom; // 商家订单号,长度若超过32位,取前32位。财付通只记录商家订单号,不保证唯一。 String sp_billno = strReq; // 财付通交易单号,规则为:10位商户号+8位时间(YYYYmmdd)+10位流水号 String transaction_id = bargainor_id + strDate + strReq; // 创建PayRequestHandler实例 PayRequestHandler reqHandler = new PayRequestHandler(request, response); // 设置密钥 reqHandler.setKey(key); // 初始化 reqHandler.init(); // ----------------------------- // 设置支付参数 // ----------------------------- reqHandler.setParameter("cs", "utf-8"); // 编码类型 reqHandler.setParameter("bargainor_id", bargainor_id); // 商户号 reqHandler.setParameter("sp_billno", order.getSn()); // 商家订单号 reqHandler.setParameter("transaction_id", transaction_id); // 财付通交易单号 reqHandler.setParameter("return_url", return_url); // 支付通知url reqHandler.setParameter("desc", "订单编号:" + order.getSn()); // 商品名称 reqHandler.setParameter("total_fee", formatPrice(order.getOrder_amount() * 100)); // 商品金额,以分为单位 // 用户ip,测试环境时不要加这个ip参数,正式环境再加此参数 reqHandler.setParameter("spbill_create_ip", request.getRemoteAddr()); // 获取请求带参数的url String requestUrl = ""; try { requestUrl = reqHandler.getRequestURL(); reqHandler.doSend(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // 获取debug信息 String debuginfo = reqHandler.getDebugInfo(); return requestUrl; }