陈晨辰 · 2020年02月11日

【笔记6-支付及订单模块】从0开始 独立完成企业级Java电商网站开发(服务端)

支付模块

实际开发工作中经常会遇见如下场景,一个支付模块,一个订单模块,有一定依赖,一个同事负责支付模块,另一个同事负责订单模块,但是开发支付模块的时候要依赖订单模块的相关类 ,方法,或者工具类,这些还没开发出来,看不到一个完整的订单业务逻辑,可能只拿到了订单的Order类,但是呢不能影响我们后端的并行开发,就像前端和后端之间的并行开发,后端之间也有并行开发,后端的项目有时候是非常大的,这个时候该怎么办,本章支付模块和下节订单模块就要模拟这种场景,提高自己的胜任跨业务开发的抽象开发能力,这种能力再开发大型项目的时候非常重要,而且是衡量一个优秀开发者非常重要的标准,比如在面试的时候经常会问到这样问题来此判断这个面试者是否有开发大型项目的经验或者潜力,与此同时,还有一个重要目的,为了考虑后面的进阶课程,会把项目演进到拆分微服务和进行dubbo服务化的时候,我们只能拿到一个接口和一个类,什么都看不到,具体的实现都在远程的rpc服务端,这种场景的开发正是需要跨业务的一定抽象开发能力

数据库表设计

支付信息表
file

CREATE TABLE‘ mmall_ pay_ info’ (
'id' int(11) NOT NULL AUTO_ INCREMENT,
'user_ id' int(11) DEFAULT NULL COMMENT . 用户id',
'order_ no' bigint(20) DEFAULT NULL COMMENT '订单号'
'pay_ platform' int(10) DEFAULT NULL COMMENT ' 支付平台:1-支付宝,2-微信',
'platform_ number' varchar (200) DEFAULT NULL COMMENT ' 支付宝支付流水号' ,
'platform_ _status' varchar(20) DEFAULT NULL COMMENT ' 支付宝支付状态' ,
'create_ time' datetime DEFAULT NULL COMMENT ' 创建时间,
'update_ time' datetime DEFAULT NULL COMMENT ' 更新时间',
PRIMARY KEY ( id')
) ENGINE= InnoDB AUTO_ INCREMENT=53 DEFAULT CHARSET=utf8

功能

  • 支付宝对接

file

file

  • 支付回调

file

  • 查询支付状态

支付宝对接对接流程

1、首先得有一个支付宝账号,(注册蚂蚁金服开发平台账号)

2、创建应用,因为我们是自己开发或者公司开发,所以要创建自研型应用(自研型应用分为网页移动应用,AR,生活号,小程序),创建应用得过程中:

a) 需要一个用户名和一个logo(应用图标,因为我是自己学习,可以在线网站免费设计一个),填写完毕之后确认创建,之后就可以在应用列表中看到创建得应用,一般情况下会进入下一个页面填写应用的更多详细信息

file

b) 进入下面页面

file

c) 关于应用网关和授权回调地址,单纯的支付接口是不需要配置这两个信息的,简单来说就是:应用网关是用于接收口碑或是生活号的信息的,授权回调地址是第三方授权或是用户信息授权使用的,如果用不到是可以不配置的!

d) 下面就静等审核(说是一个工作日)

涉及知识点

  • 熟悉支付宝对接核心文档,调通支付宝支付功能官方Demo
  • 解析支付宝SDK对接源码
  • RSA1和RSA2验证签名及加解密
  • 避免支付宝重复通知和数据校验
  • natapp外网穿透和tomcat remote debug
  • 生成二维码,并持久化到图片服务器

接口设计

【前台】

1.支付

/order/pay.do

http://localhost:8080/order/pay.do?orderNo=1485158676346

request
orderNo
response

success

{
    "status": 0,
    "data": {
        "orderNo": "1485158676346",
        "qrPath": "http://img.happymmall.com/qr-1492329044075.png"
    }
}

2.查询订单支付状态

/order/query_order_pay_status.do

http://localhost:8080/order/query_order_pay_status.do?orderNo=1485158676346

request
orderNo
response

success

{
    "status": 0,
    "data": true
}

3.支付宝回调

参考支付宝回调文档:
https://support.open.alipay.c...

/order/alipay_callback.do

request
HttpServletRequest
response

success

success

订单模块

数据库表设计

订单表
file

