npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yoyolearn-mobile-mp-sdk

v0.1.8

Published

yoyolearn 小程序运行时 SDK:统一封装支付、宿主能力、用户态等,兼容 uniapp 直接打包小程序与嵌入 yoyolearn-app 两种场景。

Downloads

518

Readme

@yoyolearn/mobile-mp-sdk

yoyolearn 小程序运行时 SDK:统一封装下单、调起支付、宿主能力等,支持以下三种运行模式:

| 运行模式 | 触发场景 | 支付通道 | | --- | --- | --- | | embedded-uniapp | 在 yoyolearn-app(Android / iOS / 鸿蒙)通过 DCloud UniMP 嵌入 | 调宿主桥 -> 原生微信 SDK -> trade_type=APP | | wechat-mp | 直接打包成微信小程序上架 | uni.requestPayment JSAPI | | h5 | 浏览器内运行 | 仅返回 h5Url,由业务跳转 |

安装

由于这里的源码会发布到 npm,使用方按需安装即可。

npm install @yoyolearn/mobile-mp-sdk

快速开始

import {
  initSdk,
  login,
  pay,
  payWithOrder,
  queryPayState,
  waitOrderPaid,
  getHostUserToken,
  closeMiniApp,
} from '@yoyolearn/mobile-mp-sdk';

initSdk({
  apiBaseUrl: 'https://api.yoyolearn.com',
  tokenProvider: async () => uni.getStorageSync('token'),
  defaultPayment: {
    paymentMethod: 'WECHAT',
    wechatPlatformDataKey: '402895e29c273a74019c2b74b75b0001',
  },
  debug: true,
});

const result = await pay({
  payCents: 9900,
  outsideOrderNo: 'reading-2025-0001',
  servicePlatformDataKey: 'reading-valley',
});

if (result.paid) {
  console.log('支付成功', result.orderDataKey, result.transactionId);
}

API

initSdk(config)

  • apiBaseUrl:yoyolearn-service 接口地址(必填)
  • tokenHeaderKey:默认 YOYOLEARN-USER-TOKEN
  • token / tokenProvider:用户态获取方式
  • defaultPayment.paymentMethod:默认 WECHAT
  • defaultPayment.wechatPlatformDataKey:默认 WeChat 平台
  • runtime:覆盖运行时自动探测
  • debug:打开日志

login(options?): Promise<LoginResult>

统一登录:

  • 嵌入 APP:读取宿主已登录 token / 用户信息(host:getUserInfo),不调微信登录
  • 微信小程序:uni.login + /api/system/user/wechat/login

pay(req): Promise<PayResult>

端到端支付(SDK 内部下单):

  • 嵌入 APP:转发到宿主 -> 宿主原生调起微信支付 -> 轮询后端 -> 返回结果
  • 微信小程序:takeOrder({payType: 'JSAPI'}) -> uni.requestPayment -> 二次确认订单

payWithOrder(order, orderDataKey?)

业务接口已下单并返回 SystemOrderTakeResponse 后调起支付(e学数独 VIP/闯关/报名等):

  • 嵌入 APP:pay:invoke -> 宿主用已有 prepay 调微信 APP 支付
  • 微信小程序:uni.requestPayment + queryPayState

takeOrder(req) / queryPayState(orderDataKey) / waitOrderPaid(orderDataKey)

直接调后端,业务自定义流程时使用。

宿主能力(仅嵌入 APP 有效)

  • getHostUserToken() 获取宿主登录态 token
  • getHostUserInfo() 获取宿主已登录的完整用户对象(含 token,避免再调后端 /system/user/me
  • getHostConfig() 获取宿主配置(apiBaseUrl / wechatPlatformDataKey / platform)
  • closeMiniApp() 关闭小程序
  • setNavBarTitle(title) 修改导航栏标题
  • openUrl(url) 让宿主 UrlProcessor 处理一个 URL:
    • http:// / https:// —— 宿主 WebView 打开
    • yoyolearn://mini-program:<mpKey>/<path>?<params> —— 打开内嵌小程序
    • yoyolearn://mini-program-dev:<devKey>/<path>?<params> —— 开发模式小程序
    • yoyolearn://article-content:<dataKey> / yoyolearn://article-preview:<dataKey> —— 打开文章
    • yoyolearn-app://yoyolearn:// 等价
    • 微信小程序运行模式下 HTTPS 链接降级到 pages/webview/index?url=...(约定页面),yoyolearn:// 链接 toast 提示
    • H5 模式下 HTTPS 直接 window.location.href
  • shareViaHost(req) 调起宿主分享面板(当前宿主返回 unimplemented,等原生分享接入)

与 yoyolearn-app 宿主协议

小程序侧:

uni.postMessage({
  data: {
    event: 'pay:request',
    requestId: 'bridge_xxx',
    data: { payCents: 9900, ... }
  }
});

宿主侧 IOnUniMPEventCallBack / mp.on('UniMPEventReceive') 接收事件,处理后通过:

mp.sendUniMPEvent('yyHostReply', {
  requestId: 'bridge_xxx',
  ok: true,
  data: { paid: true, orderDataKey: 'xxx' }
});

或者使用 UniMP SDK 提供的 keepAlive callback 直接回执。