添加企业微信相关接口
This commit is contained in:
parent
5e56a91bd3
commit
42df8debb0
@ -1,27 +1,20 @@
|
|||||||
import BaseController from 'common/base.controller'
|
import BaseController from 'common/base.controller'
|
||||||
import { ZError } from 'common/ZError'
|
import { ZError } from 'common/ZError'
|
||||||
import { role, router } from 'decorators/router'
|
import { role, router } from 'decorators/router'
|
||||||
import { aesDecrypt, base64Decode, sha1 } from 'utils/security.util'
|
|
||||||
import { getSignature, decrypt } from '@wecom/crypto'
|
import { getSignature, decrypt } from '@wecom/crypto'
|
||||||
|
|
||||||
let signData = function (timestamp, nonce, echostr, token) {
|
|
||||||
let hashStr = [timestamp, nonce, echostr, token].sort().join('')
|
|
||||||
return sha1(hashStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
const TOKEN = 'qDd25AkMStj6mI9ViNUQt'
|
|
||||||
const AES_KEY = 'rk7nvsNobBx3aG9jMSTlKc1gMj4GIPDrWs4ZMdlgP4V'
|
|
||||||
|
|
||||||
class WorkFlowController extends BaseController {
|
class WorkFlowController extends BaseController {
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('get /workflow/notify')
|
@router('get /workflow/notify')
|
||||||
async sendOneMail(req, res) {
|
async wxNotifyCheck(req, res) {
|
||||||
|
const token = process.env.WX_TOKEN
|
||||||
|
const aesKey = process.env.WX_AES_KEY
|
||||||
let { msg_signature, timestamp, nonce, echostr } = req.params
|
let { msg_signature, timestamp, nonce, echostr } = req.params
|
||||||
const signature = getSignature(TOKEN, timestamp, nonce, echostr)
|
const signature = getSignature(token, timestamp, nonce, echostr)
|
||||||
if (msg_signature !== signature) {
|
if (msg_signature !== signature) {
|
||||||
throw new ZError(10, 'sign check failed')
|
throw new ZError(10, 'sign check failed')
|
||||||
}
|
}
|
||||||
const { message, id } = decrypt(AES_KEY, echostr)
|
const { message, id } = decrypt(aesKey, echostr)
|
||||||
res.send(message)
|
res.send(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,12 +22,13 @@ class WorkFlowController extends BaseController {
|
|||||||
@router('post /workflow/notify')
|
@router('post /workflow/notify')
|
||||||
async flowNotify(req, res) {
|
async flowNotify(req, res) {
|
||||||
let { msg_signature, timestamp, nonce, xml } = req.params
|
let { msg_signature, timestamp, nonce, xml } = req.params
|
||||||
console.log(xml)
|
const token = process.env.WX_TOKEN
|
||||||
const signature = getSignature(TOKEN, timestamp, nonce, xml.Encrypt)
|
const aesKey = process.env.WX_AES_KEY
|
||||||
|
const signature = getSignature(token, timestamp, nonce, xml.Encrypt)
|
||||||
if (msg_signature !== signature) {
|
if (msg_signature !== signature) {
|
||||||
throw new ZError(10, 'sign check failed')
|
throw new ZError(10, 'sign check failed')
|
||||||
}
|
}
|
||||||
const { message, id } = decrypt(AES_KEY, xml.Encrypt)
|
const { message, id } = decrypt(aesKey, xml.Encrypt)
|
||||||
console.log(id)
|
console.log(id)
|
||||||
console.log(message)
|
console.log(message)
|
||||||
res.send('success')
|
res.send('success')
|
||||||
|
53
src/services/WechatWorkService.ts
Normal file
53
src/services/WechatWorkService.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { singleton } from 'decorators/singleton'
|
||||||
|
|
||||||
|
const WX_API_HOST = 'https://qyapi.weixin.qq.com'
|
||||||
|
@singleton
|
||||||
|
export class WechatWorkService {
|
||||||
|
private accessToken: string
|
||||||
|
private tokenExpire: number
|
||||||
|
private wxToken: string
|
||||||
|
private wxAesKey: string
|
||||||
|
private wxCorpId: string
|
||||||
|
private wxCorpSecret: string
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.wxToken = process.env.WX_TOKEN
|
||||||
|
this.wxAesKey = process.env.WX_AES_KEY
|
||||||
|
this.wxCorpId = process.env.WX_CORP_ID
|
||||||
|
this.wxCorpSecret = process.env.WX_CORP_SECRET
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信企业号的access_token
|
||||||
|
* https://developer.work.weixin.qq.com/resource/devtool
|
||||||
|
*/
|
||||||
|
public async refreshAccessToken() {
|
||||||
|
const url = `${WX_API_HOST}/cgi-bin/gettoken`
|
||||||
|
// use axios get url
|
||||||
|
let config = {
|
||||||
|
method: 'get',
|
||||||
|
maxBodyLength: Infinity,
|
||||||
|
url,
|
||||||
|
}
|
||||||
|
let response = await axios.request(config).then(response => {
|
||||||
|
return response.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取审批申请详情
|
||||||
|
* https://developer.work.weixin.qq.com/devtool/interface/alone?id=18615
|
||||||
|
* @param spNo 审批单号
|
||||||
|
*/
|
||||||
|
public async fetchApprovalDetail(spNo: string) {
|
||||||
|
const url = `${WX_API_HOST}/cgi-bin/oa/getapprovaldetail`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据media_id获取文件
|
||||||
|
* https://developer.work.weixin.qq.com/devtool/interface/alone?id=18615
|
||||||
|
* @param mediaId
|
||||||
|
*/
|
||||||
|
public async fetchFile(mediaId: string) {
|
||||||
|
const url = `${WX_API_HOST}/cgi-bin/media/get`
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user