Skip to content

Commit

Permalink
点餐小程序(后端)
Browse files Browse the repository at this point in the history
  • Loading branch information
陆鹏 committed Sep 19, 2018
1 parent 6f0a239 commit d5095f6
Show file tree
Hide file tree
Showing 22 changed files with 2,489 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/.idea/KOA.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions server/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions server/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/.idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

703 changes: 703 additions & 0 deletions server/.idea/workspace.xml

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions server/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>KOA</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.projects.webnature</nature>
</natures>
<filteredResources>
<filter>
<id>0</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-node_modules</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
3 changes: 3 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var current_path = process.cwd();
console.log(current_path);
require('runkoa')(__dirname + '/entry.js')
35 changes: 35 additions & 0 deletions server/config/WXBizDataCrypt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var crypto = require('crypto')

function WXBizDataCrypt(appId, sessionKey) {
this.appId = appId
this.sessionKey = sessionKey
}

WXBizDataCrypt.prototype.decryptData = function (encryptedData, iv) {
// base64 decode
var sessionKey = new Buffer(this.sessionKey, 'base64')
encryptedData = new Buffer(encryptedData, 'base64')
iv = new Buffer(iv, 'base64')

try {
// 解密
var decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv)
// 设置自动 padding 为 true,删除填充补位
decipher.setAutoPadding(true)
var decoded = decipher.update(encryptedData, 'binary', 'utf8')
decoded += decipher.final('utf8')

decoded = JSON.parse(decoded)

} catch (err) {
throw new Error('Illegal Buffer')
}

if (decoded.watermark.appid !== this.appId) {
throw new Error('Illegal Buffer')
}

return decoded
}

module.exports = WXBizDataCrypt
42 changes: 42 additions & 0 deletions server/config/wxConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* 微信参数AppID 和 Secret */
var wxConfig = {
AppID: "YOUR_APPID", // 小程序ID
Secret: "YOUR_APP_SERCRET", // 小程序Secret
Mch_id: "YOUR_MCH_ID", // 商户号
Mch_key: "YOUR_MCH_KEY", // 商户key
// 生成商户订单号
getWxPayOrdrID: function(){
var myDate = new Date();
var year = myDate.getFullYear();
var mouth = myDate.getMonth() + 1;
var day = myDate.getDate();
var hour = myDate.getHours();
var minute = myDate.getMinutes();
var second = myDate.getSeconds();
var msecond = myDate.getMilliseconds(); //获取当前毫秒数(0-999)
if(mouth < 10){ /*月份小于10 就在前面加个0*/
mouth = String(String(0) + String(mouth));
}
if(day < 10){ /*日期小于10 就在前面加个0*/
day = String(String(0) + String(day));
}
if(hour < 10){ /*时小于10 就在前面加个0*/
hour = String(String(0) + String(hour));
}
if(minute < 10){ /*分小于10 就在前面加个0*/
minute = String(String(0) + String(minute));
}
if(second < 10){ /*秒小于10 就在前面加个0*/
second = String(String(0) + String(second));
}
if (msecond < 10) {
msecond = String(String('00') + String(second));
} else if(msecond >= 10 && msecond < 100){
msecond = String(String(0) + String(second));
}

var currentDate = String(year) + String(mouth) + String(day) + String(hour) + String(minute) + String(second) + String(msecond);
return currentDate;
}
};
module.exports = wxConfig;
Loading

0 comments on commit d5095f6

Please sign in to comment.