@realsee/miniprogram
TypeScript icon, indicating that this package has built-in type declarations

0.1.11 • Public • Published

@realsee/miniprogram

如视小程序生态SDK集合

功能列表

  • [√] 如视Passport账号服务
  • [√] 如视小程序支付服务
  • [√] 如视小程序遥测服务
  • [√] 如视小程序VRWeview

接入指南

如视Passport账号服务
  1. 原生小程序用法
import { Passport } from '@realsee/miniprogram';

const passport = new Passport({ appId: '这个是开放平台的AppID' })

// 在获取用户手机号的回调里处理登录
const onGetUserPhoneNumber = async (ev) => {
  const getUserPhoneNumberResult = ev.detail
  const loginResult = await new Promise((resolve) => wx.login({ success: (res) => resolve(res) }))
  const result = await passport.login({ loginResult, getUserPhoneNumberResult })

  if (result !== false) {
    // 登录成功
    const userInfo = result
    console.log(userInfo)
  } else {
    // 登录失败
    console.error('登录失败')
  }
}

// 获取当前的token和当前的用户信息
const token = passport.token
const userInfo = passport.userInfo

// 获取最新的用户数据,调用成功会刷新passport.userInfo
const userInfo = await passport.getUserInfo()
  1. Taro示例
import { Button } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { Passport } from '@realsee/miniprogram'
import { useCallback } from 'react'

const passport = new Passport({ appKey: '如视Gateway的AppID' })

const Page = () => {
  const onGetPhoneNumber = useCallback(async ev => {
    if (ev.detail.code) {
      const getPhoneNumberResult = ev.detail
      const loginResult = await Taro.login()
      const user = await passport.login({ loginResult, getPhoneNumberResult })
      if (user !== false) {
        console.log('登录成功', user)
      } else {
        console.log('登录失败')
      }
    }
  }, [])

  return (
    <>
      <Button type='primary' openType='getPhoneNumber' onGetPhoneNumber={onGetPhoneNumber}>
        授权手机号登录
      </Button>
    </>
  )
}

export default Page
如视小程序支付服务
import { WechatPaymentOriginParams, WechatPaymentResult, requestWechatPayment } from '@realsee/miniprogram'

/**
 * 原始入参
 */
export interface WechatPaymentOriginParams {
  timeStamp: string
  nonceStr: string
  packageValue: string
  sign: string
  partnerId: string
  prepayId: string
  appId: string
  paySign: string
  signType: 'MD5' | 'HMAC-SHA256' | 'RSA'
}

/**
 * 返回结果
 */
export type WechatPaymentResult = { isSuccess: boolean; msg: string; params: WechatPaymentOriginParams }


/**
 * 调用示例
 */
try {
  const result = await requestWechatPayment(params: WechatPaymentOriginParams)
  if (result.isSuccess) {
    console.log('支付成功', msg)
  } else {
    console.log('支付失败', msg)
  }
} catch(e) {
  // 发生错误
  console.error(e)
}
如视小程序遥测服务
import { setRealseeTelemetryConfig, pushRealseeTelemetryEvent } from '@realsee/miniprogram'

// 进行配置
setRealseeTelemetryConfig({ appKey: '如视Gateway的AppID' })

// 上报数据
pushRealseeTelemetryEvent({ id: '事件id', name: '事件名', data: { foo: 'bar' } })
如视小程序VRWeview

参见如视开放平台文档:小程序容器

Dependents (0)

Package Sidebar

Install

npm i @realsee/miniprogram

Weekly Downloads

3

Version

0.1.11

License

SEE LICENSE IN TERMS.txt

Unpacked Size

1.02 MB

Total Files

50

Last publish

Collaborators

  • fengjiaojiao
  • liushu805
  • yangli004
  • maxiaoyan018
  • lichangyu
  • achillesdragon
  • lees_npm
  • emiyaaaaa
  • lichengjie
  • zythum
  • minhua