-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
884 additions
and
940 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,5 @@ | ||
const Promise = require('bluebird') | ||
const Axios = require('axios') | ||
// const Promise = require('bluebird') | ||
|
||
module.exports = function(method, url, params, body) { | ||
let options = { | ||
method: method, | ||
url: url, | ||
params: Object.assign({}, params), | ||
data: body | ||
} | ||
// module.exports = function(method, url, params, body) { | ||
|
||
return new Promise(function(resolve, reject) { | ||
Axios(options) | ||
.then(Response => { | ||
console.log(response) | ||
// if (response.status === 200) { | ||
// resolve(response.data) | ||
// } else { | ||
// reject(response.statusText.toString()) | ||
// } | ||
}) | ||
.catch(error => { | ||
console.log(error) | ||
// if (error.response) { | ||
// // The request was made, but the server responded with a status code | ||
// // that falls out of the range of 2xx | ||
// //console.log(error.response.data) | ||
// //console.log(error.response.headers) | ||
// console.log(error.response.status) | ||
// reject(error.response.status.toString()) | ||
// } else { | ||
// // Something happened in setting up the request that triggered an Error | ||
// console.log('Error', error.message) | ||
// reject(error.message.toString()) | ||
// } | ||
}) | ||
}) | ||
} | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,40 @@ | ||
var wechat = require('../../wechat/wechatListen') | ||
const sha1 = require('sha1') | ||
|
||
var config = require('../../config/config') | ||
var handler = require('../../wechat/handlerRequest') | ||
var parseRequest = require('../../wechat/parseRequest') | ||
var handleRequest = require('../../wechat/handleRequest') | ||
var handleResponse = require('../../wechat/handleResponse') | ||
|
||
module.exports = async function(ctx, next) { | ||
// this.middle = wechat(config.wechat, handler.handlerRequest) | ||
// await this.middle(next) | ||
|
||
const token = config.wechat.token | ||
const signature = ctx.query.signature | ||
const nonce = ctx.query.nonce | ||
const timestamp = ctx.query.timestamp | ||
const echostr = ctx.query.echostr | ||
|
||
const str = [token, timestamp, nonce].sort().join('') | ||
const sha = sha1(str) | ||
|
||
if (sha !== signature) { | ||
ctx.body = 'Bad Request' | ||
return false | ||
} | ||
ctx.body = '' | ||
|
||
// ctx.req is node origin request | ||
const requestData = await parseRequest(ctx.req, ctx.request) | ||
// console.log(requestData) | ||
|
||
const responseData = await handleRequest(requestData) | ||
// console.log(responseData) | ||
|
||
this.middle = wechat(config.wechat, handler.handlerRequest) | ||
const xml = await handleResponse(requestData, responseData) | ||
console.log(xml) | ||
|
||
await this.middle(next) | ||
ctx.status = 200 | ||
ctx.type = 'application/xml' | ||
ctx.body = xml | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"access_token":"gAtVLdvYGg9zK-WRTzMqtXG6Xh2PJcP29T6IPgaWR4mfwBWnYJZqnHZwFAiB2mniMAbf4T000SKuRvlq8wHJk8JQ1RRmn89Zl8Au3xqEO6pQl91rh_n2eiYeF23DnNehSRVhAIABAE","expires_in":1494061671899} | ||
{"access_token":"AbfmpGku3nxLJ5yWMpiy7hU3mAqhnymqg0fDLPxCQl-v5f_41QCHAbKR759d3sEAcX5MeBT0x6TvbhjNTsCafYm6qgY539t8-cE_dhSYKXKek7hDBNXUMnCqaL0jcxJ-ZOQjAHAPEG","expires_in":1494402197856} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.