PHP server-side SDK integration
IClientProfile is the interface for interacting with the Alibaba Cloud Captcha server-side API. All software development kit (SDK) operations are performed using IClientProfile.
Prerequisites
Your Alibaba Cloud account has an AccessKey.
You have downloaded the server-side SDK package for PHP from the Alibaba Cloud Captcha console.
The server-side development environment is PHP 5.3 or later.
Install the SDK
Extract the downloaded php_sdk.zip package to a folder on the server. Ensure that the folder has read permissions.
Add the header file to your PHP file, specify the correct file path, and import the alias. For example:
<?php include_once './aliyun-php-sdk-core/Config.php'; use afs\Request\V20180112 as Afs; //Do something below...
Notes
The Alibaba Cloud Captcha server-side SDK classes are located in the com.aliyuncs.IAcsClient package.
The default connection timeout for SDK API calls is 3 seconds, and the read timeout is 80 seconds. You can call the constructor with connectTimeout and readTimeout to customize these timeout periods.
Initialize IClientProfile
IClientProfile can be reused. We recommend that you set it as a globally unique object in your application.
<?php
include_once './aliyun-php-sdk-core/Config.php';
use afs\Request\V20180112 as Afs;
// Replace YOUR ACCESS_KEY and YOUR ACCESS_SECRET with your Alibaba Cloud AccessKey ID and AccessKey secret.
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "YOUR ACCESSKEY", "YOUR ACCESS_SECRET");
$client = new DefaultAcsClient($iClientProfile);
DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", "afs", "afs.aliyuncs.com");
Call the Alibaba Cloud Captcha server-side API
After you initialize IClientProfile, you can call the APIs of the Alibaba Cloud Captcha service. Then, you can develop handler classes for frontend page requests and methods to process the results as required.
For more information about the Alibaba Cloud Captcha service APIs, see Alibaba Cloud Captcha service APIs for web and HTML5 applications.
$request = new Afs\AuthenticateSigRequest();
$request->setSessionId("xxx");// The session ID. This parameter is required. Obtain it from the frontend. Do not change it.
$request->setToken("xxx");// The unique request token. This parameter is required. Obtain it from the frontend. Do not change it.
$request->setSig("xxx");// The signature string. This parameter is required. Obtain it from the frontend. Do not change it.
$request->setScene("xxx");// The scenario ID. This parameter is required. Obtain it from the frontend. Do not change it.
$request->setAppKey("xxx");// The application type ID. This parameter is required. Specify it on the backend.
$request->setRemoteIp("xxx");// The client IP address. This parameter is required. Specify it on the backend.
$response = $client->getAcsResponse($request);// A return code of 100 indicates that the signature verification is successful. A return code of 900 indicates that the signature verification failed.
print_r($response);