egg-alicloud-open-api
v1.0.1
Published
AliCloud OpenAPI plugin for egg
Downloads
7
Maintainers
Readme
egg-alicloud-open-api
AliCloud OpenAPI plugin for egg framework
Install
$ npm i egg-alicloud-open-api --save
Usage
Enable the plugin
Change ${app_root}/config/plugin.js
to enable AliCloud plugin:
exports.aliCloud = {
enable: true,
package: 'egg-alicloud-open-api',
};
Configuration
Configure information in ${app_root}/config/config.{env}.js:
// ${app_root}/config/config.${env}.js
config.aliCloud = {
client: {
clientType: 'RPC', // RPC or ROA, default RPC
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
endpoint: '<endpoint>',
apiVersion: '<apiVersion>'
}
};
- The
clientType
option is for creatingRPC
style client orROA
style client, defaultROA
style client. - More options
Call api
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
// call SendSms api
const res = await ctx.aliCloud.request('SendSms', {
PhoneNumbers: '138xxxxxxx',
SignName: 'xxx',
TemplateCode: 'xxx',
TemplateParam: JSON.stringify({ code: 123456 })
});
ctx.body = res;
}
}
module.exports = HomeController;