egg-alicloud-open-api

1.0.1 • Public • Published

egg-alicloud-open-api

NPM version build status Test coverage David deps Known Vulnerabilities npm download

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 creating RPC style client or ROA style client, default ROA 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;

License

MIT

Package Sidebar

Install

npm i egg-alicloud-open-api

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

10.3 kB

Total Files

18

Last publish

Collaborators

  • schwann