支付模塊
實際開發工作中經常會遇見如下場景,一個支付模塊,一個訂單模塊,有一定依賴,一個同事負責支付模塊,另一個同事負責訂單模塊,但是開發支付模塊的時候要依賴訂單模塊的相關類 ,方法,或者工具類,這些還沒開發出來,看不到一個完整的訂單業務邏輯,可能只拿到了訂單的Order類,但是呢不能影響我們后端的並行開發,就像前端和后端之間的並行開發,后端之間也有並行開發,后端的項目有時候是非常大的,這個時候該怎么辦,本章支付模塊和下節訂單模塊就要模擬這種場景,提高自己的勝任跨業務開發的抽象開發能力,這種能力再開發大型項目的時候非常重要,而且是衡量一個優秀開發者非常重要的標准,比如在面試的時候經常會問到這樣問題來此判斷這個面試者是否有開發大型項目的經驗或者潛力,與此同時,還有一個重要目的,為了考慮后面的進階課程,會把項目演進到拆分微服務和進行dubbo服務化的時候,我們只能拿到一個接口和一個類,什么都看不到,具體的實現都在遠程的rpc服務端,這種場景的開發正是需要跨業務的一定抽象開發能力
數據庫表設計
支付信息表
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
功能
- 支付寶對接
- 支付回調
- 查詢支付狀態
支付寶對接對接流程
1、首先得有一個支付寶賬號,(注冊螞蟻金服開發平台賬號)
2、創建應用,因為我們是自己開發或者公司開發,所以要創建自研型應用(自研型應用分為網頁移動應用,AR,生活號,小程序),創建應用得過程中:
a) 需要一個用戶名和一個logo(應用圖標,因為我是自己學習,可以在線網站免費設計一個),填寫完畢之后確認創建,之后就可以在應用列表中看到創建得應用,一般情況下會進入下一個頁面填寫應用的更多詳細信息
b) 進入下面頁面
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.支付寶回調
/order/alipay_callback.do
request
HttpServletRequest
response
success
success
訂單模塊
數據庫表設計
訂單表
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
訂單明細表
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": "發貨成功"
}