# Mini-Program Login FAQ
Note
For WeChat login, you can also use FinClip's associated WeChat Mini-Program login feature to reduce development costs and quickly reuse WeChat login capabilities. Click here to learn more
In the WeChat Mini-Program environment, the Mini-Program login function typically uses OpenID or UnionID as a unique identifier to associate and integrate with the Mini-Program service's account system, completing the construction and design of the user account system.
For Mini-Programs migrating from the WeChat Mini-Program environment to FinClip, the following issues may arise:
- How to quickly reuse the login process? How to associate it with the Mini-Program service's account system?
- How to integrate user data from the WeChat Mini-Program with FinClip's data? How to associate the account systems of both parties?
When encountering the above issues, you can try to resolve them with the following solutions:
# 1. Login Solutions
# Solution 1: Server-side Modification + Mini-Program Modification
Applicable Scenario: The platform party builds its own ecosystem through FinClip, and the Mini-Programs running in the FinClip environment are all third-party Mini-Programs (i.e., the platform party cannot modify the Mini-Program code).

- Step 1: When initializing the SDK in the App, configure the userId and channel information on the Config.
- Step 2: The Mini-Program integrates the unified login plugin, obtaining the code, appId, apiServer, etc., from the login interface.
- Step 3: Call the request interface to send the code, appId, and apiServer to the developer's server.
- Step 4: The developer's server performs adaptation, uses the code and apiServer to resolve the
OpenIDandUnionIDfrom the corresponding Mini-Program Management Console open interface of the apiServer, and returns the content of its own account system.
# Solution 2: Server-side Modification (Trigger WeChat Authorization)
Applicable Scenario: The platform party uses FinClip to split its own functionalities, and all Mini-Programs are developed by the platform party itself (i.e., the platform party can modify the Mini-Program code).

