autojs-bmob-sdk
SDK介绍
本SDK通过bmob restful API支持autojs数据库读写操作。
安装使用
在Autojs中使用
复制代码到main.js或下载autojs-bmob-sdk.js
然后在项目中引入
var Bmob = require('../autojs-bmob-sdk.js');
/*
* @Author: autojs.xyz
* @version 2.2.2
* @blog: blog.csdn.net/vip
* @github: github.com/hnauto/Autojs-bmob-sdk
* @Last Modified time: 2020-03-15 18:09:00
* @Description: Bmob数据库autojs SDK
* @Memo: 部分代码参考原作者 家 QQ:203118908
*/
//参见http://doc.bmob.cn/data/restful/
const APPID = '';// APPID
const REST_ID = ''; //REST ID
/*------------bmob数据库的增删改查*------------*/
const Bmob = (function () {
function Bmob(url, appId, restKey) {
this.baseUrl = url;
this.appId = appId;
this.restKey = restKey;
}
Bmob.prototype.makeRequest = function (method, url, json, sessionToken, callback) {
url = this.baseUrl + url;
var options = {
};
options.contentType = "application/json";
options.method = method;
if (json) {
options.body = JSON.stringify(json);
}
sessionToken = sessionToken || "";
options.headers = {
"X-Bmob-Application-Id": this.appId,
"X-Bmob-REST-API-Key": this.restKey,
"Content-Type": "application/json",
// 加入X-Bmob-Session-Token
"X-Bmob-Session-Token": sessionToken
}
return http.request(url, options, callback);
}
//获取服务器时间
Bmob.prototype.timestamp = function () {
return this.makeRequest("GET", "/timestamp", null).body.json();
}
/*------------------------用户表------------------------------*/
//添加用户
Bmob.prototype.userCreate = function (username,password,email,phone,info) {
let user = {
"username": username,"password": password,
// "email": email,
// "mobilePhoneNumber": phone,
// "info": info
}
return this.makeRequest("POST", "/users/", user).body.json();
}
//添加手机用户
Bmob.prototype.userMobileCreate = function (phoneNum,smsCode) {
let user = {
"mobilePhoneNumber":phoneNum,"smsCode":smsCode}
return this.makeRequest("POST", "/users/", user).body.json();
}
//用户登录
Bmob.prototype.userLogin = function (username,password) {
let url = encodeURI(util.format('/login?username=%s&password=%s', username, password));
return this.