|
|
/**
|
|
|
*
|
|
|
* @author: jiangfeng<jeff.jiang@yoho.cn>
|
|
|
* @date: 16/9/8
|
|
|
/*
|
|
|
* @Author: Targaryen
|
|
|
* @Date: 2017-01-03 17:42:41
|
|
|
* @Last Modified by: mikey.zhaopeng
|
|
|
* @Last Modified time: 2017-01-03 18:07:44
|
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const ServiceAPI = global.yoho.ServiceAPI;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
/**
|
|
|
* 微信支付相关工具类
|
|
|
*/
|
|
|
const tools = {
|
|
|
createOauthUrlForCode(redirectUrl) {
|
|
|
return redirectUrl;
|
|
|
},
|
|
|
getOpenidFromMp(code) {
|
|
|
return code;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// TODO 微信支付
|
|
|
const Wechat = {
|
|
|
pay(user, order, info) {
|
|
|
return ServiceAPI.get('payment/weixin_data', {
|
|
|
order_code: order.order_code,
|
|
|
payment_code: info.id,
|
|
|
app_key: 'blkpc'
|
|
|
}).then(result => {
|
|
|
if (result && result.code === 200 && result.data) {
|
|
|
let url = `/shopping/pay/online/weixin?url=${result.data.codeUrl}&code=${order.order_code}`;
|
|
|
GetOpenid(req, res) {
|
|
|
let code = req.query.code;
|
|
|
|
|
|
if (!code) {
|
|
|
let baseUrl = 'http://m.yohobuy.com' + req.originalUrl;
|
|
|
let url = tools.createOauthUrlForCode(baseUrl);
|
|
|
|
|
|
res.redirectUrl(url);
|
|
|
} else {
|
|
|
let openid = tools.getOpenidFromMp(code);
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
data: {
|
|
|
href: helpers.urlFormat(url)
|
|
|
}
|
|
|
};
|
|
|
} else {
|
|
|
return {
|
|
|
code: 400,
|
|
|
message: result.message
|
|
|
};
|
|
|
}
|
|
|
});
|
|
|
return openid;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|