整理代码

This commit is contained in:
cool 2024-01-30 14:11:34 +08:00
parent 58e9587c8e
commit bb5d19841c
2 changed files with 1 additions and 138 deletions

View File

@ -1,137 +0,0 @@
import { Body, Config, Inject, Post, Provide } from '@midwayjs/decorator';
import {
CoolController,
BaseController,
CoolWxPayConfig,
CoolAliPayConfig,
} from '@cool-midway/core';
import { CoolAliPay, CoolWxPay } from '@cool-midway/pay';
// @ts-ignore
import AlipayFormData from 'alipay-sdk/lib/form';
// @ts-ignore
import { sign } from 'alipay-sdk/lib/util';
/**
*
*/
@Provide()
@CoolController()
export class AppDemoPayController extends BaseController {
// 微信支付
@Inject()
wxPay: CoolWxPay;
// 支付宝支付
@Inject()
aliPay: CoolAliPay;
@Inject()
ctx;
@Config('cool.pay.wx')
wxPayConfig: CoolWxPayConfig;
@Config('cool.pay.ali')
aliPayConfig: CoolAliPayConfig;
/**
*
*/
@Post('/wx')
async wx() {
const orderNum = await this.wxPay.createOrderNum();
const params = {
description: '测试',
out_trade_no: orderNum,
notify_url: this.wxPayConfig.notify_url,
amount: {
total: 1,
},
scene_info: {
payer_client_ip: 'ip',
},
};
const result = await this.wxPay.getInstance().transactions_native(params);
return this.ok(result);
}
/**
*
*/
@Post('/wxNotify')
async wxNotify(@Body() body) {
const check = await this.wxPay.signVerify(this.ctx);
// 验签通过,处理业务逻辑
if (check) {
}
}
/**
* PC网站支付
* @returns
*/
@Post('/aliPc')
async aliPc() {
const orderNum = await this.aliPay.createOrderNum();
const formData = new AlipayFormData();
// 调用 setMethod 并传入 get会返回可以跳转到支付页面的 url
formData.setMethod('get');
formData.addField('notifyUrl', this.aliPayConfig.notifyUrl);
formData.addField('bizContent', {
outTradeNo: orderNum,
productCode: 'FAST_INSTANT_TRADE_PAY',
totalAmount: '0.01',
subject: '商品',
body: '商品详情',
});
// 返回支付链接
const result = await this.aliPay
.getInstance()
.exec('alipay.trade.page.pay', {}, { formData });
return this.ok(result);
}
/**
* APP支付
* @returns
*/
@Post('/aliApp')
async aliApp() {
const orderNum = await this.aliPay.createOrderNum();
// 返回支付链接
const data = sign(
'alipay.trade.app.pay',
{
notifyUrl: this.aliPayConfig.notifyUrl,
bizContent: {
subject: '商品标题',
totalAmount: '0.01',
outTradeNo: orderNum,
productCode: 'QUICK_MSECURITY_PAY',
},
},
this.aliPay.getInstance().config
);
const payInfo = new URLSearchParams(data).toString();
return this.ok(payInfo);
}
/**
*
*/
@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) {
}
return 'success';
}
}

View File

@ -1,7 +1,6 @@
import { BaseUpload, MODETYPE } from './interface'; import { BaseUpload, MODETYPE } from './interface';
import { BasePluginHook } from '../base'; import { BasePluginHook } from '../base';
import * as fs from 'fs'; import * as fs from 'fs';
import * as download from 'download';
import * as path from 'path'; import * as path from 'path';
import * as moment from 'moment'; import * as moment from 'moment';
import { v1 as uuid } from 'uuid'; import { v1 as uuid } from 'uuid';
@ -40,6 +39,7 @@ export class PluginUpload extends BasePluginHook implements BaseUpload {
const { domain } = this.pluginInfo.config; const { domain } = this.pluginInfo.config;
// 从url获取扩展名 // 从url获取扩展名
const extend = path.extname(url); const extend = path.extname(url);
const download = require('download');
// 数据 // 数据
const data = url.includes('http') const data = url.includes('http')
? await download(url) ? await download(url)