PHP code example of jacklin / aliyun-openapi-php-sdk

1. Go to this page and download the library: Download jacklin/aliyun-openapi-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jacklin / aliyun-openapi-php-sdk example snippets


use Tool\AliyunSdk;

$aliyun_sdk = new AliyunSdk('accessKeyId','accessKeySecret,'appKey');

$request_push = $aliyun_sdk->push('V20160801','PushRequest');


// 推送配置: iOS
$request_push->setiOSBadge("5"); // iOS应用图标右上角角标
$request_push->setiOSMusic("default"); // iOS通知声音
$request_push->setiOSApnsEnv("DEV");//iOS的通知是通过APNs中心来发送的,需要填写对应的环境信息。"DEV" : 表示开发环境 "PRODUCT" : 表示生产环境
$request_push->setiOSRemind("false"); // 推送时设备不在线(既与移动推送的服务端的长连接通道不通),则这条推送会做为通知,通过苹果的APNs通道送达一次(发送通知时,Summary为通知的内容,Message不起作用)。注意:离线消息转通知仅适用于生产环境
$request_push->setiOSRemindBody("iOSRemindBody");//iOS消息转通知时使用的iOS通知内容,仅当iOSApnsEnv=PRODUCT && iOSRemind为true时有效
$request_push->setiOSExtParameters("{\"k1\":\"ios\",\"k2\":\"v2\"}"); //自定义的kv结构,开发者扩展用 针对iOS设备
// 推送配置: Android
$request_push->setAndroidNotifyType("NONE");//通知的提醒方式 "VIBRATE" : 震动 "SOUND" : 声音 "BOTH" : 声音和震动 NONE : 静音
$request_push->setAndroidNotificationBarType(1);//通知栏自定义样式0-100
$request_push->setAndroidOpenType("URL");//点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
$request_push->setAndroidOpenUrl("http://www.aliyun.com");//Android收到推送后打开对应的url,仅当AndroidOpenType="URL"有效
$request_push->setAndroidActivity("com.alibaba.push2.demo.XiaoMiPushActivity");//设定通知打开的activity,仅当AndroidOpenType="Activity"有效
$request_push->setAndroidMusic("default");//Android通知音乐
$request_push->setAndroidXiaoMiActivity("com.ali.demo.MiActivity");//设置该参数后启动小米托管弹窗功能, 此处指定通知点击后跳转的Activity(托管弹窗的前提条件:1. 集成小米辅助通道;2. StoreOffline参数设为true
$request_push->setAndroidXiaoMiNotifyTitle("Mi Title");
$request_push->setAndroidXiaoMiNotifyBody("Mi Body");
$request_push->setAndroidExtParameters("{\"k1\":\"android\",\"k2\":\"v2\"}"); // 设定android类型设备通知的扩展属性
// 推送控制
$pushTime = gmdate('Y-m-d\TH:i:s\Z', strtotime('+3 second'));//延迟3秒发送
$request_push->setPushTime($pushTime);
$expireTime = gmdate('Y-m-d\TH:i:s\Z', strtotime('+1 day'));//设置失效时间为1天
$request_push->setExpireTime($expireTime);
$request_push->setStoreOffline("false"); // 离线消息是否保存,若保存, 在推送时候,用户即使不在线,下一次上线则会收到
$request_push->setBatchNumber("100010"); // 批次编号,用于活动效果统计. 设置成业务可以记录的字符串
$response = $client->getAcsResponse($request_push);
print_r("\r\n");
print_r($response);


use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')->asDefaultClient();

try {
    $result = AlibabaCloud::roa()
                          ->regionId('cn-hangzhou') // Specify the requested regionId, if not specified, use the client regionId, then default regionId
                          ->product('CS') // Specify product
                          ->version('2015-12-15') // Specify product version
                          ->action('DescribeClusterServices') // Specify product interface
                          ->serviceCode('cs') // Set ServiceCode for addressing, optional
                          ->endpointType('openAPI') // Set type, optional
                          ->method('GET') // Set request method
                          ->host('cs.aliyun.com') // Location Service will not be enabled if the host is specified. For example, service with a Certification type-Bearer Token should be specified
                          ->pathPattern('/clusters/[ClusterId]/services') // Specify path rule with ROA-style
                          ->withClusterId('123456') // Assign values to parameters in the path. Method: with + Parameter
                          ->request(); // Make a request and return to result object. The request is to be placed at the end of the setting
                          
    print_r($result->toArray());
    
} catch (ClientException $exception) {
    print_r($exception->getErrorMessage());
} catch (ServerException $exception) {
    print_r($exception->getErrorMessage());
}