1.0.5 • Published 3 years ago

@souche2014/bulter-api v1.0.5

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

bulter-api 车管家小程序API

车管家小程序为合作方提供的开放api服务,此sdk仅用于开发期间的功能接入,调用api方法也只会返回固定的假数据,只有当三方代码运行在车管家小程序中时,才会返回有效数据

使用说明:

  1. 添加依赖
yarn add @souche2014/bulter-api
  1. 使用(示例):
import bulterApi from '@souche2014/bulter-api'

//创建api实例
const api = bulterApi({ partner: '填写你在车管家的唯一标识,建议使用分包名' })
//发送埋点
api.bury('userClickPayButton',{time:new Date().valueof(),loginState:false})
//用户注册
api.register({
    encryptedData: '通过调用微信的getPhoneNumber获取到的加密串',
    iv: '加密算法的初始向量',
    scope: 'all'
  }).then(resp=>{
      if(resp.success){
          console.log('authCode is ',resp.data)
      }else{
          console.log('err is ',resp.msg,'err code is ',resp.code)
      }
  }).catch(e=>{
    console.log(e)
  })
//获取用户信息
api.getUserInfo({
    scope: 'all'
  }).then(resp=>{
      if(resp.success){
          console.log('authCode is ',resp.data)
      }else{
          console.log('err is ',resp.msg,'err code is ',resp.code)
      }
  }).catch(e=>{
    console.log(e)
  })

API 说明

  /**
   * 发送埋点
   * @param typeId 埋点类型 eg:buyBtnClicked
   * @param data 埋点数据 eg:{ time: '2020-02-02' , user:'zhangsan' }
   */
  bury: (typeId: string, data?: Dict) => void;

  /**
   * 手机号注册
   * @param scope 接口调用业务code,当前传 all 即可
   * @param encryptedData 微信小程序获取手机号接口返回的加密数据
   * @param iv 加密算法的初始向量
   * @return BulterApiResponse<string> 参见 BulterApiResponse 说明
   * 示例:{
   *  code:200,
   *  success:true,
   *  message:'ok',
   *  data:'authCode' //使用此authCode调用我方后台接口获取用户信息,用户信息包括unionId,openId,phoneNumber,车牌号等
   * }
   */
  register: (params: {
    encryptedData: string;
    iv: string;
    scope: string;
  }) => Promise<BulterApiResponse<string>>;
  

  /**
   * 获取用户信息
   * @param scope 接口调用业务code,当前传 all 即可
   * @return BulterApiResponse<string> 参见 BulterApiResponse 说明
   * 示例:{
   *  code:200,
   *  success:true,
   *  message:'ok',
   *  data:'authCode' //使用此authCode调用我方后台接口获取用户信息,用户信息包括unionId,openId,phoneNumber,车牌号列表等
   * }
   */
  getUserInfo: (params: {
    scope: string;
  }) => Promise<BulterApiResponse<string>>;

  /**
   * 打开宿主小程序页面:
   * @param pageName:页面名称,必填
   * @param data:打开页面时传递的参数,可选
   * 目前可打开的页面:
   *  home:打开首页
   */
  openPage(pageName: string, data?: Dict);

BulterApiResponse

字段类型说明
successBoolean接口调用是否成功
dataAny接口返回数据
msgString失败时的错误提示
codeString接口调用的状态码(出错时凭此码与我方调试)
traceIdString接口调用链路id

change log

  • 1.0.5

    • 没有对外的更改
  • 1.0.4
    • BulterApiResponse:code 字段类型替换为String
    • BulterApiResponse:message 更改为 msg,含义不变
    • demo 添加异常处理
1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago