分类列表
{{item.id}}:{{item.category_name}}
config, XMLY, XMplayer 喜马拉雅sdk封装好的
config({
app_key: '2e*****1', // 必传,官方提供的 app_key:b617866c20482d133d5de66fceb37da3 仅供测试,有调用次数限制。
//get_access_token: getAccessToken, // 标准登录授权,必须传 get_access_token 参数,值为 js 函数,和 sig_url 互斥
device_id: XMLY.getDeviceId(),
sig_url: 'http******/xmly/jssdk.php', // 免登录授权,必须传 sig_url,和 get_access_token 互斥
timeout: 10 * 1000,
debug: true,
})
that.xmly = new XMLY()
// 获取访问令牌 access_token,函数的返回值为字符串(即:access_token 的值)
function getAccessToken() {
// 书写授权逻辑
// 确保返回有效的 access_token 值
return 'b7a259c1864cc659ddfdd07910dc75a8' // return 返回有效的 access_token 值
}
1,
'message' => "success",
'signature' => $sig
);
echo json_encode($d);
/**
* sig 生成
*/
function createSig($data)
{
ksort($data);
$parme = "";
foreach ($data as $k => $v) {
$parme .= "$k=$v&";
}
$parme = trim($parme, '&');
$str = base64_encode($parme);
$hashKey = CLIENT_SECRET;
$sigStr = md5(hash_hmac('sha1', $str, $hashKey, true));
return $sigStr;
}
CLIENT_ID,
'client_secret' => CLIENT_SECRET,
'device_id' => $device_id,
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => 'http://w***y/oauth.php'
);
$xmly_url = 'https://api.ximalaya.com/oauth2/v2/access_token';
$res = curl($xmly_url, $data);
var_dump($res);
/**
* curl 方法
* @param String $url
* @param Array $data
* @return $tmpInfo
*/
function curl($url, $data = null)
{
$ch = curl_init();
$header = array("Content-Type:application/x-www-form-urlencoded");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $tmpInfo;
}
/**
* createUrl 生成请求连接
* @param String $url
* @param Array $data
* @return $tmpInfo
*/
function createUrl($o_url, $data)
{
$url = "https://api.ximalaya.com{$o_url}?";
$rand_only = time() . rand(1, 9999);
$data['app_key'] = CLIENT_ID;
$data['client_os_type'] = 4; //客户端系统类型,固定值
$data['nonce'] = (string) $rand_only; //设备唯一码
$data['timestamp'] = getMillisecond(); //毫秒级别时间戳
$data['server_api_version'] = '1.0.0'; //服务器端API版本号
//生成sign
ksort($data);
$parme = "";
foreach ($data as $k => $v) {
$parme .= "$k=$v&";
}
$parme = trim($parme, '&');
$str = base64_encode($parme);
$hashKey = CLIENT_SECRET . CLIENT_STATIC_KEY;
$sigStr = "&sig=" . md5(hash_hmac('sha1', $str, $hashKey, true));
$url .= $parme . $sigStr;
return $url; //生成的url的timestamp 标签被html页面转译了 如果是用浏览器测试 记得修改一下这个标签
}
/**
* 时间戳 - 精确到毫秒
* @return float
*/
function getMillisecond()
{
list($t1, $t2) = explode(' ', microtime());
return (float) sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
}
喜马拉雅JSSDK接入
分类列表
{{item.id}}:{{item.category_name}}