@bytedance-ad/fuwu-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

群峰 SDK

提供应用服务市场内购相关功能

SDK API

// 查询应用可用付费功能点入参
export interface ICheckFuncsAvailableOpts {
  funcKeys?: string[]
}
// 查询应用可用付费功能点返回值
interface ICheckFuncsAvailableResult {
  code: 0 | 1 // 0 可用,1 不可用
  funcKey: string // 功能key
  msg: string
}

export interface ISdkRequests {
  checkFuncsAvailable: (data?: ICheckFuncsAvailableOpts) => Promise<ICheckFuncsAvailableResult[]>
}

// SDK初始化入参
export interface ISdkCtorOpts {
  appId: string
  requests: ISdkRequests
}

// 打开付款对话框入参
export interface IOpenAppPaidFeatureOpts {
  funcKey: string
}
// 付款对话框关闭返回值
interface IOpenAppPaidFeatureResult {
  code: 0 | 1 | 2 // 执行结束会关闭弹窗,0表示用户购买成功,1表示已经购买过了,无需再次购买,2表示未购买
  msg: string
}
  • new QfSdk(opts: ISdkCtorOpts): 初始化 SDK
  • qfSdk.checkFuncsAvailable(data?: ICheckFuncsAvailableOpts): 查询功能点是否已购买,参数可为空,为空时查询所有付费点
  • qfSdk.openAppPaidFeature(opts: IOpenAppPaidFeatureOpts): 打开功能付费对话框
  • qfSdk.destroy(): 销毁 SDK

使用示例

import QfSdk from '@bytedance-ad/fuwu-sdk';

const qfSdk = new QfSdk({
  appId: 'xxx',
  requests: {
    checkFuncsAvailable: (data) => {
      // 返回 Promise<ICheckFuncsAvailableResult[]>
    },
  },
});

// 检查功能是否可用
qfSdk
  .checkFuncsAvailable({
    funcKeys: ['xxx'], // 功能点key列表, 可不传,默认返回全量可用的功能
  })
  .then((results) => {});

// 唤起付款对话框
qfSdk
  .openAppPaidFeature({
    funcKey: 'xxx', // 功能点key
  })
  .then((result: IOpenAppPaidFeatureResult) => {
    if (result.code === 0) {
      console.log('购买成功');
    } else if (result.code === 1) {
      console.log('已经购买过了,无需再次购买');
    } else if (result.code === 2) {
      console.log('未购买')
    }
  });

// 销毁SDK
qfSdk.destroy()

源码目录说明

  • src/pages: 开发时的入口文件,index 为主入口,iframe 为调试时的子页面
  • src/sdk: sdk 源码

Readme

Keywords

none

Package Sidebar

Install

npm i @bytedance-ad/fuwu-sdk

Weekly Downloads

0

Version

0.0.6

License

ISC

Unpacked Size

51.6 kB

Total Files

8

Last publish

Collaborators

  • manwithmask
  • jianghong.0103
  • xinzhu
  • mui-bot
  • addone-robot
  • shanxiaohan
  • harperyang
  • giflee
  • bytednpm
  • sakop
  • wp-byte
  • shimina