# bsm-sdk **Repository Path**: robin901118/bsm-sdk ## Basic Information - **Project Name**: bsm-sdk - **Description**: 巴士盟js-sdk - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-02-27 - **Last Updated**: 2025-07-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 巴士盟js-sdk 第一步:在 main.js 中引入并使用,注意,一定要在巴士盟环境才可以使用 ```js //引入 import {use} from 'bsm-sdk' //使用 use() ``` 第二步:使用sdk ```js //引入sdk import appBridge from 'bsm-sdk' //使用 async function getAppInfo() { try { const {data} = await appBridge.ssGetAppInfo() appInfo.value = JSON.stringify(data) } catch (e) { console.error(e) } } ``` ### 判断是否是巴士盟环境 `2.1.1+` ```js //可以通过此标识判断 import {isBsm} from 'bsm-sdk' ``` ## sdk列表 ### 从相册选择图片或者拍照 ```js const imgs = ref([]) async function onChoose() { try { const {data} = await appBridge.ssTakePhotos() if (data != null) { // 显示原生传过来的图片 const bytes = new Uint8Array(data) const blob = new Blob([bytes], {type: 'image/png'}) imgs.value.push({ //本地路径 url: URL.createObjectURL(blob), //图片内容 blob }) } } catch (e) { console.error(e) } } ``` ### 获取当前GPS ```js /*国测局坐标转百度坐标*/ /*BMap自己引入百度地图的js*/ function transGPStoBPointsByGcj02(Point) { return new Promise((resolve, reject) => { try { const convertor = new BMap.Convertor() const pointArr = [] pointArr.push(Point) /* from---------------------- 1:GPS设备获取的角度坐标,WGS84坐标; 2:GPS获取的米制坐标、sogou地图所用坐标; 3:google地图、soso地图、aliyun地图、mapabc地图和amap地图所用坐标,国测局(GCJ02)坐标; 4:3中列表地图坐标对应的米制坐标; 5:百度地图采用的经纬度坐标; 6:百度地图采用的米制坐标; 7:mapbar地图坐标; 8:51地图坐标 * */ /* to---------------------- 3:国测局(GCJ02)坐标; 4:3中对应的米制坐标; 5:bd09ll(百度经纬度坐标); 6:bd09mc(百度米制经纬度坐标) * */ convertor.translate(pointArr, 3, 5, data => { data.status === 0 ? resolve(data.points[0]) : reject('转换失败') }) } catch (e) { reject(e.toString()) } }) } async function getGeo() { try { const location = await appBridge.ssGetLocation() const { lng, lat } = await transGPStoBPointsByGcj02(new BMap.Point(location.data.longitude, location.data.latitude)) info.value = `从手机获取的GPS:${location.data.longitude},${location.data.latitude}
转换成百度坐标:${lng},${lat}` } catch (e) { console.error(e) } } ``` ### 设置导航标题 ```js async function onSet() { try { await appBridge.ssAppBarTitle({title: '巴士盟123'}) } catch (e) { console.error(e) } } ``` ### 扫二维码 ```js async function onScan() { try { const {data} = await appBridge.ssOpenScanCode('') alert(`扫码出来的内容是:${JSON.stringify(data)}`) } catch (e) { console.error(e) } } ``` ### 分享给微信联系人 ```js async function onShare() { try { await appBridge.ssOpenShare({ title: '标题,非必传', image: '图片URL,非必传', link: '跳转链接,必填', desc: '描述,必填' }) } catch (e) { console.error(e) } } ``` ### 获取用户信息 ```js async function getUserInfo() { try { const {data} = await appBridge.ssGetUserInfo() console.log(JSON.stringify(data)) } catch (e) { console.error(e) } } ``` ### 获取app信息 ```js async function getAppInfo() { try { const {data} = await appBridge.ssGetAppInfo() console.log(JSON.stringify(data)) } catch (e) { console.error(e) } } ``` ### 支付 ```js async function openPay() { try { await appBridge.ssOpenPay({ appCode: '应用CODE', tenantId: '租户id', groupOrderNo: '组合订单号', payAmount: '应付款' }) } catch (e) { console.error(e) } } ``` ### 跳转小程序 ```js async function openMiniprogram() { try { await appBridge.ssOpenMiniprogram({ appid: '小程序APPID', path: '指定小程序的页面路径,可以带参数', params: '额外参数:根据需要,可能还需要传递其他参数,如跳转时携带的数据等' }) } catch (e) { console.error(e) } } ``` ### 跳转其他APP ```js async function openApp() { try { await appBridge.ssOpenApp({ scheme: 'APP的scheme' }) } catch (e) { console.error(e) } } ``` ### 关闭应用(整个关闭) ```js async function onBack() { try { await appBridge.ssExitApp() } catch (e) { console.error(e) } } ``` ### 退出webview ```js async function backApp() { try { await appBridge.ssBack() } catch (e) { console.error(e) } } ``` ### 隐藏、显示导航栏 `1.1.0+` ```js async function hideNav() { try { //隐藏 await appBridge.ssHideNav(false) //显示 // await appBridge.ssHideNav(true) } catch (e) { console.error(e) } } ``` ### 跳转APP内部某个页面 `1.2.0+` ```js async function jumpToAppPage() { try { await appBridge.ssJumpToPage() } catch (e) { console.error(e) } } ``` ### 打开、关闭loading `1.2.0+` ```js async function toggleLoading() { try { //打开 await appBridge.ssToggleLoading(true) //关闭 // await appBridge.ssToggleLoading(false) } catch (e) { console.error(e) } } ``` ## AI扩展 ```js //新增ai-plugin import {aiPlugin} from 'bsm-sdk' ``` ### 设置发送消息状态 `2.1.0+` ```js async function sendLoading() { try { //打开 await aiPlugin.ssSetSendLoading(true) //关闭 // await aiPlugin.ssSetSendLoading(false) } catch (e) { console.error(e) } } ``` ### 点击超链接,把内容发送给APP `2.1.0+` ```js async function sendLinkContext() { try { await aiPlugin.ssSendLinkContext('https://www.baidu.com') } catch (e) { console.error(e) } } ``` ### 点击多媒体组件,把src发送给APP `2.1.0+` ```js async function sendMediaSrc() { try { await aiPlugin.ssSendMediaSrc('https://www.baidu.com/ssjkhkjhk.mp3') } catch (e) { console.error(e) } } ``` ### 向APP发送最新的conversation_id `2.2.0+` ```js async function ssSendChatCID() { try { await aiPlugin.ssSendChatCID('xxxx-sss-www') } catch (e) { console.error(e) } } ``` ### 前端监听APP调用H5的方法示例 `2.2.0 update` ```js window._evokeAiAndSendMessage = msg => console.log('收到APP的消息:', msg) window._stopAiChat = () => console.log('收到APP停止对话的指令') window._newAiChat = () => console.log('收到APP发起新对话的指令') window._changeChatByConversationId = id => console.log('收到APP切换新的conversation_id的指令,新id:' + id) window._setChatRoomTitle = title => console.log('收到APP更改聊天室title的指令,新title:' + title) ```