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.
| Method | URL | Called by | Authentication |
|---|---|---|---|
POST | https://open.acrossflow.com/v1/mp/issue | Old mini program's backend | Issue 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
- Request with the existing session credential
/v1/mp/issuewith the openId from the server session- Single-use jump token
- Jump parameters
wx.navigateToMiniProgramwithaf_token- Redeem the token and report
- 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.
- The backend reads the member's
openIdfrom its server-side session, calls/v1/mp/issue, and returns the jump parameters to the relay page. - The relay page opens the new mini program with
wx.navigateToMiniProgram, passing the token asaf_tokenboth in the landing path's query string and inextraData. - The new mini program's backend redeems the token, credits the member, and reports the migration; see Redeem jump tokens and report migrations.
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.comas 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, addapp.acrossflow.comas a business domain; business domains need an ICP filing,acrossflow.comhas 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
| Field | Type | Required | Description |
|---|---|---|---|
openId | string | Yes | The 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
}
| Field | Type | Description |
|---|---|---|
appId | string | The new mini program's AppID, from the channel's jump target |
path | string | Landing path, from the channel's jump target; an empty string opens the new mini program's home page |
envVersion | string | The new mini program's version: release, trial, or develop |
token | string | Single-use jump token, passed to the new mini program as af_token |
expiresIn | integer | Validity in seconds |
Notes
- A jump token can be redeemed once. Issue a new one for every jump.
- An
openIdthe merchant never imported can still be issued; the new mini program then receivesmember: nullon 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.
| HTTP | error | Description |
|---|---|---|
| 400 | invalid | openId is missing or malformed |
| 402 | paused | The 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 |
| 403 | channel | The channel is not a server-integration channel, or is disabled |
| 409 | target | The channel has no jump target configured |
| 429 | rate_limited | This Issue token has issued 60 jump tokens in the past 60 seconds |