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.

canDecodeURLContent

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

Signature

copy
+ (BOOL)canDecodeURLContent:(NSString *)urlContent;

Request parameters

Item

Type

Description

urlContent

String

Check if this URL can be decoded

Response parameters

Type

Length

Description

BOOL

/

Return the identification result

decodeURLContent

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

Signature

copy
+ (void)decodeURLContent:(NSString *)urlContent completion:(void(^)(GRVURLContentDecodeResponse *response))completion;

Request parameters

Item

Type

Description

Required

url

String

The URL to be decoded

M

completion

iOS Block

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

M

completion

Item

Type

Description

Required

response

GRVURLContentDecodeResponse

The decoding result that is required if the request succeeds.

O

GRVURLContentDecodeResponse

Item

Type

Description

Required

decodedURL

NSString

The decoding result that is required if the decode succeeds.

O

success

BOOL

Indicate that the decode succeeds

O

errorCode

NSInteger

The error code that is required if the request fails.

O

errorMessage

NSString

The error message that is required if the request fails.

O

Response parameters

N/A

Sample

copy
import ACGriverCore

// the scanning result of the QR Code
let scanResult: String = ... 

// test whether the URL can be decoded
if (GRVURLContentDecoder.canDecodeURLContent(scanResult)) {
    GRVURLContentDecoder.decodeURLContent(scanResult) { (response) in
        // use the decoded URL to open a mini program
        if response.success, let decodedURL = response.decodedURL {
            GRVAppContainerLaunch.sharedInstance().openApp(withUrl: decodedURL, extraParams: [:])
        } else {
            print(response.errorMessage ?? "")
        }
    }
}

Next Steps

Start to use Griver AppContainer