AcrossFlow Start free

Old mini program: issue jump tokens from your backend

The default channel setup: the old mini program's backend uses an Issue access token to request jump tokens for signed-in members.

MethodURLCalled byAuthentication
POSThttps://open.acrossflow.com/v1/mp/issueOld mini program's backendIssue token

Server integration is the default channel setup: the old mini program's backend requests jump tokens from AcrossFlow for the OpenID of a signed-in member, with no WeChat authorization required. For authentication, response structure, and common error codes, see the API overview.

Call sequence

Relay pageOld backendAcrossFlowNew mini program
  1. Request with the existing session credential
  2. /v1/mp/issue with the openId from the server session
  3. Single-use jump token
  4. Jump parameters
  5. wx.navigateToMiniProgram with af_token
  6. Redeem the token and report
The Issue token stays on the old backend. The relay page never handles the token or sends an openId.
  1. The member starts a jump in the old mini program. The relay page calls the old mini program's backend with its existing session credential.
  2. The backend reads the member's openId from its server-side session, calls /v1/mp/issue, and returns the jump parameters to the relay page.
  3. The relay page opens the new mini program with wx.navigateToMiniProgram, passing the token as af_token both in the landing path's query string and in extraData.
  4. The new mini program's backend redeems the token, credits the member, and reports the migration; see Redeem jump tokens and report migrations.
openId must come from the server-side session

Never use an openId supplied by the client; it can be forged. Issuing on it would let anyone claim any member's points and stored value. The same applies to the Issue token: whoever holds it can impersonate any member, so it must stay on the server.

Prerequisites

  • In the Dashboard, create the channel with Server integration, enable it, import the member sheet, and configure the jump target.
  • On the channel's Integration tab, create two access tokens: an Issue token for the old mini program's backend and a Redeem token for the new one's.
  • The old mini program does not need open.acrossflow.com as a request domain; the relay page calls only its own backend. So this method works for old mini programs registered in mainland China too. If you also add a web-view page for the jump page built in the Dashboard, add app.acrossflow.com as a business domain; business domains need an ICP filing, acrossflow.com has none, and mini programs registered in mainland China cannot add it.
  • The channel's Integration tab shows its jump page URL. Complete backend and page code is under Example.
  • The old mini program's privacy policy must state that the member's OpenID is shared with AcrossFlow to identify members.

Issue a jump token

POST https://open.acrossflow.com/v1/mp/issue
Authorization: Bearer aft_…
Content-Type: application/json

{ "openId": "<the member's OpenID in the old mini program>" }

Request parameters

FieldTypeRequiredDescription
openIdstringYesThe member's OpenID in the old mini program, taken from the server-side session

Response

{
  "ok": true,
  "appId": "wx…",
  "path": "pages/index/index",
  "envVersion": "release",
  "token": "…",
  "expiresIn": 600
}
FieldTypeDescription
appIdstringThe new mini program's AppID, from the channel's jump target
pathstringLanding path, from the channel's jump target; an empty string opens the new mini program's home page
envVersionstringThe new mini program's version: release, trial, or develop
tokenstringSingle-use jump token, passed to the new mini program as af_token
expiresInintegerValidity in seconds

Notes

  • A jump token can be redeemed once. Issue a new one for every jump.
  • An openId the merchant never imported can still be issued; the new mini program then receives member: null on redemption.
  • Each Issue token is limited to 60 calls per minute; see Rate limits.
  • Revoking an Issue token immediately voids every unredeemed jump token it issued. If you suspect a leak, revoke first, then create a new token.

Example

Old mini program's backend (Node.js / Express):

app.post("/acrossflow/jump", requireLogin, async (req, res) => {
  // openId comes from the server-side session only
  const openId = req.session.openId;
  try {
    const response = await fetch("https://open.acrossflow.com/v1/mp/issue", {
      method: "POST",
      headers: {
        authorization: `Bearer ${process.env.ACROSSFLOW_ISSUE_TOKEN}`,
        "content-type": "application/json",
      },
      body: JSON.stringify({ openId }),
    });
    const isJson = (response.headers.get("content-type") || "").includes("application/json");
    const data = isJson ? await response.json() : null;
    if (!data || !data.ok) {
      // Log AcrossFlow errors on the server; return your own error to the relay page
      console.error("acrossflow issue failed", response.status, data && data.error);
      return res.status(502).json({ ok: false });
    }
    const { appId, path, envVersion, token } = data;
    res.json({ ok: true, appId, path, envVersion, token });
  } catch (error) {
    console.error("acrossflow issue failed", error);
    res.status(502).json({ ok: false });
  }
});

Do not pass AcrossFlow error responses through to the relay page: a status such as 401 access_token would be read by the client as its own session expiring. Log the error code on the server and return your own error to the relay page.

Old mini program pages

Add a relay page that makes the jump to the old mini program, and link to it from an existing entry point such as a home banner or the member centre. To show the jump page built in the AcrossFlow Dashboard inside the old mini program, you can also add a web-view page that opens it and configure a business domain; mini programs registered to an individual or in mainland China cannot use it. Without it, drop pages/acrossflow-page/index and its page below.

Add both paths to the pages list in app.json:

{
  "pages": [
    "pages/acrossflow-page/index",
    "pages/acrossflow-jump/index"
  ]
}

pages/acrossflow-page/index.wxml, using the jump page URL shown on the channel's Integration tab:

<web-view src="https://app.acrossflow.com/p/chn_…"></web-view>

pages/acrossflow-jump/index.js:

// Your own backend
const API = "https://your-backend.example.com/acrossflow/jump";

Page({
  data: { state: "loading", message: "" },
  onShow() {
    this.prepare();
  },
  prepare() {
    this.target = null;
    this.setData({ state: "loading" });
    wx.request({
      url: API,
      method: "POST",
      header: { authorization: getApp().globalData.sessionToken }, // Use the old mini program's existing session credential
      success: ({ data }) => this.ready(data),
      fail: () => this.setData({ state: "error", message: "Network unavailable" }),
    });
  },
  ready(data) {
    if (data && data.ok) {
      this.target = data;
      this.setData({ state: "ready" });
    } else {
      this.setData({ state: "error", message: "Unable to continue right now" });
    }
  },
  go() {
    const t = this.target;
    if (!t) return;
    const options = {
      appId: t.appId,
      envVersion: t.envVersion,
      extraData: { af_token: t.token },
    };
    if (t.path) options.path = t.path + (t.path.includes("?") ? "&" : "?") + "af_token=" + t.token;
    wx.navigateToMiniProgram(options);
  },
});

pages/acrossflow-jump/index.wxml:

<view style="padding: 120rpx 48rpx; text-align: center;">
  <button wx:if="{{state === 'ready'}}" type="primary" bindtap="go">Go now</button>
  <block wx:elif="{{state === 'error'}}">
    <view style="margin-bottom: 24rpx; color: #888;">{{message}}</view>
    <button size="mini" bindtap="prepare">Retry</button>
  </block>
  <view wx:else style="color: #888;">Preparing…</view>
</view>

Error codes

Error codes specific to this endpoint. For common error codes, see the API overview.

HTTPerrorDescription
400invalidopenId is missing or malformed
402pausedThe merchant's account is over its plan limits and the grace period has ended, so jumps are paused. Jump tokens already issued can still be redeemed
403channelThe channel is not a server-integration channel, or is disabled
409targetThe channel has no jump target configured
429rate_limitedThis Issue token has issued 60 jump tokens in the past 60 seconds