mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 22:20:30 +08:00
完善用户模块与微信支付回调解密
This commit is contained in:
parent
e5b3cbe9bf
commit
ef3f552403
@ -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",
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import {
|
||||
Index,
|
||||
UpdateDateColumn,
|
||||
CreateDateColumn,
|
||||
// @ts-ignore
|
||||
ObjectID,
|
||||
ObjectIdColumn,
|
||||
} from "typeorm";
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-midway/core",
|
||||
"version": "6.0.3",
|
||||
"version": "6.0.4",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"typings": "index.d.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;
|
||||
})
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
27
src/modules/user/controller/app/comm.ts
Normal file
27
src/modules/user/controller/app/comm.ts
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user