tencent cloud

Feedback

Open APIs

Last updated: 2024-08-06 15:23:50
The mini program SDK provides some open APIs for implementing capabilities such as login, obtaining user information, and payment, which are provided by host apps. See the following table for the supported open APIs:
Mini program
MiniOpenApiProxy
Description
wx.login
login
Login API
wx.getUserInfo
getUserInfo
Obtain basic user information
wx.getUserProfile
getUserProfile
Obtain user attribute information
wx.getPhoneNumber
getPhoneNumber
Obtain phone number
wx.requestPayment
requestPayment
Initiate a payment
wx.checkSession
checkSession
Check if the login has expired
You can associate data interactions between the mini program and the host application by implementing the OpenApiHandler abstract class
abstract class OpenApiHandler {
  // The API is called when the mini program calls wx.requestPayment to request a third-party payment
   
  Future<Map<String, dynamic>> requestPayment(
      AppInfo appInfo, Map<Object?, Object?> params);
 
  /// The API is called when the mini program calls wx.getUserProfile to request the user information of the host app
  ///
  Future<Map<String, dynamic>> getUserProfile(
      AppInfo appInfo, Map<Object?, Object?> params);
 
  /// The API is called when the mini program calls wx.login to request the login certificate of the host app
  ///
  Future<Map<String, dynamic>> login(
      AppInfo appInfo, Map<Object?, Object?> params);
 
  /// The API is called when the mini program calls wx.checkSession to request the login status of the host app
  /// Check if the login has expired
  ///
  Future<Map<String, dynamic>> checkSession(
      AppInfo appInfo, Map<Object?, Object?> params);
 
  /// The API is called when the mini program calls wx.getUserProfile
  /// Compatible with earlier mini program APIs
  ///
  Future<Map<String, dynamic>> getUserInfo(
      AppInfo appInfo, Map<Object?, Object?> params);
 
  /// The API is called when the mini program calls wx.getPhoneNumber to request the current user's phone number
  ///
  Future<Map<String, dynamic>> getPhoneNumber(
      AppInfo appInfo, Map<Object?, Object?> params);
}
Sample code for obtaining user information instance:
@override
Future<Map<String, dynamic>> getUserProfile(
AppInfo appInfo, Map<Object?, Object?> params) async {
print("getUserProfile:$appInfo params:$params");
Map<String, dynamic> result = {
"userInfo": {
"nickName": "xcode",
"avatarUrl":
"https://staticintl.cloudcachetci.com/cms/backend-cms/8WGP653_%E5%BC%80%E5%8F%91%E8%80%85%E5%B7%A5%E5%85%B7%E9%80%9A%E7%94%A8.png",
"gender": 1,
"country": "China",
"province": "ChongQing",
"city": "ChongQing",
}
};
return Future.value(result);
}

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support