diff --git a/packages/core/package.json b/packages/core/package.json index 9a6dc8f..46b38fe 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/core", - "version": "6.0.3", + "version": "6.0.4", "description": "", "main": "dist/index.js", "typings": "index.d.ts", diff --git a/packages/core/src/controller/base.ts b/packages/core/src/controller/base.ts index bb94330..24d5f90 100644 --- a/packages/core/src/controller/base.ts +++ b/packages/core/src/controller/base.ts @@ -66,6 +66,7 @@ export abstract class BaseController { return; } this.baseCtx.request.body = { + // @ts-ignore ...this.baseCtx.request.body, ...(await curdOption.insertParam(this.baseCtx, this.baseApp)), }; @@ -115,6 +116,7 @@ export abstract class BaseController { * @returns */ async delete() { + // @ts-ignore const { ids } = this.baseCtx.request.body; return this.ok(await this.service.delete(ids)); } diff --git a/packages/core/src/entity/mongo.ts b/packages/core/src/entity/mongo.ts index 6c80d32..f17dec5 100644 --- a/packages/core/src/entity/mongo.ts +++ b/packages/core/src/entity/mongo.ts @@ -2,6 +2,7 @@ import { Index, UpdateDateColumn, CreateDateColumn, + // @ts-ignore ObjectID, ObjectIdColumn, } from "typeorm"; diff --git a/packages/core/src/package.json b/packages/core/src/package.json index 147e832..b4d0170 100644 --- a/packages/core/src/package.json +++ b/packages/core/src/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/core", - "version": "6.0.3", + "version": "6.0.4", "description": "", "main": "index.js", "typings": "index.d.ts", diff --git a/packages/core/src/tag/data.ts b/packages/core/src/tag/data.ts index 5832e2f..217246b 100644 --- a/packages/core/src/tag/data.ts +++ b/packages/core/src/tag/data.ts @@ -9,6 +9,7 @@ import { ScopeEnum, } from '@midwayjs/decorator'; import { COOL_URL_TAG_KEY } from '../decorator/tag'; +import * as _ from 'lodash'; /** * URL标签 @@ -27,10 +28,10 @@ export class CoolUrlTagData { controller ); const data: string[] = this.data[tagOption.key] || []; - this.data[tagOption.key] = data.concat( + this.data[tagOption.key] = _.uniq(data.concat( tagOption.value.map(e => { return controllerOption.prefix + '/' + e; - }) + })) ); } } diff --git a/src/modules/demo/controller/app/pay.ts b/src/modules/demo/controller/app/pay.ts index 39cd8c6..34a2449 100644 --- a/src/modules/demo/controller/app/pay.ts +++ b/src/modules/demo/controller/app/pay.ts @@ -122,6 +122,12 @@ export class AppDemoPayController extends BaseController { */ @Post('/aliNotify') async aliNotify(@Body() body) { + const { ciphertext, associated_data, nonce } = body.resource; + // 解密数据 + const data = this.wxPay + .getInstance() + .decipher_gcm(ciphertext, associated_data, nonce); + console.log(data); const check = await this.aliPay.signVerify(body); // 验签通过,处理业务逻辑 if (check) { diff --git a/src/modules/user/controller/app/comm.ts b/src/modules/user/controller/app/comm.ts new file mode 100644 index 0000000..78af233 --- /dev/null +++ b/src/modules/user/controller/app/comm.ts @@ -0,0 +1,27 @@ +import { + CoolController, + BaseController, + CoolUrlTag, + TagTypes, +} from '@cool-midway/core'; +import { Get, Inject, Query } from '@midwayjs/core'; +import { UserWxService } from '../../service/wx'; + +/** + * 通用 + */ +@CoolUrlTag({ + key: TagTypes.IGNORE_TOKEN, + value: ['wxMpConfig'], +}) +@CoolController() +export class UserCommController extends BaseController { + @Inject() + userWxService: UserWxService; + + @Get('/wxMpConfig', { summary: '获取微信公众号配置' }) + public async getWxMpConfig(@Query() url: string) { + const a = await this.userWxService.getWxMpConfig(url); + return this.ok(a); + } +} diff --git a/src/modules/user/service/wx.ts b/src/modules/user/service/wx.ts index 2d2ec87..14482d6 100644 --- a/src/modules/user/service/wx.ts +++ b/src/modules/user/service/wx.ts @@ -2,6 +2,8 @@ import { Config, Provide } from '@midwayjs/decorator'; import { BaseService, CoolCommException } from '@cool-midway/core'; import axios from 'axios'; import * as crypto from 'crypto'; +import { v1 as uuid } from 'uuid'; +import * as moment from 'moment'; /** * 微信 @@ -11,6 +13,45 @@ export class UserWxService extends BaseService { @Config('module.user') config; + /** + * 获得微信配置 + * @param appId + * @param appSecret + * @param url 当前网页的URL,不包含#及其后面部分(必须是调用JS接口页面的完整URL) + */ + public async getWxMpConfig(url: string) { + const access_token = await this.getWxToken(); + const ticket = await axios.get( + 'https://api.weixin.qq.com/cgi-bin/ticket/getticket', + { + params: { + access_token: access_token.data.access_token, + type: 'jsapi', + }, + } + ); + const { appid } = this.config.wx.mp; + // 返回结果集 + const result = { + timestamp: parseInt(moment().valueOf() / 1000 + ''), + nonceStr: uuid(), + appId: appid, //appid + signature: '', + }; + const signArr = []; + signArr.push('jsapi_ticket=' + ticket.data.ticket); + signArr.push('noncestr=' + result.nonceStr); + signArr.push('timestamp=' + result.timestamp); + signArr.push('url=' + decodeURI(url)); + // 敏感信息加密处理 + result.signature = crypto + .createHash('sha1') + .update(signArr.join('&')) + .digest('hex') + .toUpperCase(); + return result; + } + /** * 获得公众号用户信息 * @param code