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](https://ac.alipay.com/storage/2020/5/11/793a3d8d-5270-405b-9362-e6a670b9c842.png)
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
+ (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
+ (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
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 ?? "")
}
}
}