移动云nodeJs SDK使用条件:
- 从移动云订购页开通相应产品
- 获取Access Key ID(AK)和Secret Access Key(SK)对称加密方式验证接口调用者身份。AK和SK由移动云官方颁发给访问者,订购产品后可查看。
移动云API服务会对每个访问的请求进行身份验证,所以都需要在请求中包含签名(Signature)信息。 其中:
AK用于标识访问者的身份。 SK用于对请求签名字符串进行摘要加密,同时也是API服务器端验证签名字符串的密钥,用户应谨慎保管SK。
移动云nodeJs SDK支持6.0及以上版本的node,提供以下安装方式:
通过 npm 获取安装是使用 Node.js SDK 的推荐方法,npm 是 Node.js 的包管理工具。关于 npm 详细介绍可参见npm 官网
- 执行以下安装命令: npm install smartlib-web-sdk --save
- 在您的代码中引用对应模块代码,如下 SDK 示例。
// 导入对应产品模块的models。
import { selfdefinition } from "smartlib-web-sdk/ecloud-nodejs-sdk/api/ocr.js";
//接口调用
toBase64() {
//获取图片
let files = document.getElementById("upImageFile").files[0];
//图片转base64格式
var reader = new FileReader();
reader.readAsDataURL(files);
reader.onload = () => {
this.newBase64 = reader.result.replace(
/^data:image\/(png|jpg|jpeg);base64,/,
""
);
// 调用SDK接口
selfdefinition(
"AccessKey",
"SecretAccessKey",
"Image",
{ Image: this.newBase64, TemplateId: "126222879799902208" }
).then((res) => {
//用户自定义操作
console.log(res, "sdk");
});
};
},