- Step 1: Integrate the WeChat Open Platform SDK into the FinClip SDK.
- Step 2: Use a custom API to inject
wx.login. After triggering WeChat authorization, the code can be obtained. At this point, it may be necessary to append a unique identifier to the code. - Step 3: The Mini-Program requires no changes. Following the implementation in the WeChat environment, the code is sent to the developer's server.
- Step 4: The server, based on the code's unique identifier, calls the corresponding authorization interface to obtain the
OpenID, checks the login status, and returns the result.
Limitation: Due to WeChat restrictions, OpenIDs under different entities and different open platforms are inconsistent. In this case, the Mini-Program needs to be associated with the same entity or the same open platform (where the unique identifier is the UnionID).
# 2. Solution Implementation Code Examples
We provide corresponding implementation code for your reference.
# 2.1 Solution 1
First, the app integrates the SDK and configures the userId and channel when initializing the SDK.
iOS
FATConfig *config = [FATConfig configWithStoreConfigs:storeArrayM];
config.currentUserId = @"xxxxx";
config.channel = @"finclip";
config.phone = @"12345678901";
FATUIConfig *uiConfig = [[FATUIConfig alloc] init];
BOOL flag = [[FATClient sharedClient] initWithConfig:config uiConfig:uiConfig error:nil];
Android
val config = FinAppConfig.Builder()
.setFinStoreConfigs(finStoreConfigs)
.setUserId("xxxxxx")
.setChannel("finclip")
.setPhone("12345678901")
.build()
FinAppClient.init(application, config, object : FinCallback<Any?> {
override fun onSuccess(result: Any?) {
}
override fun onError(code: Int, error: String) {
Log.d(TAG, "init code:$code error:$error")
}
override fun onProgress(status: Int, error: String?) {
}
})
Then, add the unified login plugin to the app.json file in the Mini-Program.
"plugins":{
"loginPlugins": {
"version": "1.0.5",
"provider": "2275269218722181"
}
}
Note: The plugin version and provider may vary slightly depending on the server.
Next, call the login interface within the Mini-Program and pass the appId, code, and apiServer to the Mini-Program's backend page.
wx.login({
success: (res) => {
console.log('获取到的登录code为:', res)
//此处添加调用小程序业务服务获取用户信息逻辑
const appId = res.appId;
const code = res.code;
const apiServer = res.apiServer;
// 将appId、code、apiServer,传递给小程序业务后台。
// 小程序业务后台,需要调用小程序管理平台的开放接口
wx.request({
url: url,
data: {
appId: appId,
code: code,
apiServer: apiServer
},
success:(res) {
console.log("openId:", res.data.openId);
console.log("unionId:", res.data.unionId);
}
})
}
})
The server-side open interface description is as follows:
Endpoint
{apiserver}/api/v1/open/dev/mini-apps/unified-auth/login
Request Type
POST
Request Parameters
| Field | Type | Location | Description |
|---|---|---|---|
| Authorization | String | In the request header, format: Bearer {personalAccessToken} | personalAccessToken is generated in the Personal Center of the Developer Center. Ensure the 'Mini-Program Unified Authentication' scope is selected. |
| appId | String | In the request body | Mini-Program ID |
| code | String | In the request body | The code returned by the login interface |
Response Content
| Field | Type | Description |
|---|---|---|
| data | Map | Returned data, including channel, openId, unionId, accessToken |
| error | String | Error message |
| errcode | String | Error code |
Request Example:
POST {Mini-Program Server apiserver}/api/v1/open/dev/mini-apps/unified-auth/login
Body application/json
{
"appId":"fc2183741419665349", "code":"1drac2l7scWpTtetZtF4tA02llZegeLbJSxTYTUG6MmjBA2L3xewOk7IjSqY72ZNDsvWKU0r2EdLKcLqS82g0EKnDgE0uSu1REmvFpPIF8Y="
}
Response
{
"error": "",
"errcode": "OK",
"data": {
"channel": "com.finogeeks.finosprite",
"openId": "2279547539610117",
"unionId": "5110c76fbc1c8ebc7429e906b83c1f7f",
"accessToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImNlcnQtYnVpbHQtaW4iLCJ0eXAiOiJKV1QifQ.eyJvd25lciI6ImNvbS5maW5vZ2Vla3MuZmlub3Nwcml0ZSIsIm5hbWUiOiIyMjc5NTQ3NTM5NjEwMTE4IiwiY3JlYXRlZFRpbWUiOiIyMDI0LTA3LTE4IDEwOjE1OjQyIiwidXBkYXRlZFRpbWUiOiIyMDI0LTA3LTE4IDEwOjE1OjQyIiwiaWQiOiIyMjc5NTQ3NTM5NjEwMTE4IiwidHlwZSI6Im5vcm1hbC11c2VyIiwicGFzc3dvcmQiOiIiLCJwYXNzd29yZFNhbHQiOiIiLCJkaXNwbGF5TmFtZSI6IiIsImZpcnN0TmFtZSI6IiIsImxhc3ROYW1lIjoiIiwiYXZhdGFyIjoiIiwicGVybWFuZW50QXZhdGFyIjoiIiwiZW1haWwiOiIiLCJlbWFpbFZlcmlmaWVkIjpmYWxzZSwicGhvbmUiOiIiLCJsb2NhdGlvbiI6IiIsImFkZHJlc3MiOltdLCJhZmZpbGlhdGlvbiI6IiIsInRpdGxlIjoiIiwiaWRDYXJkVHlwZSI6IiIsImlkQ2FyZCI6IiIsImhvbWVwYWdlIjoiIiwiYmlvIjoiIiwicmVnaW9uIjoiIiwibGFuZ3VhZ2UiOiIiLCJnZW5kZXIiOiIiLCJiaXJ0aGRheSI6IiIsImVkdWNhdGlvbiI6IiIsIn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mweNhEqrjSj78jMz2_eeXMxfX1f2t-1asV4RahFVOZSSYLGcuFf44oK4GPMfzhOwwTIH4sqmNlsHIor8aT0DUFUU5HW3nMKDM3shl0zsnlgQT5-YdxhaYElLMjSOpY4pscwn6pdaGb9yYwkTommE_RxysmpXfA6TPuTg14_rNXQXxcJ1eDG4BjjHP9dp1Vk66AmUVnNbLZCheFioG1IsXIjaXnUUSxwyUCZRHL3GFrPbcwiyqmWwwgOLZfYetQTUO3MPJOY52eR0zS_-fWwGcHBf2SMZMb7Daz9w7u_fOL-FU1T57MvF97cEB3zx9o4GHIjd7K1gUX0UnvAvQsYUG2A6iJu9C2KziCDFH30q1rxCqrG35ZkwsKoYh1PHBu1ej-T1h9oRUFjzlO83N7LPR3KsQKCcgpkkchUje4pg2iD9-UDRoKsOuwn02qf1dlk0"
},
"traceid": "4fccb7b175cc401690235e4a400bb363"
}
# 2.2 Solution 2
# 2.1 APP Integrates WeChat Login
If you need to implement WeChat account authorization login in the APP, please refer to the WeChat Open Platform's Mobile App Development (opens new window) and the documentation WeChat Authorization Login Development Guide (opens new window). If not needed, proceed directly to step 2.
# 2.2 APP Implements Custom Injection Interface
First, the APP needs to refer to the iOS SDK Custom Injection Interface and Android SDK Custom Injection Interface documents to inject the account authorization login capability into the SDK, allowing the Mini-Program to call it. The detailed explanation is as follows.
Android Side: To allow the Mini-Program to access data outside the Mini-Program (i.e., from the host App), it is necessary to register custom Mini-Program interfaces. For specific instructions on custom Mini-Program interfaces, please refer to FinClip Mini-Program Open Platform - Custom Mini-Program Interfaces and FinClip Mini-Program Open Platform - Registering APIs in the Mini-Program Process.
- Customize the login interface
- Create a custom Api class, specifying the api name as "login";
public class LoginApi extends AbsApi {
private final static String API_NAME_LOGIN = "login"; // API name called by the Mini-Program Base Library
@Override
public String[] apis() {
return new String[]{API_NAME_LOGIN};
}
}
2. Register the custom Api;
This example shows a user authorization prompt Dialog, which requires an Activity object as the Dialog's context parameter, so the custom Api needs to be registered in the Mini-Program process.
if (FinAppClient.INSTANCE.isFinAppProcess(this)) {
// Mini-Program process
// The method of registering APIs in the Mini-Program process can obtain the Activity object where the Mini-Program is located, which can be used as the context parameter for creating the dialog)
FinAppProcessClient.INSTANCE.setCallback(new FinAppProcessClient.Callback() {
@Override
public List<IApi> getRegisterExtensionApis(@NotNull Activity activity) {
ArrayList<IApi> apis = new ArrayList<>();
apis.add(new LoginApi());
return apis;
}
@Nullable
@Override
public List<IApi> getRegisterExtensionWebApis(@NotNull Activity activity) {
return null;
}
});
return;
}
3. Implement the custom Api's invoke() method;
First, display the authorization prompt Dialog (developers should decide whether to show the authorization prompt Dialog based on requirements), then obtain the user login information from the main process (App process).
public class LoginApi extends AbsApi {
@Override
public void invoke(String event, JSONObject param, ICallback callback) {
if (event.equals(API_NAME_LOGIN)) {
showAuthDialog(callback);
}
}
/**
* Displays the authorization prompt dialog for obtaining user login information
*/
private void showAuthDialog(final ICallback callback) {
// Whether to display the authorization prompt dialog should be handled by the developer according to product requirements
new AlertDialog.Builder(activity)
.setTitle("是否同意授权获取用户登录信息?")
.setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
callback.onFail();
}
})
.setPositiveButton("同意", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
loginMainProcess(callback);
}
})
.show();
}
/**
* Obtains user login information from the main process
*/
private void loginMainProcess(final ICallback callback) {
// The Mini-Program process calls the main process, which obtains the user information and returns it to the Mini-Program process
FinAppProcessClient.INSTANCE.getAppletProcessApiManager()
.callInMainProcess(API_NAME_LOGIN, null, new FinCallback<String>() {
@Override
public void onSuccess(final String result) {
// The callback method needs to be called on the main thread
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
callback.onSuccess(new JSONObject(result));
} catch (JSONException e) {
e.printStackTrace();
callback.onFail();
}
}
});
}
@Override
public void onError(int code, String error) {
callback.onFail();
}
@Override
public void onProgress(int status, String info) {
}
});
}
}
Subsequently, in the main process (typically in the Application, but developers can choose another suitable location), return the user login information to the Mini-Program process.
// Set the handler for "Mini-Program process calls main process" in the main process
// Developers can also choose to set the handler in other suitable code locations in the main process
FinAppClient.INSTANCE.getAppletApiManager()
.setAppletProcessCallHandler(new IAppletApiManager.AppletProcessCallHandler() {
@Override
public void onAppletProcessCall(@NotNull String name,
@Nullable String params,
@Nullable FinCallback<String> callback) {
if (callback != null) {
if (name.equals(LoginApi.API_NAME_LOGIN)) {
// Obtain login information from the main process and return it to the Mini-Program process
// Here, dummy user login information is returned; developers should obtain the actual user login information from the APP
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("userId", "123");
} catch (JSONException e) {
e.printStackTrace();
}
callback.onSuccess(jsonObject.toString());
}
}
}
});
At this point, the entire process of Mini-Program login via the custom Api is complete.
Note: If the product requirements do not require displaying a user authorization prompt Dialog, it is recommended to register the custom Api in the main process (APP process), thereby omitting the process of the Mini-Program process calling the main process (APP process) method to obtain data.
iOS Side:
- Register a custom
loginapi in the native App
[[FATClient sharedClient]registerExtensionApi:@"login" handle:^(id param, FATExtensionApiCallback callback) {
NSDictionary *resDic = @{};
// Callback the user information result to the Mini-Program
if (resDic) {
callback(FATExtensionCodeSuccess,resDic);
}else{
callback(FATExtensionCodeFailure,resDic);
}
}];
- Call the declared getUserProfile in the Mini-Program to obtain user information
wx.login({
success: (res) => {
}
})
# 2.3 Obtaining User Information
There are two interfaces for obtaining user information in a Mini-Program: getUserInfo and getUserProfile, as well as the button component (with open-type set to getUserInfo).
- The app implements the corresponding delegate methods and returns user information within these methods.
iOS
On iOS, the following two delegate methods in FATAppletButtonOpenTypeDelegate need to be implemented:
- (BOOL)getUserInfoWithAppletInfo:(FATAppletInfo *)appletInfo bindGetUserInfo:(void (^)(NSDictionary *result))bindGetUserInfo;
- (BOOL)getUserProfileWithAppletInfo:(FATAppletInfo *)appletInfo bindGetUserProfile:(void (^)(NSDictionary *result))bindGetUserProfile;
Refer to the documentation for details: buttonopentypedelegate
Android
On Android, two handlers need to be implemented: IUserInfoHandler and IUserProfileHandler
Refer to the documentation for details: iuserinfohandler and iuserprofilehandler
- Call the user information retrieval interface in the Mini-Program
wx.getUserProfile({
success: (res) => {
console.log('getUserProfile success', res)
},
fail: (res) => {
console.log('getUserProfile fail', res.errMsg)
}
})
# 3. FAQ
According to the official WeChat announcement (opens new window), after December 27, 2021, user nickname and avatar information will no longer be provided to developers. You may need to handle the logic for obtaining user avatars and nicknames yourself.
Common handling logic is as follows:
- In the Mini-Program or Mini-Game, do not display the user's avatar and nickname; use other field content instead.
- After the user enters the Mini-Program or Mini-Game, randomly generate an avatar and nickname for the user.
- After the user enters the Mini-Program or Mini-Game, guide the user to configure their avatar, nickname, and other content information.