Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
8ab02652
Commit
8ab02652
authored
May 06, 2018
by
Junling Bu
Browse files
update[litemall-wx]: 小商场小程序端支持微信支付。
1. 删除原来pay.js,而是直接在下单页面和订单付款页面直引入微信支付api 2. 小商城后台服务的订单预支付会话api调整
parent
a0caba38
Changes
4
Hide whitespace changes
Inline
Side-by-side
litemall-wx/config/api.js
View file @
8ab02652
...
@@ -48,8 +48,6 @@ module.exports = {
...
@@ -48,8 +48,6 @@ module.exports = {
CartGoodsCount
:
WxApiRoot
+
'
cart/goodscount
'
,
// 获取购物车商品件数
CartGoodsCount
:
WxApiRoot
+
'
cart/goodscount
'
,
// 获取购物车商品件数
CartCheckout
:
WxApiRoot
+
'
cart/checkout
'
,
// 下单前信息确认
CartCheckout
:
WxApiRoot
+
'
cart/checkout
'
,
// 下单前信息确认
PayPrepayId
:
WxApiRoot
+
'
pay/prepay
'
,
//获取微信统一下单prepay_id
CollectList
:
WxApiRoot
+
'
collect/list
'
,
//收藏列表
CollectList
:
WxApiRoot
+
'
collect/list
'
,
//收藏列表
CollectAddOrDelete
:
WxApiRoot
+
'
collect/addordelete
'
,
//添加或取消收藏
CollectAddOrDelete
:
WxApiRoot
+
'
collect/addordelete
'
,
//添加或取消收藏
...
@@ -74,7 +72,7 @@ module.exports = {
...
@@ -74,7 +72,7 @@ module.exports = {
RegionList
:
WxApiRoot
+
'
region/list
'
,
//获取区域列表
RegionList
:
WxApiRoot
+
'
region/list
'
,
//获取区域列表
OrderSubmit
:
WxApiRoot
+
'
order/submit
'
,
// 提交订单
OrderSubmit
:
WxApiRoot
+
'
order/submit
'
,
// 提交订单
OrderPay
:
WxApiRoot
+
'
order/pay
'
,
//
支付
订单
OrderP
rep
ay
:
WxApiRoot
+
'
order/
pre
pay
'
,
// 订单
的预支付会话
OrderList
:
WxApiRoot
+
'
order/list
'
,
//订单列表
OrderList
:
WxApiRoot
+
'
order/list
'
,
//订单列表
OrderDetail
:
WxApiRoot
+
'
order/detail
'
,
//订单详情
OrderDetail
:
WxApiRoot
+
'
order/detail
'
,
//订单详情
OrderCancel
:
WxApiRoot
+
'
order/cancel
'
,
//取消订单
OrderCancel
:
WxApiRoot
+
'
order/cancel
'
,
//取消订单
...
...
litemall-wx/pages/payResult/payResult.js
View file @
8ab02652
var
util
=
require
(
'
../../utils/util.js
'
);
var
util
=
require
(
'
../../utils/util.js
'
);
var
api
=
require
(
'
../../config/api.js
'
);
var
api
=
require
(
'
../../config/api.js
'
);
const
pay
=
require
(
'
../../services/pay.js
'
);
var
app
=
getApp
();
var
app
=
getApp
();
Page
({
Page
({
...
@@ -32,36 +31,57 @@ Page({
...
@@ -32,36 +31,57 @@ Page({
},
},
payOrder
()
{
payOrder
()
{
let
that
=
this
;
let
that
=
this
;
//
目前不能支持微信支付,这里仅仅是
模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已
// 模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已
wx
.
showModal
({
//
wx.showModal({
title
:
'
目前不能微信支付
'
,
//
title: '目前不能微信支付',
content
:
'
点击确定模拟支付成功,点击取消模拟未支付成功
'
,
//
content: '点击确定模拟支付成功,点击取消模拟未支付成功',
success
:
function
(
res
)
{
//
success: function (res) {
if
(
res
.
confirm
)
{
//
if (res.confirm) {
util
.
request
(
api
.
OrderPay
,
{
orderId
:
that
.
data
.
orderId
},
'
POST
'
).
then
(
res
=>
{
//
util.request(api.OrderP
rep
ay, { orderId: that.data.orderId }, 'POST').then(res => {
if
(
res
.
errno
===
0
)
{
//
if (res.errno === 0) {
that
.
setData
({
//
that.setData({
status
:
true
//
status: true
});
//
});
}
//
}
else
{
//
else {
util
.
showErrorToast
(
'
支付失败
'
);
//
util.showErrorToast('支付失败');
}
//
}
});
//
});
}
//
}
else
if
(
res
.
cancel
)
{
//
else if (res.cancel) {
util
.
showErrorToast
(
'
支付失败
'
);
//
util.showErrorToast('支付失败');
}
//
}
// }
// });
util
.
request
(
api
.
OrderPrepay
,
{
orderId
:
that
.
data
.
orderId
},
'
POST
'
).
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
const
payParam
=
res
.
data
;
console
.
log
(
"
支付过程开始
"
)
wx
.
requestPayment
({
'
timeStamp
'
:
payParam
.
timeStamp
,
'
nonceStr
'
:
payParam
.
nonceStr
,
'
package
'
:
payParam
.
packageValue
,
'
signType
'
:
payParam
.
signType
,
'
paySign
'
:
payParam
.
paySign
,
'
success
'
:
function
(
res
)
{
console
.
log
(
"
支付过程成功
"
)
that
.
setData
({
status
:
true
});
},
'
fail
'
:
function
(
res
)
{
console
.
log
(
"
支付过程失败
"
)
util
.
showErrorToast
(
'
支付失败
'
);
},
'
complete
'
:
function
(
res
)
{
console
.
log
(
"
支付过程结束
"
)
}
});
}
}
});
});
// pay.payOrder(this.data.orderId).then(res => {
// this.setData({
// status: true
// });
// }).catch(res => {
// util.showErrorToast('支付失败');
// });
}
}
})
})
\ No newline at end of file
litemall-wx/pages/shopping/checkout/checkout.js
View file @
8ab02652
var
util
=
require
(
'
../../../utils/util.js
'
);
var
util
=
require
(
'
../../../utils/util.js
'
);
var
api
=
require
(
'
../../../config/api.js
'
);
var
api
=
require
(
'
../../../config/api.js
'
);
const
pay
=
require
(
'
../../../services/pay.js
'
);
var
app
=
getApp
();
var
app
=
getApp
();
...
@@ -106,47 +105,69 @@ Page({
...
@@ -106,47 +105,69 @@ Page({
if
(
res
.
errno
===
0
)
{
if
(
res
.
errno
===
0
)
{
const
orderId
=
res
.
data
.
orderId
;
const
orderId
=
res
.
data
.
orderId
;
// 目前不能支持微信支付,这里仅仅是模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已
// 模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已
wx
.
showModal
({
// wx.showModal({
title
:
'
目前不能微信支付
'
,
// title: '目前不能微信支付',
content
:
'
点击确定模拟支付成功,点击取消模拟未支付成功
'
,
// content: '点击确定模拟支付成功,点击取消模拟未支付成功',
success
:
function
(
res
)
{
// success: function(res) {
if
(
res
.
confirm
)
{
// if (res.confirm) {
util
.
request
(
api
.
OrderPay
,
{
orderId
:
orderId
},
'
POST
'
).
then
(
res
=>
{
// util.request(api.OrderPrepay, { orderId: orderId }, 'POST').then(res => {
if
(
res
.
errno
===
0
)
{
// if (res.errno === 0) {
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=1&orderId=' + orderId
// });
// }
// else{
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=0&orderId=' + orderId
// });
// }
// });
// }
// else if (res.cancel) {
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=0&orderId=' + orderId
// });
// }
// }
// });
util
.
request
(
api
.
OrderPrepay
,
{
orderId
:
orderId
},
'
POST
'
).
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
const
payParam
=
res
.
data
;
console
.
log
(
"
支付过程开始
"
)
wx
.
requestPayment
({
'
timeStamp
'
:
payParam
.
timeStamp
,
'
nonceStr
'
:
payParam
.
nonceStr
,
'
package
'
:
payParam
.
packageValue
,
'
signType
'
:
payParam
.
signType
,
'
paySign
'
:
payParam
.
paySign
,
'
success
'
:
function
(
res
)
{
console
.
log
(
"
支付过程成功
"
)
wx
.
redirectTo
({
wx
.
redirectTo
({
url
:
'
/pages/payResult/payResult?status=1&orderId=
'
+
orderId
url
:
'
/pages/payResult/payResult?status=1&orderId=
'
+
orderId
});
});
}
},
else
{
'
fail
'
:
function
(
res
)
{
console
.
log
(
"
支付过程失败
"
)
wx
.
redirectTo
({
wx
.
redirectTo
({
url
:
'
/pages/payResult/payResult?status=0&orderId=
'
+
orderId
url
:
'
/pages/payResult/payResult?status=0&orderId=
'
+
orderId
});
});
},
'
complete
'
:
function
(
res
)
{
console
.
log
(
"
支付过程结束
"
)
}
}
});
});
}
}
else
if
(
res
.
cancel
)
{
});
wx
.
redirectTo
({
url
:
'
/pages/payResult/payResult?status=0&orderId=
'
+
orderId
});
}
}
});
// pay.payOrder(orderId).then(res => {
}
else
{
// wx.redirectTo({
wx
.
redirectTo
({
// url: '/pages/payResult/payResult?status=1&orderId=' + orderId
url
:
'
/pages/payResult/payResult?status=0&orderId=
'
+
orderId
// });
});
// }).catch(res => {
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=0&orderId=' + orderId
// });
// });
// } else {
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=0&orderId=' + orderId
// });
}
}
});
});
}
}
...
...
litemall-wx/services/pay.js
deleted
100644 → 0
View file @
a0caba38
/**
* 支付相关服务
*/
const
util
=
require
(
'
../utils/util.js
'
);
const
api
=
require
(
'
../config/api.js
'
);
/**
* 判断用户是否登录
*/
function
payOrder
(
orderId
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
util
.
request
(
api
.
PayPrepayId
,
{
orderId
:
orderId
}).
then
((
res
)
=>
{
console
.
log
(
res
)
if
(
res
.
errno
===
0
)
{
const
payParam
=
res
.
data
;
wx
.
requestPayment
({
'
timeStamp
'
:
payParam
.
timeStamp
,
'
nonceStr
'
:
payParam
.
nonceStr
,
'
package
'
:
payParam
.
package
,
'
signType
'
:
payParam
.
signType
,
'
paySign
'
:
payParam
.
paySign
,
'
success
'
:
function
(
res
)
{
resolve
(
res
);
},
'
fail
'
:
function
(
res
)
{
reject
(
res
);
},
'
complete
'
:
function
(
res
)
{
reject
(
res
);
}
});
}
else
{
reject
(
res
);
}
});
});
}
module
.
exports
=
{
payOrder
,
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment