Skip to content

Mini-App Backend Development

Interface Description

The common server-side interfaces are encapsulated in the MiniAppCommonService service class from the public module. You can obtain an instance by injecting this service class. Usage example:

java
@Resource
private MiniAppCommonService miniAppCommonService;

@Resource
private MiniAppPayService miniAppPayService;
    
ApplicationVo application = miniAppCommonService.getApplication();
// ...

Before using the server-side interfaces, you must correctly configure the Mini-App's appKey and appSecret. These are mainly used for signing request parameters when the Mini-App backend initiates requests to the Mos server. Developers do not need to concern themselves with the specific signing method — the public service has already encapsulated it. After injecting the corresponding service, you can directly call the specific methods.

Interface BaseURL

Interface Signature

If calling directly via HTTP, the request Body must include the following fields:

  • appKey: Mini-App App Key
  • sign: Signature

Signature generation rule: Sort all parameters (including appKey) in ascending order, convert them to QueryString format (e.g., key1=value1&key2=value2...), then append secret=appSecret at the end, and finally perform MD5 on the resulting string. Java example code:

java
import org.springframework.util.DigestUtils;

/**
 * Get signature
 *
 * @param request Request object (Object used here as example; replace with actual request type or base class)
 * @return Signature
 */
public String getSign(Object request) {
    // Convert request to a key-ordered TreeMap (ascending by default), "appKey" must be included
    Map<String, String> requestSortedMap = JSON.parseObject(JSON.toJSONString(request), new TypeReference<TreeMap<String, String>>() {
    });
    requestSortedMap.put("appKey", "<your_app_key>");

    // Convert request to QueryString format, e.g., key1=value1&key2=value2...
    StringBuilder qsBuilder = new StringBuilder();
    for (Map.Entry<String, String> entry : requestSortedMap.entrySet()) {
        // "sign" or empty values do not participate in signing
        if ("sign".equals(entry.getKey()) || entry.getValue() == null || entry.getValue().isEmpty()) {
            continue;
        }
        qsBuilder.append(entry.getKey()).append("=").append(entry.getValue().trim()).append("&");
    }
    // Append "secret=your_app_secret" at the end
    qsBuilder.append("secret=").append("<your_app_secret>");

    // MD5 processing
    return DigestUtils.md5DigestAsHex(qsBuilder.toString().getBytes(StandardCharsets.UTF_8));
}

Login & Authentication

Get Application Information

API: MiniAppCommonService.getApplication()

HTTP: POST /open-apis/application/v1/getApplication

Get Mini-App application information

Parameters

None (signature still required)

Response

FieldTypeDescription
appNameStringApplication name
appKeyStringApplication key
appSecretStringApplication secret
descriptionStringApplication description
statusBooleanApplication status
notifyUrlStringCallback URL

Universal Login

API: MiniAppCommonService.miniAppLogin(String code)

A universal login interface provided by the public module. It uses the code obtained from the Mini-App frontend and JWT to generate an identity token. After creating a new Mini-App module, a default login interceptor com.testproject.mos.miniapp.xxx.interceptor.LoginInterceptor is included. This interceptor validates the token passed from the Mini-App frontend in the format of Bearer token via HTTP Header:

Authorization: Bearer <token>

After authentication passes, users can retrieve the logged-in user's openid and language type via the "Get Current User Information" interface, which can then be used to fetch the user's information within the Mini-App itself (the Mini-App must maintain its own user table with a column storing openid).

If the universal login does not meet your needs, you may override the login interceptor and implement your own login and current user information retrieval interfaces.

Note: Do not modify the code in the public module.

Parameters

FieldTypeRequiredDescription
codeStringYesCode obtained via mos.login in Mini-App

Response TokenVo

FieldTypeDescription
tokenStringIdentity token

Get Current User Information

API: MiniAppCommonService.getMiniAppUser()

A universal method provided by the public module to get the current logged-in user. It works only when used with the universal login interface and the default login interceptor.

Parameters

None (signature still required)

Response MiniAppUserBo

FieldTypeDescription
appKeyStringApplication key
openidStringUser unique identifier
languageTypeLanguageEnumLanguage type

Exchange Code for Mos Session

API: MiniAppCommonService.code2session(String code)

HTTP: POST /open-apis/mp/v1/auth/code2session

Get Mos session information using code

Parameters

FieldTypeRequiredDescription
codeStringYesCode obtained via mos.login in Mini-App

Response MosSessionVo

