npm i @axolo/egg-alipay --save
// config/plugin.js
exports.alipay = {
enable: true,
package: '@axolo/egg-alipay',
};
// {app_root}/config/config.default.js
const fs = require('fs');
const path = require('path');
const alipayPrivateKeyPath = 'path/to/your-alipay-app-private-key.pem';
const alipayPublicKeyPath = 'path/to/alipay-public-key.pem';
const alipayPrivateKey = fs.readFileSync(path.join(appInfo.baseDir, alipayPrivateKeyPath), 'ascii');
const alipayPublicKey = fs.readFileSync(path.join(appInfo.baseDir, alipayPublicKeyPath), 'ascii');
exports.alipay = {
default: {
AlipaySdk: require('alipay-sdk').default,
camelcase: true,
},
clients: {
sandbox: {
gateway: 'https://openapi.alipaydev.com/gateway.do', // sandbox
appId: 'your-alipay-app-id',
alipayPublicKey,
privateKey: alipayPrivateKey,
notifyUrl: 'url/to/your-alipay-notify',
},
},
};
请到 config/config.default.js 查看详细配置项说明。
成员 | 说明 |
---|---|
AlipaySdk | AlipaySdk类 |
sdk | AlipaySdk实例 |
config | AlipaySdk实例配置 |
请到 egg issues 异步交流。