最近更新
- 增加socket.io集群功能。
- 增加支付mysql数据库功能。
- 为了更加灵活使用数据库,取消了postgresql数据库自动事务,修改为手动控制(具体方法如下)。
- 增加定时任务功能(精确到秒
重点说明
- 2.x版本不与1.x版本兼容!!!!!
- 下载工程包并解压
- 打开命令行并执行:
npm install
命令 - 由于国外网络速度受限制,推荐使用淘宝 NPM 镜像:
cnpm install
命令进行安装 。(淘宝源安装命令:npm install -g cnpm --registry=https://registry.npm.taobao.org
) - 建议使用pm2 进行程序启动 命令:
pm2 start start.json
- start.json(pm2启动配置文件)
- apimain.js(服务器启动入口文件)
- time_run_main.js(定时任务启动入口文件)
- README.md(说明文档)
- package.josn(框架清单)
- config(配置文件目录)
- app.json(程序主要配置文件如:监听商品,数据库类型,数据库连接参数等)
- func(同步功能方法封装文件目录)
- api(APP接口目录)
- api.js(接口主文件)
- routes(*xhtml接口目录)
- app_routes_main.js(接口主文件)
- www(静态文件目录)
- im(socket.io接口文件目录)
- app_im_main.js(接口主文件)
- auth.js(用户认证接口文件)
- time.js(心跳包接口文件)
- cnannel.js(集群频道接口文件)
- disconnect.js(断开连接接口文件)
- temp(临时文件目录)
- time_run_func(定时任务功能目录)
- time_run_second(定时任务时间控制目录)
//去除数据中含有null的
// var a = common.removenull("{"账号":null,"手机号码":null}");
// var b = {"账号":null,"手机号码":null};
// var a = common.removenull(b);
//取当前时间的几天后或几月后
// var a = common.afterDM("2015-02-01 00:00:00","day",1);
// var a = common.afterDM("2015-02-01 00:00:00","month",1);
//获取范围内的随机数
// var a = common.sjs("1000","9999");
//获取两个时间的差
var d = common.timeSecond(time1,time2);
//截取中间字符串
// var str = "hello world"
// var a = common.getsub(str,"h","o");
// console.log(a); //ell
//postgresql开始事务
var begin = pgdb.query(db,"BEGIN;");
//postgresql保存事务
var commit = pgdb.query(db,"COMMIT;");
//postgresql回滚事务
var rollback = pgdb.query(db,"ROLLBACK;");
//mysql开始事务
var begin = mysql.query(db,"BEGIN;");
//mysql保存事务
var commit = mysql.query(db,"COMMIT;");
//mysql回滚事务
var rollback = mysql.query(db,"ROLLBACK;");
//引用
var cipher = require('../func/cipher.js');
//aes加密
var str = cipher.aesencode('1234567890','12345678901234567890123456789012');
console.log(str);
//aes解密
var str1 = cipher.aesdecode(str,'12345678901234567890123456789012');
console.log(str1);
//md5加密
var str2 = cipher.md5('123456');
console.log(str2);
//sha1加密
var str3 = cipher.sha1('123456');
console.log(str3);
var qcloud = require("../func/qcloud.js");
var config = require("../func/config.js");
module.exports.run = function (body, pg, mo) {
var conf = config.get('txsms');
if (conf == null) {
result.状态 = '失败';
result.回复信息 = '读取配置文件失败';
return result;
}
var result = qcloud.sendsms("xx", "9083677888", "您的手机验证码为1155,请勿向他人泄漏!", "140xxxxxx", "1xxxxxxxxxxxx");
return result;
}
var AlipayAPI = require("../func/alipay_api.js");
module.exports.run = function (body,db, mo,redis) {
var subject = "iphone8 1TB全网通";
var data = {};
data.out_trade_no = "001"+(new Date()).valueOf();
data.store_id = "NJ_001";
data.subject = subject;
data.total_amount = 0.01;
data.timeout_express = "90m";
var result = AlipayAPI.request("2017021405667105","alipay.trade.precreate",data);
return result;
}
var WeixinPay = require("../func/weixin_api.js");
var config = require("../func/config.js");
module.exports.run = function (body, pg, mo) {
var conf = config.get("pay").微信支付;
////公众号支付
// var key = [];
// key.push("openid");
// key.push("body");
// key.push("detail");
// key.push("out_trade_no");
// key.push("total_fee");
// key.push("spbill_create_ip");
// key.push("notify_url");
// var value = [];
// value.push("oI6wfw3PpJyM1MAPgDz0jxjeL5Q8");
// value.push("1块钱测试");
// value.push("你确定这是1块钱");
// value.push("001" + (new Date()).valueOf());
// value.push("0.01");
// value.push("0.0.0.0");
// value.push("http://xxx/test_wx.xhtml");
// var result = WeixinPay.request("JSAPI",key,value);
// console.log("-------------JSAPI------------------");
// console.log(result);
// return result;
//扫码支付
var weixin_conf = {};
weixin_conf.appid = conf.appid;
weixin_conf.mch_id = conf.mch_id;
weixin_conf.partner_key = conf.partner_key;
var key = [];
key.push("body");
key.push("product_id");
key.push("out_trade_no");
key.push("total_fee");
key.push("spbill_create_ip");
key.push("notify_url");
var value = [];
value.push("1块钱测试");
value.push("1234567890");
value.push("001" + (new Date()).valueOf());
value.push("0.01");
value.push("0.0.0.0");
value.push("http://xxx/test_wx.xhtml");
var result = WeixinPay.request("NATIVE",weixin_conf,key,value);
console.log("-------------NATIVE------------------");
console.log(result);
return result;
//原生支付
// var key = [];
// key.push("body");
// key.push("product_id");
// key.push("out_trade_no");
// key.push("total_fee");
// key.push("spbill_create_ip");
// key.push("notify_url");
// var value = [];
// value.push("1块钱测试");
// value.push("1234567890");
// value.push("001" + (new Date()).valueOf());
// value.push("0.01");
// value.push("0.0.0.0");
// value.push("http://xxx/test_wx.xhtml");
// var result = WeixinPay.request("APP",key,value);
// console.log("-------------APP------------------");
// console.log(result);
// return result;
}
更多功能请详细阅读禅道系统文档