Independent Authorization for Viewer User System
Feature Description
When accessing the live streaming viewing page, specific parameters must be included in the URL. After the live streaming system verifies the request's legitimacy, the user is directed to the viewing page. The parameters passed by the user are set as the viewer's information on the viewing page. The viewer account returned by the API must be unique, meaning the same account cannot be logged in from two locations simultaneously. The account that logged in earlier will be logged out.
- Secretkey: Used to generate the signature for verification. (Management Console > Development Settings > Developer Information > appSecret)
Detailed Independent Authorization Process
Enable the viewer user system feature and obtain the appSecret from the Developer Information in the Management Console.
When requesting the Polyv live streaming viewing page, include the relevant parameters, e.g.,
https://live.polyv.cn/watch/1965681?externalViewerId=1b448be323&ts=1498547407000&sign=dd9dc9e42ad7c0204398e925a4ee0f46&nickname=viewerTestsThe live streaming system compares the value of the
signparameter submitted by the user to determine its validity. After a successful request, the link becomes invalid (the sign can only be used successfully once). If valid, the live streaming system usesnicknameandexternalViewerId. The viewer's nickname will be displayed in the chat area of the Polyv live streaming viewing page. If verification fails, an error page is displayed.Management Console > Users > User List > External User Information Management
<a href="/req.html?api=http://live.polyv.cn/watch/{channelId}"" target="_blank">Online API Call
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| externalViewerId | true | String | Viewer ID. If a duplicate ID exists, the earlier logged-in viewer will be kicked out of the live room. [Only supports English letters, numbers, and underscores. Maximum length is 64 characters. Characters exceeding 64 will be truncated and not recorded.] |
| ts | true | Long | Current 13-digit millisecond timestamp, valid for 3 minutes. |
| sign | true | String | Signature for verification. Generation rule: MD5 encryption of secretkey + externalViewerId + secretkey + ts. |
| nickname | true | String | Viewer nickname, requires URL-safe base64 encoding. |
| avatar | false | String | URL of the viewer's avatar. |
| param4 | false | String | Custom parameter for tracking viewer watch logs. Must be base64 encoded first, then URL-encoded. |
| param5 | false | String | Custom parameter for tracking viewer watch logs. Must be base64 encoded first, then URL-encoded. |
| forceUserAuth | false | String | Y/N. Y: Re-authenticate independently and update viewer information. Default: N. |
Code Example (Java)
//TODO 设置为独立授权的SecretKey
private static final String DIRECT_SECRET_KEY = "******";
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
String url = "https://live.polyv.cn/watch/";
//TODO 设置为独立授权的频道号
String channelId = "2292421";
//TODO 设置观众id,同一个观众id,后面进入的会把前面的观众挤出频道
String externalViewerId = "sadboy";
String ts = String.valueOf(System.currentTimeMillis());
//url安全的base64编码
String nickname = "保利威";
nickname = new String(org.apache.commons.codec.binary.Base64.encodeBase64URLSafe(nickname.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
String avatar = "http://live.polyv.net/assets/images/avatars/9avatar.jpg";
String sign = DIRECT_SECRET_KEY+externalViewerId+DIRECT_SECRET_KEY+ts;
sign = LiveSignUtil.md5Hex(sign);
url += channelId+"?externalViewerId="+externalViewerId+"&ts="+ts+"&sign="+sign+"&nickname="+nickname+"&avatar="+avatar;
//浏览器直接访问url即可进入直播间
System.out.println(url);
}
Code Example (PHP)
<?php
$secretkey = "qwertyui"; //后台secretKey
$externalViewerId = "test" . rand(0, 5); //直播的用户ID
$ts = time() * 1000; //当前时间
$sign = md5($secretkey . $externalViewerId . $secretkey . $ts); //用于校验的sign
$nickname = urlencode(base64_encode("保利威")); //学员的昵称
$avatar = "http://live.polyv.net/assets/images/avatars/9avatar.jpg"; //学员的头像
$url = "https://live.polyv.cn/watch/108008";
$callbackUrl = $url . "?externalViewerId=" . $externalViewerId . "&nickname=" . $nickname . "&avatar=" . $avatar . "&ts=" . $ts . "&sign=" . $sign;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>login</title>
</head>
<body>
<div id="btn">
<input type="button" onclick="openurl()" value="独立授权观看" class="btn" >
</div>
<script>
function openurl(){
location.href="<?php
echo $callbackUrl ?>";
};
</script>
</form>
</body>
</html>
Notes
- Ensure the uniqueness of the submitted
userid. When multiple viewers use the sameuseridto enter the viewing page, the earlier logged-in viewer will be kicked out by the later one. The viewing page will display the message: "Account logged in from another location. You will be logged out." As shown below:

