-
Notifications
You must be signed in to change notification settings - Fork 1
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
shijunfeng
committed
Dec 5, 2019
0 parents
commit 0433177
Showing
90 changed files
with
17,529 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
prefix: '^', | ||
plugin: 'autod-egg', | ||
test: [ | ||
'test', | ||
'benchmark', | ||
], | ||
devdep: [ | ||
'egg', | ||
'egg-ci', | ||
'egg-bin', | ||
'autod', | ||
'autod-egg', | ||
'eslint', | ||
'eslint-config-egg', | ||
], | ||
exclude: [ | ||
'./test/fixtures', | ||
'./docs', | ||
'./coverage', | ||
], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "eslint-config-egg" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- | ||
Thank you for your pull request. Please review below requirements. | ||
Bug fixes and new features should include tests and possibly benchmarks. | ||
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md | ||
感谢您贡献代码。请确认下列 checklist 的完成情况。 | ||
Bug 修复和新功能必须包含测试,必要时请附上性能测试。 | ||
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md | ||
--> | ||
|
||
##### Checklist | ||
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> | ||
|
||
- [ ] `npm test` passes | ||
- [ ] tests and/or benchmarks are included | ||
- [ ] documentation is changed or added | ||
- [ ] commit message follows commit guidelines | ||
|
||
##### Affected core subsystem(s) | ||
<!-- Provide affected core subsystem(s). --> | ||
|
||
|
||
##### Description of change | ||
<!-- Provide a description of the change below this comment. --> |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
logs/ | ||
npm-debug.log | ||
node_modules/ | ||
coverage/ | ||
.idea/ | ||
run/ | ||
store/ | ||
.DS_Store | ||
*.swp | ||
|
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '8' | ||
- '10' | ||
before_install: | ||
- npm i npminstall -g | ||
install: | ||
- npminstall | ||
script: | ||
- npm run ci | ||
after_script: | ||
- npminstall codecov && codecov |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019-present Alibaba Group Holding Limited and other contributors. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# egg-echat | ||
|
||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![David deps][david-image]][david-url] | ||
[![Known Vulnerabilities][snyk-image]][snyk-url] | ||
[![npm download][download-image]][download-url] | ||
|
||
[npm-image]: https://img.shields.io/npm/v/egg-echat.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/egg-echat | ||
[travis-image]: https://img.shields.io/travis/eggjs/egg-echat.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/eggjs/egg-echat | ||
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-echat.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/eggjs/egg-echat?branch=master | ||
[david-image]: https://img.shields.io/david/eggjs/egg-echat.svg?style=flat-square | ||
[david-url]: https://david-dm.org/eggjs/egg-echat | ||
[snyk-image]: https://snyk.io/test/npm/egg-echat/badge.svg?style=flat-square | ||
[snyk-url]: https://snyk.io/test/npm/egg-echat | ||
[download-image]: https://img.shields.io/npm/dm/egg-echat.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/egg-echat | ||
|
||
<!-- | ||
Description here. | ||
--> | ||
|
||
## Install | ||
|
||
```bash | ||
$ npm i egg-echat --save | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
// {app_root}/config/plugin.js | ||
exports.echat = { | ||
enable: true, | ||
package: 'egg-echat', | ||
}; | ||
``` | ||
|
||
## Configuration | ||
|
||
```js | ||
// {app_root}/config/config.default.js | ||
exports.echat = { | ||
}; | ||
``` | ||
|
||
see [config/config.default.js](config/config.default.js) for more detail. | ||
|
||
## Example | ||
|
||
<!-- example here --> | ||
|
||
## Questions & Suggestions | ||
|
||
Please open an issue [here](https://github.com/eggjs/egg/issues). | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# egg-echat | ||
|
||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![David deps][david-image]][david-url] | ||
[![Known Vulnerabilities][snyk-image]][snyk-url] | ||
[![npm download][download-image]][download-url] | ||
|
||
[npm-image]: https://img.shields.io/npm/v/egg-echat.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/egg-echat | ||
[travis-image]: https://img.shields.io/travis/eggjs/egg-echat.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/eggjs/egg-echat | ||
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-echat.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/eggjs/egg-echat?branch=master | ||
[david-image]: https://img.shields.io/david/eggjs/egg-echat.svg?style=flat-square | ||
[david-url]: https://david-dm.org/eggjs/egg-echat | ||
[snyk-image]: https://snyk.io/test/npm/egg-echat/badge.svg?style=flat-square | ||
[snyk-url]: https://snyk.io/test/npm/egg-echat | ||
[download-image]: https://img.shields.io/npm/dm/egg-echat.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/egg-echat | ||
|
||
<!-- | ||
Description here. | ||
--> | ||
|
||
## 依赖说明 | ||
|
||
### 依赖的 egg 版本 | ||
|
||
egg-echat 版本 | egg 1.x | ||
--- | --- | ||
1.x | 😁 | ||
0.x | ❌ | ||
|
||
### 依赖的插件 | ||
<!-- | ||
如果有依赖其它插件,请在这里特别说明。如 | ||
- security | ||
- multipart | ||
--> | ||
|
||
## 开启插件 | ||
|
||
```js | ||
// config/plugin.js | ||
exports.echat = { | ||
enable: true, | ||
package: 'egg-echat', | ||
}; | ||
``` | ||
|
||
## 使用场景 | ||
|
||
- Why and What: 描述为什么会有这个插件,它主要在完成一件什么事情。 | ||
尽可能描述详细。 | ||
- How: 描述这个插件是怎样使用的,具体的示例代码,甚至提供一个完整的示例,并给出链接。 | ||
|
||
## 详细配置 | ||
|
||
请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。 | ||
|
||
## 单元测试 | ||
|
||
<!-- 描述如何在单元测试中使用此插件,例如 schedule 如何触发。无则省略。--> | ||
|
||
## 提问交流 | ||
|
||
请到 [egg issues](https://github.com/eggjs/egg/issues) 异步交流。 | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-cayman |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = app => { | ||
// 将 static 中间件放到 bodyParser 之前 | ||
|
||
// app.config.coreMiddleware.unshift('echatOauth2'); | ||
// console.log(app.config); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const Echat = require('../../lib/echat'); | ||
|
||
module.exports = { | ||
echat(config) { | ||
|
||
config = config || this.app.config.echat; | ||
|
||
config = Object.assign(config, this.app.config.echat); //合并配置 | ||
|
||
config.ctx = this; | ||
|
||
const S_echat = Symbol(`Context${config}`); | ||
|
||
if (!this[S_echat]) { | ||
// 例如,从 header 中获取,实际情况肯定更复杂 | ||
this[S_echat] = new Echat(config); | ||
} | ||
|
||
return this[S_echat]; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
|
||
module.exports = (options, app) => { | ||
console.log('感谢您使用echat插件,本插件主要用于eggjs接入私有化部署的企业微信,详细使用文档:http://www.baidu.com'); | ||
|
||
return async function (ctx, next) { | ||
// //判断是否已经登录 | ||
const isEchatAuth = await ctx.service.echatAuth.check(); | ||
|
||
if (!isEchatAuth) { | ||
const oauth2 = await ctx.echat().oauth2(); | ||
const code = ctx.query.code; | ||
if (!code) { | ||
ctx.unsafeRedirect(await oauth2.redirectUrl()); | ||
return; | ||
} | ||
|
||
function isDetail() { | ||
let scope = (ctx.app.config.echat.Agent.oauth.hasOwnProperty('scopes') ? ctx.app.config.echat.Agent.oauth.scopes : null) ; | ||
return scope === 'snsapi_base' ? false : true; | ||
} | ||
|
||
let userInfo = await oauth2.getUserInfo(code, isDetail()); | ||
//删除干扰信息 | ||
delete userInfo.errcode; | ||
delete userInfo.errmsg; | ||
delete userInfo.user_ticket; | ||
delete userInfo.expires_in; | ||
//存入session | ||
ctx.session.echat = { | ||
userid: userInfo.userid, | ||
name: userInfo.name, | ||
deviceId: userInfo.DeviceId, | ||
usertype: userInfo.usertype, | ||
test: userInfo.test, | ||
gender: userInfo.gender, | ||
avatar: userInfo.avatar, | ||
original: userInfo | ||
} | ||
|
||
|
||
} | ||
await next(); | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
const Service = require('egg').Service; | ||
|
||
class EchatAuthService extends Service { | ||
|
||
//用户是否已用echat登陆 | ||
async check() { | ||
const result = await this.ctx.session.echat; | ||
if (result) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = EchatAuthService; | ||
|
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '8' | ||
- nodejs_version: '10' | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- npm i npminstall && node_modules\.bin\npminstall | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run test | ||
|
||
build: off |
Oops, something went wrong.