FieldTypeDescription
openidStringUser unique identifier
sessionKeyStringSession key (currently unused)

QR Code Login

Generate QR Code

HTTP: POST /open-apis/mp/v1/auth/getLoginQrCodeUrl

Generate a QR code for Mini-App scan-to-login. Expires in 120 seconds. The Mini-App uses this string to generate the QR code image.

Request Body

None (signature still required)

Response Body

FieldTypeDescription
qrCodeStringQR code string, format: https://mos.me/miniapp-open/login/{uuid}
uuidStringQR code UUID string

Check QR Code Status

HTTP: POST /open-apis/mp/v1/auth/getLoginQrCodeStatus

Check the status of the QR code. Returns user information upon successful scan.

Request Body

FieldTypeRequiredDescription
qrCodeUuidStringYesQR code UUID string

Response Body

FieldTypeDescription
statusString'NO_SCAN': Not scanned | 'SCAN': Scanned
mosOpenUserVoMosOpenUserVoUser info (available only after successful scan)

Response MosOpenUserVo

FieldTypeDescription
openIdStringUser unique identifier
firstNameStringFirst name
lastNameStringLast name
headPortraitStringAvatar URL

Payment

Before developing payment features, you must apply to become a Mos merchant and obtain the corresponding merchant ID (mcId), which is required in the payment flow.

Create Prepayment Order

API: MiniAppPayService.prepay(CreatePrepayOrderAo ao)

HTTP: POST /open-apis/mp/v1/pay/prepay

Create a prepayment order

Parameters CreatePrepayOrderAo

FieldTypeRequiredDescription
mcIdStringYesMerchant ID
nonceStrStringNoRandom string, must be unique in the system
descStringNoOrder description
outTradeNoStringYesMerchant Mini-App system order number
currencyStringYesCurrency: USD - US Dollar | KHR - Cambodian Riel
totalAmountStringYesOrder amount
notifyUrlStringYesCallback URL
openidStringYesUser unique identifier
expireTimeStringNoOrder expiration timestamp (milliseconds)

Response PrepayOrderVo

FieldTypeDescription
prepayIdStringPrepayment order ID

Merchant Pays User

API: MiniAppPayService.payToMiniAppUser(PayToMiniAppUserAo ao)

HTTP: POST /open-apis/mp/v1/pay/payToMiniAppUser

Call this interface to pay a user

Parameters PayToMiniAppUserAo

FieldTypeRequiredDescription
nonceStrStringNoRandom string, must be unique in the system
outTradeNoStringYesMerchant Mini-App system order number
currencyStringYesCurrency: USD - US Dollar | KHR - Cambodian Riel
amountStringYesPayment amount
openidStringYesUser unique identifier

Response PayToMiniAppUserVo

FieldTypeDescription
prepayIdStringPrepayment order ID
nonceStrStringRandom string
outTradeNoStringMerchant Mini-App system order number
paymentNoStringMos order number

Query Order

API: MiniAppPayService.orderQuery(OrderQueryAo ao)

HTTP: POST /open-apis/mp/v1/pay/orderQuery

Query order status

Parameters OrderQueryAo

FieldTypeRequiredDescription
nonceStrStringYesRandom string, must be unique in the system
outTradeNoStringYesMerchant Mini-App system order number

Response OrderQueryVo

FieldTypeDescription
openidStringUser unique identifier
prepayIdStringPrepayment order ID
outTradeNoStringMerchant Mini-App order number
countryStringCountry code
currencyStringCurrency
totalAmountStringOrder amount
descStringProduct description
statusStringOrder status
expireTimeLongExpiration time
createTimeLongCreation time

Customer Service Account

Create Customer Service Account

HTTP: POST /open-apis/mp/v1/customerServ/create

Create a customer service account

Request Body

FieldTypeRequiredDescription
openidStringYesUser unique identifier
nameStringYesCustomer service name

Response Body

FieldTypeDescription
tokenStringUnique identifier of the customer service account (used in subsequent requests)

Send Message via Customer Service Account

HTTP: POST /open-apis/mp/v1/customerServ/{token}/sendMessage

Send a message to a specified user via the customer service bot

Path Parameter

FieldTypeRequiredDescription
tokenStringYesCustomer service account identifier

Request Body

FieldTypeRequiredDescription
openidStringYesRecipient user unique identifier
contentContentAoYesMessage content, see ContentAo

ContentAo

FieldTypeRequiredDescription
textStringYesMessage text

Response Body

None