在此承诺只做技术分享
查看专栏=V
背景
国家经济飞速发展,人们的收入大幅度提升,传统的线下购物模式很难满足人们的生活需求。因此,国内网上购物平台的迅速崛起是势在必得。比如当下的淘宝,京东以及苏宁易购等,这些大型的网上购物平台每天的访问量以及成交量是不可估量的,并且面向的对象是大众。
系统设计
前端:easyui+echarts
后端:ssm
数据库:mysql
该系统功能模块前台主要有商品首页展示,商品分类,关键字搜索,个人信息管理,购物车,收藏商品,登录注册,退换货,评价,敏感词屏蔽,支付宝沙箱支付;后台主要有商品管理,订单管理,用户管理,物流管理,退换货管理等
前台业务流程图
后台业务流程图
功能结构图
支付宝沙箱接入
public class AlipayConfig {//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓// 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号public static String app_id = "";// 商户私钥,您的PKCS8格式RSA2私钥public static String merchant_private_key = "";// 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。public static String alipay_public_key = "";// 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问public static String notify_url = "http://127.0.0.1:8080/EasyBuy/pay/notify";// 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问public static String return_url = "http://127.0.0.1:8080/EasyBuy/home/index";// 签名方式public static String sign_type = "RSA2";// 字符编码格式public static String charset = "utf-8";// 支付宝网关public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";// 支付宝网关public static String log_path = "C:\\";//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑/** * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)* @param sWord 要写入日志里的文本内容*/public static void logResult(String sWord) {FileWriter writer = null;try {writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");writer.write(sWord);} catch (Exception e) {e.printStackTrace();} finally {if (writer != null) {try {writer.close();} catch (IOException e) {e.printStackTrace();}}}}
}
调用支付宝功能
@RequestMapping("/pay")
@Controller
public class PayController {@Autowiredprivate OrderService orderService;@Autowiredprivate CartService cartService;@RequestMapping(value = "/gopay", produces="text/html; charest=utf-8")@ResponseBodypublic String gopay(Long orderId, Long money,HttpServletRequest request, HttpServletRequest response) throws AlipayApiException{Order order = orderService.findById(orderId);Map<String, Object> queryMap = new HashMap<String, Object>();List<Cart> cartList = cartService.findList(queryMap);double orderAmount = 0;for(Cart cart:cartList){OrderItem orderItem = new OrderItem();orderItem.setMoney(cart.getMoney());orderItem.setPrice(cart.getPrice());orderAmount += cart.getMoney();}orderAmount = money;//获得初始化的AlipayClientAlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);//设置请求参数AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();alipayRequest.setReturnUrl(AlipayConfig.return_url);alipayRequest.setNotifyUrl(AlipayConfig.notify_url);//商户订单号,商户网站订单系统中唯一订单号,必填String out_trade_no = order.getSn();//付款金额,必填String total_amount = orderAmount + "";//订单名称,必填String subject = "Test";//商品描述,可空String body = "";alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\"," + "\"total_amount\":\""+ total_amount +"\"," + "\"subject\":\""+ subject +"\"," + "\"body\":\""+ body +"\"," + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");//若想给BizContent增加其他可选请求参数,以增加自定义超时时间参数timeout_express来举例说明//alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\"," // + "\"total_amount\":\""+ total_amount +"\"," // + "\"subject\":\""+ subject +"\"," // + "\"body\":\""+ body +"\"," // + "\"timeout_express\":\"10m\"," // + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");//请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节//请求String result = alipayClient.pageExecute(alipayRequest).getBody();return result;}@RequestMapping(value = "/notify")@ResponseBodypublic String notify(Long orderId,HttpServletRequest request, HttpServletRequest response) throws AlipayApiException, UnsupportedEncodingException{Map<String,String> params = new HashMap<String,String>();Map<String,String[]> requestParams = request.getParameterMap();for (Iterator<String> 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] + ",";}//乱码解决,这段代码在出现乱码时使用valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");params.put(name, valueStr);}boolean signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type); //调用SDK验证签名//——请在这里编写您的程序(以下代码仅作参考)——/* 实际验证过程建议商户务必添加以下校验:1、需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)4、验证app_id是否为该商户本身。*/if(signVerified) {//验证成功//商户订单号String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");//支付宝交易号String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");//交易状态String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"),"UTF-8");if(trade_status.equals("TRADE_FINISHED")){//判断该笔订单是否在商户网站中已经做过处理//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序//如果有做过处理,不执行商户的业务程序//注意://退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知}else if (trade_status.equals("TRADE_SUCCESS")){//判断该笔订单是否在商户网站中已经做过处理//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序//如果有做过处理,不执行商户的业务程序//注意://付款完成后,支付宝系统发送该交易状态通知}}else {//验证失败//调试用,写文本函数记录程序运行情况是否正常//String sWord = AlipaySignature.getSignCheckContentV1(params);//AlipayConfig.logResult(sWord);}return "success";//——请在这里编写您的程序(以上代码仅作参考)——}@RequestMapping(value = "/return")@ResponseBodypublic String return_url(Long orderId,HttpServletRequest request, HttpServletRequest response) throws AlipayApiException{//Order order = orderService.findById(orderId);Map<String, Object> queryMap = new HashMap<String, Object>();List<Cart> cartList = cartService.findList(queryMap);double orderAmount = orderId;for(Cart cart:cartList){OrderItem orderItem = new OrderItem();orderItem.setMoney(cart.getMoney());orderItem.setPrice(cart.getPrice());orderAmount += cart.getMoney();}//获得初始化的AlipayClientAlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);//设置请求参数AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();alipayRequest.setReturnUrl(AlipayConfig.return_url);alipayRequest.setNotifyUrl(AlipayConfig.notify_url);//商户订单号,商户网站订单系统中唯一订单号,必填String out_trade_no = orderId.toString();//付款金额,必填String total_amount = orderAmount + "";//订单名称,必填String subject = "Test";//商品描述,可空String body = "";alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\"," + "\"total_amount\":\""+ total_amount +"\"," + "\"subject\":\""+ subject +"\"," + "\"body\":\""+ body +"\"," + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");//若想给BizContent增加其他可选请求参数,以增加自定义超时时间参数timeout_express来举例说明//alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\"," // + "\"total_amount\":\""+ total_amount +"\"," // + "\"subject\":\""+ subject +"\"," // + "\"body\":\""+ body +"\"," // + "\"timeout_express\":\"10m\"," // + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");//请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节//请求String result = alipayClient.pageExecute(alipayRequest).getBody();return result;}}
功能展示
关键词搜索
购物车
确认订单
支付订单
订单列表
退换货列表
评价列表
后台登录
商品管理
订单管理
评价管理
物流管理
退换货管理
以上展示部分的功能模块
本人承诺只做技术分享
查看专栏—》V