CREATE TABLE mmall_ order’(
'id' int(11) NOT NULL AUTO_ INCREMENT COMMENT '订单id',
'order_ no'   bigint(20) DEFAULT NULL COMMENT '订单号',
'user_ id'  int(11) DEFAULT NULL COMMENT '用户id' ,
'shipping_ id' int(11) DEFAULT NULL,
'payment' decimal(20,2) DEFAULT NULL COMMENT ' 实际付款金额,单位是元,保留两位小数',
'payment_ type'  int(4) DEFAULT NULL COMMENT ' 支付类型,1-在线支付' ,
'postage'  int(10) DEFAULT NULL COMMENT ' 运费,单位是元',
'status' int(10) DEFAULT NULL COMMENT '订单状态:0-已取消-10- 未付款,20-已付款, 40-已发货,50- 交易成功,60- 交易关闭",
'payment_time' datetime DEFAULT NULL COMMENT ' 支付时间',
'send_ time' datetime DEFAULT NULL COMMENT ' 发货时间,
'end. time' datetime DEFAULT NULL COMHENT ‘交易 完成时间',
'close_ time' datetine DEFAULT NULL COMMENT ‘交 易关闭时间',
'create_ _time' datetime DEFAULT NULL COMMENT ' 创建时间",
'update_ time' datetime DEFAULT NULL COMMENT ' 更新时间' ,
PRIHARY KEY ( id'),
UNIQUE KEY“ order_ _no_ index" (order_ no') USING BTREE
) ENGINE-InnoDB AUTO INCREMENT-103 DEFAULT CHARSET=utf8

订单明细表
file

CREATE TABLE: mmall_ order_ item’(
'id' int(11) NOT NULL AUTO_ ,INCREMENT COMMENT '订单子表id' ,
'user_ id'  int(11) DEFAULT NULL,
'order_ no' bigint(20) DEFAULT NULL,
'product_ id' int(11) DEFAULT NULL COMNENT .商晶id',
'product_ name' varchar(100) DEFAULT NULL COMMENT ' 商品名称',
'product_ image' varchar(500) DEFAULT NULL COMNENT ' 商品图片地址,
'current _unit_ price' decimal(20,2) DEFAULT NULL COMNENT '生成订单时的商品单价,单位是元,保留两位小数' , .
'quantity' int(10) DEFAULT NULL COMMENT 商品数量
'total_ price' decimal(20,2) DEFAULT NULL COMMENT "商品总价,单位是元,保留两位小数' ,
'create_ time' datetime DEFAULT NULL,
'update_ time' datetime DEFAULT NULL,
PRIMARY KEY ( id'),
KEY 'order_ no_ index'  ('order. no' ) USING BTREE,
KEY 'order_ no_user_ id_ index' ('user_ _id' ,'order_ no') USING BTREE
) ENGINE: =InnoDB AUTO_ INCREMENT-113 DEFAULT CHARSET=utf8

功能

前台功能

创建订单
商品信息
订单列表
订单详情
取消订单

后台功能

订单列表
订单搜索
订单详情
订单发货

涉及知识点

  • 避免业务逻辑中横向越权和纵向越权等安全漏洞
  • 设计实用、安全、扩展性强大的常量、枚举类
  • 订单号生成规则、订单严谨性判断
  • POJO和VO之间的实际操练
  • mybatis批量插入

接口设计

【前台】

1.创建订单

/order/create.do

引用已存在的收货地址id
http://localhost:8080/order/create.do?shippingId=5

request
shippingId
response

success

{
    "status": 0,
    "data": {
        "orderNo": 1485158223095,
        "payment": 2999.11,
        "paymentType": 1,
        "postage": 0,
        "status": 10,
        "paymentTime": null,
        "sendTime": null,
        "endTime": null,
        "closeTime": null,
        "createTime": 1485158223095,
        "orderItemVoList": [
            {
                "orderNo": 1485158223095,
                "productId": 2,
                "productName": "oppo R8",
                "productImage": "mainimage.jpg",
                "currentUnitPrice": 2999.11,
                "quantity": 1,
                "totalPrice": 2999.11,
                "createTime": null
            }
        ],
        "shippingId": 5,
        "shippingVo": null
    }
}

2.获取订单的商品信息

/order/get_order_cart_product.do

http://localhost:8080/order/get_order_cart_product.do

request
response

success

{
    "status": 0,
    "data": {
        "orderItemVoList": [
            {
                "orderNo": null,
                "productId": 1,
                "productName": "iphone7",
                "productImage": "mmall/aa.jpg",
                "currentUnitPrice": 7999,
                "quantity": 10,
                "totalPrice": 79990,
                "createTime": ""
            }
        ],
        "imageHost": "http://img.happymmall.com/",
        "productTotalPrice": 79990
    }
}

3.订单List

http://localhost:8080/order/list.do?pageSize=3

/order/list.do

request
pageSize(default=10)
pageNum(default=1)
response

success

{
  "status": 0,
  "data": {
    "pageNum": 1,
    "pageSize": 3,
    "size": 3,
    "orderBy": null,
    "startRow": 1,
    "endRow": 3,
    "total": 16,
    "pages": 6,
    "list": [
      {
        "orderNo": 1485158676346,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:36",
        "orderItemVoList": [
          {
            "orderNo": 1485158676346,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:36"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675516,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675516,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675316,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675316,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      }
    ],
    "firstPage": 1,
    "prePage": 0,
    "nextPage": 2,
    "lastPage": 6,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2,
      3,
      4,
      5,
      6
    ]
  }
}

4.订单详情detail

http://localhost:8080/order/detail.do?orderNo=1480515829406

/order/detail.do

request
orderNo
response

success

{
  "status": 0,
  "data": {
    "orderNo": 1480515829406,
    "payment": 30000.00,
    "paymentType": 1,
    "paymentTypeDesc": "在线支付",
    "postage": 0,
    "status": 10,
    "statusDesc": "未支付",
    "paymentTime": "",
    "sendTime": "",
    "endTime": "",
    "closeTime": "",
    "createTime": "2016-11-30 22:23:49",
    "orderItemVoList": [
      {
        "orderNo": 1480515829406,
        "productId": 1,
        "productName": "iphone7",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 10000.00,
        "quantity": 1,
        "totalPrice": 10000.00,
        "createTime": "2016-11-30 22:23:49"
      },
      {
        "orderNo": 1480515829406,
        "productId": 2,
        "productName": "oppo R8",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 20000.00,
        "quantity": 1,
        "totalPrice": 20000.00,
        "createTime": "2016-11-30 22:23:49"
      }
    ],
    "imageHost": "http://img.happymmall.com/",
    "shippingId": 3,
    "receiverName": "geely",
    "shippingVo": {
      "receiverName": "geely",
      "receiverPhone": "0100",
      "receiverMobile": "186",
      "receiverProvince": "北京",
      "receiverCity": "北京",
      "receiverDistrict": "昌平区",
      "receiverAddress": "矩阵小区",
      "receiverZip": "100000"
    }
  }
}

5.取消订单

http://localhost:8080/order/cancel.do?orderNo=1480515829406

/order/cancel.do

request
orderNo
response

success

{
  "status": 0
}

【后台】

1.订单List

http://localhost:8080/manage/order/list.do?pageSize=3

/manage/order/list.do

request
pageSize(default=10)
pageNum(default=1)
response

success

{
  "status": 0,
  "data": {
    "pageNum": 1,
    "pageSize": 3,
    "size": 3,
    "orderBy": null,
    "startRow": 1,
    "endRow": 3,
    "total": 16,
    "pages": 6,
    "list": [
      {
        "orderNo": 1485158676346,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:36",
        "orderItemVoList": [
          {
            "orderNo": 1485158676346,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:36"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "shippingVo": null
      },
      {
        "orderNo": 1485158675516,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675516,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675316,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675316,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      }
    ],
    "firstPage": 1,
    "prePage": 0,
    "nextPage": 2,
    "lastPage": 6,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2,
      3,
      4,
      5,
      6
    ]
  }
}

2.按订单号查询

http://localhost:8080/manage/order/search.do?orderNo=1480515829406

/manage/order/search.do

request
orderNo
response

success

{
  "status": 0,
  "data": {
    "pageNum": 1,
    "pageSize": 3,
    "size": 3,
    "orderBy": null,
    "startRow": 1,
    "endRow": 3,
    "total": 16,
    "pages": 6,
    "list": [
      {
        "orderNo": 1485158676346,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:36",
        "orderItemVoList": [
          {
            "orderNo": 1485158676346,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:36"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "shippingVo": null
      },
      {
        "orderNo": 1485158675516,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675516,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675316,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "在线支付",
        "postage": 0,
        "status": 10,
        "statusDesc": "未支付",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675316,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      }
    ],
    "firstPage": 1,
    "prePage": 0,
    "nextPage": 2,
    "lastPage": 6,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2,
      3,
      4,
      5,
      6
    ]
  }
}

3.订单详情

http://localhost:8080/manage/order/detail.do?orderNo=1480515829406

/manage/order/detail.do

request
orderNo
response

success

{
  "status": 0,
  "data": {
    "orderNo": 1480515829406,
    "payment": 30000.00,
    "paymentType": 1,
    "paymentTypeDesc": "在线支付",
    "postage": 0,
    "status": 10,
    "statusDesc": "未支付",
    "paymentTime": "",
    "sendTime": "",
    "endTime": "",
    "closeTime": "",
    "createTime": "2016-11-30 22:23:49",
    "orderItemVoList": [
      {
        "orderNo": 1480515829406,
        "productId": 1,
        "productName": "iphone7",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 10000.00,
        "quantity": 1,
        "totalPrice": 10000.00,
        "createTime": "2016-11-30 22:23:49"
      },
      {
        "orderNo": 1480515829406,
        "productId": 2,
        "productName": "oppo R8",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 20000.00,
        "quantity": 1,
        "totalPrice": 20000.00,
        "createTime": "2016-11-30 22:23:49"
      }
    ],
    "imageHost": "http://img.happymmall.com/",
    "shippingId": 3,
    "receiverName": "geely",
    "shippingVo": {
      "receiverName": "geely",
      "receiverPhone": "0100",
      "receiverMobile": "186",
      "receiverProvince": "北京",
      "receiverCity": "北京",
      "receiverDistrict": "昌平区",
      "receiverAddress": "矩阵小区",
      "receiverZip": "100000"
    }
  }
}

4.订单发货

http://localhost:8080/manage/order/send_goods.do?orderNo=1480515829406

/manage/order/send_goods.do

request
orderNo
response

success

{
  "status": 0,
  "data": "发货成功"
}
推荐阅读
关注数
2
文章数
95
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息