更新时间:2025-08-11 GMT+08:00
公共依赖
使用样例时需要引用以下依赖文件:
data.php
<?php /* please replace the appId and secret, when you use the demo. */ // base_url、appid、secret购买服务时下发,请替换为实际值 $click2call_appid = '*****'; $click2call_secret = '*****'; $callnotify_appid = '*****'; $callnotify_secret = '*****'; $callverify_appid = '*****'; $callverify_secret = '*****'; $t_transmit_appid = '*****'; $t_transmit_secret = '*****'; /* please replace the IP and Port, when you use the demo. */ $base_url = 'https://{domain}:{port}'; //*************************** The following constants do not need to be modified *********************************// function getBaseUrl() { global $base_url; return $base_url; } function getClick2Call_AppId() { global $click2call_appid; return $click2call_appid; } function getClick2Call_Secret() { global $click2call_secret; return $click2call_secret; } function getCallNotify_AppId() { global $callnotify_appid; return $callnotify_appid; } function getCallNotify_Secret() { global $callnotify_secret; return $callnotify_secret; } function getCallverify_AppId() { global $callverify_appid; return $callverify_appid; } function getCallverify_Secret() { global $callverify_secret; return $callverify_secret; } function getTTransmit_AppId() { global $t_transmit_appid; return $t_transmit_appid; } function getTTransmit_Secret() { global $t_transmit_secret; return $t_transmit_secret; } ?>
util.php
<?php /** * buildAKSKHeader * @param string $appKey * @param string $appSecret * @return string */ function buildAKSKHeader($appKey, $appSecret) { date_default_timezone_set("UTC"); $Created = date('Y-m-d\TH:i:s\Z'); //Created $nonce = uniqid(); //Nonce $base64 = base64_encode(hash_hmac('sha256', ($nonce . $Created), $appSecret, TRUE)); //PasswordDigest return sprintf("UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\"", $appKey, $base64, $nonce, $Created); } /** * createOptions * @param string $method * @param string $xaksk * @return string[][][] */ function createOptions($method, $xaksk, $content) { // 请求Headers $headers = [ 'Content-Type: application/json;charset=UTF-8', 'Authorization: AKSK realm="SDP",profile="UsernameToken",type="Appkey"', 'X-AKSK: ' . $xaksk ]; $context_options = [ 'http' => [ 'method' => $method, // 请求方法为GET 'header' => $headers, 'content' => $content, 'max_redirects' => '0', // 关闭重定向 'ignore_errors' => true // 获取错误码,方便调测 ], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false ] ]; return $context_options; } ?>
父主题: PHP