@alicloud/mpserverless-sdk
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "@alicloud/mpserverless-sdk", | ||
"author": "zack-lin <linzegia@gmail.com>", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "JavaScript SDK for Alicloud MPServerless", | ||
@@ -6,0 +6,0 @@ "main": "dist/umd/index.js", |
@@ -1,10 +0,10 @@ | ||
# miniprogram-sdk | ||
# MPServerless SDK | ||
[![NPM](https://nodei.co/npm/@ant-basement/miniprogram-sdk.png)](https://nodei.co/npm/@ant-basement/miniprogram-sdk/) | ||
Basement SDK for Alipay Mini Program IDE | ||
MPServerless SDK | ||
## Getting Started | ||
> npm install --save @ant-basement/miniprogram-sdk | ||
> npm install --save @alicloud/mpserverless-sdk | ||
@@ -14,16 +14,24 @@ ## Usage | ||
```js | ||
basement.user.getInfo().then(res => { | ||
const MPServerless = require('@alicloud/mpserverless-sdk'); | ||
const mpServerless = new MPServerless({ | ||
uploadFile: my.uploadFile, | ||
request: my.request, | ||
getAuthCode: my.getAuthCode, | ||
}, { | ||
appId: 'xxx', // 小程序应用标识 | ||
spaceId: 'xxx', // 服务空间标识 | ||
clientSecret: 'xxx', // 服务空间 secret key | ||
endpoint: 'https://webgw.basement.nlark.com' // 服务空间地址,从小程序 serverless 控制台处获得 | ||
}); | ||
mpServerless.user.getInfo().then(res => { | ||
console.log('user info', res); | ||
}); | ||
basement.db.collection('task').find().then(res => { | ||
mpServerless.db.collection('task').find().then(res => { | ||
console.log('task list', res.result); | ||
}); | ||
basement.function.invoke('sayHello', { name: 'angela' }).then(res => { | ||
mpServerless.function.invoke('sayHello', { name: 'angela' }).then(res => { | ||
console.log(res.result + ' says angela'); | ||
}); | ||
basement.appService.invoke('myApp', { method: 'GET' }).then(res => { | ||
console.log(res.result + 'userId say hello to angela'); | ||
}); | ||
my.chooseImage({ | ||
@@ -33,9 +41,22 @@ chooseImage: 1, | ||
const path = res.apFilePaths[0]; | ||
const options = { | ||
env: 'public', | ||
filePath: path, | ||
}; | ||
basement.file.uploadFile(options).then(res => { | ||
console.log('file info', res); | ||
const that = this; | ||
my.getImageInfo({ | ||
src: path, | ||
success: function(res) { | ||
const options = { | ||
filePath: path, | ||
extension: res.type, | ||
headers: { | ||
contentDisposition: 'inline', | ||
}, | ||
}; | ||
app.mpServerless.file.uploadFile(options).then((image) => { | ||
that.setData({ | ||
iconUrl: image.fileUrl, | ||
}); | ||
}).catch(console.error); | ||
}, | ||
fail: function(err) { | ||
console.log(err); | ||
} | ||
}); | ||
@@ -42,0 +63,0 @@ }, |
840898
64