1.0.42 • Published 3 years ago

xx_js_sdk_v2 v1.0.42

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

XX

js sdk

onReady

监听SDK准备完毕,可多次监听。其他任何调用都需要在onReady之后

XX.onReady(()=>{
    
});

getUnionid

获取用户unionid

const res = await XX.getUnionid(); 
if(res.status){
    const unionid = res.data;
}

getUserId

获取用户ID

const res = await XX.getUserId(); 
if(res.status){
    const userId = res.data;
}

getRelationId

获取淘宝渠道ID

const res = await XX.getRelationId(); 
if(res.status){
    const relationId = res.data;
}

openAppPage

打开APP页面

const res = await XX.openAppPage({
    name: "app_login",                  // app内部页面名称,需要APP内部定义好的
    pageParam: {                        // 参数,APP页面接收
        type: 1
    }
}); 

const result = res.data;                // 下一个页面返回的result数据

openWebPage

打开web页面

const res = await XX.openWebPage({
    url: "https://www.baidu.com",                  // app内部页面名称,需要APP内部定义好的
    title: "标题",                                 // 不传标题时会使用web页面的title, 头部通过url中的titlebar参数控制,当titlebar=0时则不显示头部
    pageParam: {                                   // 参数,打他开页面接收
        type: 1
    }
}); 

const result = res.data;                            // 下一个页面返回的result数据

closePage

关闭页面

XX.closePage({
    result:{                                        // 可选参数,返回给上一个页面的数据
        success: true
    }
});

getWebPageParam

获取页面参数

const params = await XX.getWebPageParam();        // 获取打开页面时传递的pageParam参数

installed

判断是否安装APP

const res = await XX.installed({             
    scheme: "weixin://"
});
const installed = res.data;                        // 返回boolean类型

openApp

根据url scheme启动APP

const res = await XX.openApp({             
    scheme: "weixin://"
});
const reuslt = res.data;                        // 返回boolean类型

saveImageToAlbum

保存图片到相册,需要请求运行时储存权限

const res = await XX.saveImageToAlbum({
    path: "本都图片绝对路径"
});

var result = res.data;                              // 返回boolean类型

base64FromImage

base64转图片

const res = await XX.base64FromImage({
    base64: ""                                      // 支持带头的
});

const path = res.data;                              // 本地绝对路径

imageFromBase64

图片转base64

const res = await XX.imageFromBase64({
    path: ""                                      // 支持带头的
});

const path = res.data;                              // base64 带头

download

下载文件

const res = await XX.download({
    path:"https://www.image.com/123.png"            // 网络文件地址
});

const path = res.data;                              //  本地绝对路径

hasPermission发起权限请求

检测权限

var permissions = [
    'calendar',                                 // 日历
    'camera',                                   // 相机
    'contacts',                                 // 通讯录
    'location',                                 // 定位
    'locationAlways',                           // 定位-后台运行
    'locationWhenInUse',                        // 定位-使用时权限
    'mediaLibrary',                             // ios-媒体库
    'microphone',                               // 麦克风
    'phone',                                    // 读取手机状态
    'photos',                                   // ios-相册
    'reminders',                                // 日历提醒事项
    'sensors',                                  // 体感传感器
    'sms',                                      // 发送短信
    'speech',                                   // 语音识别
    'storage',                                  // android-储存
    'ignoreBatteryOptimizations',               // 电池
    'notification',                             // 通知
    'access_media_location',
    'activity_recognition',
    'unknown',
];
const res = await XX.requestPermission({
    permissions: []                             // 需要请求的权限数组
});

var data = res.data;                            // 返回一个数组
/**************************************************************/
data = [{
    name: 'calendar',                           权限名称
    permanentlyDenied: false,                   是否永久决绝了权限,无法再发起请求,只能通过openAppSetting打开应用详情设置
    restricted: false,                          是否受限制的权限,比如家长控制
    granted: true                               是否通过权限申请
}]
/**************************************************************/

requestPermission

发起权限请求

var permissions = [
    'calendar',                                 // 日历
    'camera',                                   // 相机
    'contacts',                                 // 通讯录
    'location',                                 // 定位
    'locationAlways',                           // 定位-后台运行
    'locationWhenInUse',                        // 定位-使用时权限
    'mediaLibrary',                             // ios-媒体库
    'microphone',                               // 麦克风
    'phone',                                    // 读取手机状态
    'photos',                                   // ios-相册
    'reminders',                                // 日历提醒事项
    'sensors',                                  // 体感传感器
    'sms',                                      // 发送短信
    'speech',                                   // 语音识别
    'storage',                                  // android-储存
    'ignoreBatteryOptimizations',               // 电池
    'notification',                             // 通知
    'access_media_location',
    'activity_recognition',
    'unknown',
];
const res = await XX.requestPermission({
    permissions: []                             // 需要请求的权限数组
});

var data = res.data;                            // 返回一个数组
/**************************************************************/
data = [{
    name: 'calendar',                           权限名称
    permanentlyDenied: false,                   是否永久决绝了权限,无法再发起请求,只能通过openAppSetting打开应用详情设置
    restricted: false,                          是否受限制的权限,比如家长控制
    granted: true                               是否通过权限申请
}]
/**************************************************************/

openAppSetting

打开APP设置详情页面

XX.openAppSetting();

setCopyText

设置文本到剪贴板

const res = await XX.setCopyText({
    text:"asdsdsd"          
});

getCopyText

获取剪贴板内容

const res = await XX.getCopyText();
const text= res.data;                   // 剪贴板内容

clearCopyText

清除剪贴板内容

const res = await XX.clearCopyText();

getSafeArea

获取状态栏高度和安全区域尺寸

const res = await XX.getSafeArea();
const safeArea = res.data;                  
const top = safeArea.top;
const left = safeArea.left;
const right = safeArea.right;
const bottom = safeArea.bottom;

淘宝sdk

文档详细

平多多sdk

文档详细

京东sdk

文档详细

唯品会sdk

文档详细

微信sdk

文档详细

支付宝sdk

文档详细

系统分享

文档详细