Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solution

3. Support Alipay+ promotion QR code

Scenario description

Scan promotion QR code is an offline scene. When a user finds a QR code offline, the user can scan promotion QR code with wallet app camera or the user can open camera inside A+Rewards.

System Flow

3. Support Alipay+ promotion QR code

Open Alipay+ promotion QR code

The promotion QR code is an encoded URL, and it can't be used to open a Mini Program or H5 page directly. You must decode it to a valid Mini Program URL or H5 URL beforehand. Griver had a URL decoder specified for this purpose. Please refer to the code below.

canDecodeUrl

This API is used to identify the Alipay+ promotion QR code.

Signature

copy
public static synchronized boolean canDecodeUrl(String url);

Request parameters

Name

Type

Description

url

String

Check if this URL can be decoded

Response parameters

Type

Length

Description

boolean

/

Return the decoding result

decodeUrlContent

If the canDecodeUrl() returns true, then call this API to decode the promotion code.

Signature

copy
public static synchronized void decodeUrlContent(final String url,
                                                     final GriverDecodeUrlCallback callback);

Request parameters

Name

Type

Description

Required

url

String

The URL to be decoded

M

callback

GriverDecodeUrlCallback

The callback to be invoked after the process ends. See GriverDecodeUrlCallback for details.

M

GriverDecodeUrlCallback

Item

Type

Description

Required

url

String

The decoding result that is required if the decode succeeds.

O

errorCode

Int

The error code that is required if the request fails.

O

errorMessage

String

The error message that is required if the request fails.

O

Response parameters

N/A

Sample

copy
// the scanning result of the QR Code
String scanResult = ...
    
// test whether the URL can be decoded
if (GriverDecodeUrl.canDecodeUrl(scanResult)) {
    GriverDecodeUrl.decodeUrlContent(scanResult, new GriverDecodeUrlCallback() {
        @Override
        public void onDecodeSuccess(String url) {
            // use the decoded URL to open a mini program
            Bundle bundle = new Bundle();
            Griver.openUrl(activity, url, bundle);
        }
        @Override
        public void onDecodeFailed(int errorCode, String errorMessage) {
            Log.d(TAG, "decodeUrlContent failed");
        }
    }
}