Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
姜枫
9 years ago
Commit
ccd5582a8f26a208a0fd64dc642e2a17c4013120
1 parent
dcdcff6d
alipay
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
121 additions
and
12 deletions
apps/shopping/controllers/pay.js
apps/shopping/helpers/pay.js
apps/shopping/helpers/pay/alipay.js
apps/shopping/helpers/pay/common.js
apps/shopping/helpers/pay/sign.js
apps/shopping/models/pay.js
apps/shopping/router.js
config/common.js
apps/shopping/controllers/pay.js
View file @
ccd5582
...
...
@@ -32,12 +32,15 @@ const toPay = (req, res, next) => {
let
orderCode
=
req
.
query
.
code
;
let
method
=
req
.
query
.
method
;
let
uid
=
req
.
user
.
uid
;
let
user
=
req
.
user
;
method
=
parseInt
(
method
,
10
);
OrderData
.
orderDetail
(
uid
,
orderCode
).
then
(
result
=>
{
if
(
result
&&
result
.
data
)
{
let
order
=
camelCase
(
result
.
data
);
return
PayHelpers
.
pay
(
order
,
method
);
return
PayHelpers
.
pay
(
user
,
order
,
method
);
}
else
{
return
{
code
:
400
,
...
...
apps/shopping/helpers/pay.js
View file @
ccd5582
...
...
@@ -10,13 +10,20 @@ const PayData = require('../models/pay');
const
Alipay
=
require
(
'./pay/alipay'
);
const
Payment
=
{
pay
(
order
,
method
)
{
pay
(
user
,
order
,
method
)
{
return
PayData
.
getPaymentInfo
(
method
).
then
(
result
=>
{
console
.
log
(
result
);
if
(
method
===
'Alipay'
)
{
Alipay
.
pay
(
order
);
if
(
result
&&
result
.
id
===
method
)
{
if
(
method
===
2
)
{
return
Alipay
.
pay
(
user
,
order
,
result
);
}
}
else
{
return
{
code
:
400
,
message
:
'获取支付方式信息失败'
};
}
});
}
};
...
...
apps/shopping/helpers/pay/alipay.js
View file @
ccd5582
...
...
@@ -4,11 +4,47 @@
* @date: 16/7/22
*/
'use strict'
;
const
config
=
global
.
yoho
.
config
;
const
helpers
=
global
.
yoho
.
helpers
;
const
common
=
require
(
'./common'
);
const
sign
=
require
(
'./sign'
);
const
md5
=
global
.
yoho
.
md5
;
const
ALIPAY_URL
=
"https://mapi.alipay.com/gateway.do"
;
const
Alipay
=
{
pay
(
order
,
config
)
{
console
.
log
(
order
,
config
);
pay
(
user
,
order
,
param
)
{
console
.
log
(
order
,
param
);
let
payParams
=
JSON
.
parse
(
param
.
payParams
);
let
params
=
{
service
:
'create_direct_pay_by_user'
,
partner
:
payParams
.
merchant_id
,
_input_charset
:
'utf-8'
,
notify_url
:
config
.
pay
.
serviceNotify
+
'payment/alipay_notify'
,
return_url
:
helpers
.
urlFormat
(
'shopping/pay/callback/alipay'
),
subject
:
'有货订单号:'
+
order
.
orderId
,
out_trade_no
:
order
.
orderCode
,
it_b_pay
:
common
.
getPayExpireMin
(
order
.
payExpire
)
+
'm'
,
total_fee
:
parseFloat
(
order
.
paymentAmount
,
10
)
*
100
,
payment_type
:
'1'
,
seller_email
:
payParams
.
merchant_other_code
,
sign_id_ext
:
user
.
uid
,
sign_name_ext
:
user
.
username
};
// TODO 防钓鱼配置,参考php
let
signStr
=
md5
(
sign
.
raw
(
params
)
+
payParams
.
merchant_key
);
let
body
=
sign
.
rawUncode
(
params
)
+
'&sign='
+
signStr
+
'&sign_type=MD5'
;
return
{
href
:
ALIPAY_URL
+
'?body='
+
body
};
}
};
...
...
apps/shopping/helpers/pay/common.js
0 → 100644
View file @
ccd5582
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/22
*/
'use strict'
;
const
moment
=
require
(
'moment'
);
const
common
=
{
getPayExpireMin
(
expire
)
{
let
defaultValue
=
120
;
if
(
expire
)
{
let
expireTime
=
moment
(
expire
,
'YYYY-MM-DD HH:mm:ss'
);
let
diff
=
expireTime
.
diff
(
moment
());
if
(
diff
>
0
)
{
return
Math
.
floor
(
diff
/
1000
/
60
);
}
else
{
return
defaultValue
;
}
}
else
{
return
defaultValue
;
}
}
};
module
.
exports
=
common
;
...
...
apps/shopping/helpers/pay/sign.js
View file @
ccd5582
...
...
@@ -3,3 +3,28 @@
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/22
*/
'use strict'
;
const
Sign
=
{
raw
(
args
)
{
let
keys
=
Object
.
keys
(
args
);
keys
=
keys
.
sort
();
return
keys
.
map
(
k
=>
{
return
'&'
+
k
.
toLowerCase
()
+
'='
+
args
[
k
];
}).
join
(
'&'
);
},
rawUncode
(
args
)
{
let
keys
=
Object
.
keys
(
args
);
keys
=
keys
.
sort
();
return
keys
.
map
(
k
=>
{
return
'&'
+
k
.
toLowerCase
()
+
'='
+
encodeURIComponent
(
args
[
k
]);
}).
join
(
'&'
);
}
};
module
.
exports
=
Sign
;
...
...
apps/shopping/models/pay.js
View file @
ccd5582
...
...
@@ -77,9 +77,12 @@ const getPayInfo = (uid, code) => {
*/
const
getPaymentInfo
=
(
id
)
=>
{
return
co
(
function
*
()
{
let
payment
=
yield
api
.
getPaymentInfo
(
id
);
let
data
=
yield
api
.
getPaymentInfo
(
id
);
return
payment
;
if
(
data
&&
data
.
code
===
200
&&
data
.
data
){
return
camelCase
(
data
.
data
);
}
return
{};
})();
};
...
...
apps/shopping/router.js
View file @
ccd5582
...
...
@@ -33,7 +33,7 @@ router.post('/order/submit', auth, order.orderSub);
// 支付
router
.
get
(
'/pay/online'
,
pay
.
online
);
router
.
ge
t
(
'/pay/online/go'
,
pay
.
toPay
);
router
.
pos
t
(
'/pay/online/go'
,
pay
.
toPay
);
// 在线支持完成
router
.
get
(
'/pay/online/success'
,
pay
.
success
);
...
...
config/common.js
View file @
ccd5582
...
...
@@ -19,7 +19,7 @@ module.exports = {
},
cookieDomain
:
'yohobuy.com'
,
domains
:
{
api
:
'http://
api.yoho.cn
/'
,
// devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
api
:
'http://
testapi.yoho.cn:28078
/'
,
// devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service
:
'http://testservice.yoho.cn:28077/'
,
// testservice.yoho.cn:28077 devservice.yoho.cn:58077
search
:
'http://192.168.102.216:8080/yohosearch/'
},
...
...
@@ -61,6 +61,9 @@ module.exports = {
appID
:
'wx3ae21dcbb82ad672'
,
appSecret
:
'e78afb2321e6a19085767e1a0f0d52c1'
}
},
pay
:
{
serviceNotify
:
'http://testservice.yoho.cn:28077/'
}
};
...
...
@@ -78,7 +81,10 @@ if (isProduction) {
timeout
:
3000
},
useOneapm
:
true
,
useCache
:
true
useCache
:
true
,
pay
:
{
serviceNotify
:
'http://service.yoho.cn/'
}
});
}
else
if
(
isTest
)
{
Object
.
assign
(
module
.
exports
,
{
...
...
Please
register
or
login
to post a comment