工作流
1、windows系统,复制代码到job里面时,需要保存为:UTF-8编码格式的;否则会导致汉字乱码
2、对项目lib/middle文件夹内文件发送变动(目前当修改main.js或者job文件会涉及到),请使用<<技术任务更新通知>>的六条发送邮件

(function() {
module.exports.exec = function(req, data) {
var finish_data = {};
var tmp_data = {};
var inputs = data.data;
// 用户实际支付了多少钱
inputs.totalfee = Number(data.data.record.md_amount);
// 资源id
inputs.transactionID = data.data.record.md_iid;
// 付款用户的uid
inputs.uid = data.data.record.md_uid;
return when.pipeline([
/*INSBEGIN:JOBPROCESS*/
!注意! 通常来说,必须要对用户实际支付的钱与应该支付多少钱做一个判断; 如果不做判断,就会出现用户支付一分钱,但是却买了N元钱的东西;
请手动删除这句话,并且插入相应的代码段
!但是! 如果允许用户支付任意金额,例如充值,那么可以可以不做检查
/*INSBEGIN:CUSTOM*/
function() {
// 用来判断 实付金额 与 应付金额是否相等. 应付金额由自己从数据库中获取.
var resourcePrice = Number(应付金额由自己从数据库中获取,并且将这里修改为对应的变量);
/*
x,y 为参与操作的变量,自动取小数点后两位
加法(x+y)操作 math.format(math.add(x,y), { notation: 'fixed', precision: 2 });
减法(x-y)操作 math.format(math.subtract(x,y), { notation: 'fixed', precision: 2 });
乘法(x*y)操作 math.format(math.multiply(x,y), { notation: 'fixed', precision: 2 });
除法(x/y)操作 math.format(math.divide(x,y), { notation: 'fixed', precision: 2 });
*/
// TODO
if (isNaN(inputs.totalfee) || isNaN(resourcePrice)) {
throw {
"status": 200,
"message": {
"success": false,
"status": 200,
"message": {
"error": "totalfee=" + inputs.totalfee + "; resourcePrice=" + resourcePrice + " 不是合法金额"
}
}
};
}
resourcePrice = math.format(resourcePrice, { notation: 'fixed', precision: 2 });
var totalfee = math.format(inputs.totalfee, { notation: 'fixed', precision: 2 });
if (!math.equal(totalfee, resourcePrice)) {
throw {
"status": 200,
"message": {
"success": false,
"status": 200,
"message": {
"error": "应付金额["+resourcePrice+"]实际支付["+totalfee+"]不匹配!"
}
}
};
}
},
/*INSEND:CUSTOM*/
判断通过后的处理逻辑.......
/*INSEND:JOBPROCESS*/
function() {
var default_data = /*INSBEGIN:MARK*/ {} /*INSEND:MARK*/ ;
return _.extend(default_data, finish_data);
}
]);
};
})();

/*INSBEGIN:CUSTOM*/
function() {
// 用来判断 实付金额 与 应付金额是否相等. 应付金额由自己从数据库中获取.
var resourcePrice = Number(应付金额由自己从数据库中获取,并且将这里修改为对应的变量);
/*
x,y 为参与操作的变量,自动取小数点后两位
加法(x+y)操作 math.format(math.add(x,y), { notation: 'fixed', precision: 2 });
减法(x-y)操作 math.format(math.subtract(x,y), { notation: 'fixed', precision: 2 });
乘法(x*y)操作 math.format(math.multiply(x,y), { notation: 'fixed', precision: 2 });
除法(x/y)操作 math.format(math.divide(x,y), { notation: 'fixed', precision: 2 });
*/
// TODO
if (isNaN(inputs.totalfee) || isNaN(resourcePrice)) {
throw {
"status": 200,
"message": {
"success": false,
"status": 200,
"message": {
"error": "totalfee=" + inputs.totalfee + "; resourcePrice=" + resourcePrice + " 不是合法金额"
}
}
};
}
resourcePrice = math.format(resourcePrice, { notation: 'fixed', precision: 2 });
var totalfee = math.format(inputs.totalfee, { notation: 'fixed', precision: 2 });
if (!math.equal(totalfee, resourcePrice)) {
throw {
"status": 200,
"message": {
"success": false,
"status": 200,
"message": {
"error": "应付金额["+resourcePrice+"]实际支付["+totalfee+"]不匹配!"
}
}
};
}
},
/*INSEND:CUSTOM*/
部分可以放到接口中处理



支付成功后 job被启动时,并且通过inputs对象能获取如下信息.
{
gateway: 'WechatPay_Native',
transactionID: 'e2c9505971394474a5085c7f40cbd261',
gatewayTID: '4006562001201610126507572552',
banktype: 'CFT',
cashfee: '1',
issubscribe: 'N',
openid: 'ofT5Zw5LccA9OMoryujP6Ug-f1_s',
resultcode: 'SUCCESS',
returncode: 'SUCCESS',
timeend: '20161012194701',
totalfee: '1',
mch_id: '1374513602',
appid: 'wx912cdabac8ac5aa5',
success: true,
sellerid: '1374513602',
customerid: 'ofT5Zw5LccA9OMoryujP6Ug-f1_s',
paymentid: '4006562001201610126507572552',
record: {
md_tid: 'e2c95059-7139-4474-a508-5c7f40cbd261',
md_orderid: null,
md_state: 1,
md_amount: '0.01',// 实际支付金额
md_currencycode: 'CNY',
md_customer: null,
md_customerid: 'ofT5Zw5LccA9OMoryujP6Ug-f1_s',
md_seller: null,
md_sellerid: '1374513602',
md_gateway: 'WechatPay_Native',
md_paymentid: '4006562001201610126507572552',
md_paymentdate: Wed Oct 12 2016 19: 23: 54 GMT + 0800(CST),
md_subject: '一分钱测试',
md_body: 'asdasdas',
md_jobid: 'zhifucallback',
md_jobnum: null,
md_jobstate: null,
md_iid: 'cc5e155f0a7f1fc5eab523e02716b91f', // 请求发起付款时传入的 transactionID
md_prepayid: null,
md_error: null,
md_uid: '2df6a5c8ef794b41814f1d1ae04e83a1', // 请求发起付款时的 用户ID
createdAt: Wed Oct 12 2016 19: 23: 54 GMT + 0800(CST),
updatedAt: Wed Oct 12 2016 19: 24: 07 GMT + 0800(CST),
success: true
}
}
注意1: 在支付功能中 job被执行到的时候一定是充值成功 如果用户没有支付成功,job是不会被执行到的. 所以job中处理的逻辑就是 用户付款成功后应该如何做