中国电信IPTV2.0平台

来自IPTV爱好者
跳转至: 导航搜索

IPTV2.0平台文档

2.0平台鉴权流程

1、获取EncryToken
C->S: GET http://58.223.251.139:8298/auth?UserID=0512xxxxxxxx&Action=Login
S->C: Authentication.CTCGetAuthInfo('cjvbWsMxpv9zWJLpi4Ig7Kkg1lfK36EJ')
2、获取UserToken
C->S: POST http://58.223.251.139:8298/uploadAuthInfo   
      UserID=0512xxxxxxxx&Authenticator=xxxxxx..xxxx&AccessMethod=dhcp&AccessUserName=0512xxxxxxxx@itv
S->C: Authentication.CTCSetConfig ('UserToken','05178355509172127866530321112947');
      Authentication.CTCSetConfig ('EPGDomain','http://58.223.251.175:8080/iptvepg/function/index.jsp');
3、登录EPG主服务器
C->S: GET http://58.223.251.175:8080/iptvepg/function/index.jsp?UserToken=05178355509172127866530321112947&UserID=0512xxxxxxxx&UserIP=192.168.1.1
S->C: top.document.location = 'http://58.223.132.211:8080/iptvepg/function/index.jsp?haslogin=1&stb_id=&UserIP=114.218.32.454&UserID=0512xxxxxxxx&UserToken=05178355509172127866530321112947&STBID=&LastTermno=612&emg=0';
4、登录负载均衡EPG服务器
C->S: GET http://58.223.132.211:8080/iptvepg/function/index.jsp?haslogin=1&stb_id=&UserIP=114.218.32.454&UserID=0512xxxxxxxx&UserToken=05178355509172127866530321112947&STBID=&LastTermno=612&emg=
S->C:

鉴权示例代码:

import java.net.URL;
import java.net.HttpURLConnection;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.DataOutputStream;
import java.util.Random;
import java.util.Calendar;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;

public class IPTVTest {
	public static void main(String[] args) {
		String AuthServer = "http://58.223.251.139:8298/auth";		// 认证服务器
		String StbId = "381001000000004000001A2B3C4D5E6F";		// 机顶盒序列号
		String MacAddr = "1A:2B:3C:4D:5E:6F";				// 机顶盒网卡MAC地址
		String IpAddr = "192.168.1.12";					// 机顶盒IP地址
		String UserId = "softtysz0000004";				// 业务帐号
		String Password = "******";					// 帐号密码

		try {
			URL AuthUrl;
			HttpURLConnection Conn;
			String Url;
			String Line;
			String Response;
			String AuthInfo;
			String Request;
			int Begin, End;

			AuthUrl = new URL(AuthServer+"?UserID="+UserId+"&Action=Login");

			Conn = (HttpURLConnection)AuthUrl.openConnection();

			if (Conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
				BufferedReader in = new BufferedReader(new InputStreamReader(Conn.getInputStream()));

				Response = "";
				while ((Line = in.readLine()) != null) {
					Response += Line;
				}
				Conn.disconnect();
			} else {
				Conn.disconnect();
				System.out.println("URL: "+AuthUrl.toString()+" Code: "+Conn.getResponseCode());
				return;
			}
			Begin = Response.indexOf("Authentication.CTCGetAuthInfo");
			if (Begin < 0 || (Begin = Response.indexOf("'", Begin)) < 0 || (End = Response.indexOf("'", Begin+1)) < 0) {
				System.out.println("Authentication.CTCGetAuthInfo not found.");
				return;
			}
			AuthInfo = Response.substring(Begin+1, End);
			System.out.println("AuthInfo: "+AuthInfo);

			Request = "UserID="+UserId;
			Request += "&Authenticator="+Authenticator(AuthInfo, StbId, MacAddr, IpAddr, UserId, Password);
			Request += "&AccessMethod=lan";
			Request += "&AccessUserName="+UserId+"@itv";

			AuthUrl = new URL(AuthServer.substring(0, AuthServer.lastIndexOf('/'))+"/uploadAuthInfo");
			Conn = (HttpURLConnection)AuthUrl.openConnection();
			Conn.setRequestMethod("POST");
			Conn.setDoOutput(true);
			Conn.setDoInput(true);
			Conn.setUseCaches(false);
			Conn.setAllowUserInteraction(false);
			Conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			Conn.setRequestProperty("Content-Length", "" + Request.length());
			DataOutputStream OutStream = new DataOutputStream(Conn.getOutputStream());
			OutStream.writeBytes(Request);
			OutStream.close();
			if (Conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
				BufferedReader in = new BufferedReader(new InputStreamReader(Conn.getInputStream()));

				Response = "";
				while ((Line = in.readLine()) != null) {
					Response += Line;
				}
				Conn.disconnect();
			} else {
				Conn.disconnect();
				System.out.println("URL: "+AuthUrl.toString()+" Code: "+Conn.getResponseCode());
				return;
			}

			String UserToken = CTCSetConfig(Response, "UserToken");
			String EPGDomain = CTCSetConfig(Response, "EPGDomain");
			System.out.println("UserToken: "+UserToken);
			System.out.println("EPGDomain: "+EPGDomain);

			AuthUrl = new URL(EPGDomain+"?UserToken="+UserToken+"&UserID="+UserId+"&UserIP="+IpAddr);
			Conn = (HttpURLConnection)AuthUrl.openConnection();

			if (Conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
				BufferedReader in = new BufferedReader(new InputStreamReader(Conn.getInputStream()));

				Response = "";
				while ((Line = in.readLine()) != null) {
					Response += Line;
				}
				Conn.disconnect();
			} else {
				Conn.disconnect();
				System.out.println("URL: "+AuthUrl.toString()+" Code: "+Conn.getResponseCode());
				return;
			}
//			System.out.println(Response);

			Begin = Response.indexOf("top.document.location");
			if (Begin < 0 || (Begin = Response.indexOf("'", Begin)) < 0 || (End = Response.indexOf("'", Begin+1)) < 0) {
				System.out.println("top.document.location not found.");
				return;
			}
			Url = Response.substring(Begin+1, End);
			System.out.println("EPG URL: "+Url);

		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
	}

	static String CTCSetConfig(String Response, String Name)
	{
		int Begin, End;
		String Key = "Authentication.CTCSetConfig ('"+Name+"','";

		Begin = Response.indexOf(Key);
		if (Begin > 0)
		{
			Begin += Key.length();
			End = Response.indexOf("'", Begin);
			if (End > 0)
				return Response.substring(Begin, End);
		}

		return "";
	}

	static public String Authenticator(String AuthInfo, String StbId, String MacAddr, String IpAddr, String UserId, String Password) {
		String AuthStr = "";
		String Result = "";
		Random Rand = new Random(Calendar.getInstance().getTimeInMillis());

		AuthStr += String.format("%08d", Rand.nextInt(100000000))+"$";
		AuthStr += AuthInfo+"$";
		AuthStr += UserId+"$";
		AuthStr += StbId+"$";
		AuthStr += IpAddr+"$";
		AuthStr += MacAddr+"$";
		AuthStr += "990070|$CTC";

//		System.out.println(AuthStr);

		try {
			byte Auth[] = AuthStr.getBytes("ASCII");
			int Len = Auth.length;
			int Mod = Len % 8;

			if (Mod != 0)Len += 8-Mod;
			byte AuthBytes[] = new byte[Len];

			for (int i=0; i<Len; i++) {
				if (i >= Auth.length)
					AuthBytes[i] = (byte)(8-Mod);
				else
					AuthBytes[i] = Auth[i];
			}

			String Algorithm = "DESede";
			byte KeyBytes[] = new byte[24];
			byte PassBytes[] = Password.getBytes();

			for (int i=0; i<24; i++) {
				if (i < PassBytes.length)
					KeyBytes[i] = PassBytes[i];
				else
					KeyBytes[i] = 0x30;
			}

	 	        Security.addProvider(new com.sun.crypto.provider.SunJCE());
			SecretKey DesKey = new SecretKeySpec(KeyBytes, Algorithm);

			Cipher C = Cipher.getInstance(Algorithm);
			C.init(Cipher.ENCRYPT_MODE, DesKey);
			byte Encrypt[] = C.doFinal(AuthBytes);

			for (int i=0; i<Len; i++) {
				Result += String.format("%02X", Encrypt[i]<0?(256+Encrypt[i]):Encrypt[i]);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return Result;
	}
}

EPG服务器

C->S:

GET /iptvepg/function/index.jsp?UserGroupNMB=20000022&EPGGroupNMB=%20&UserToken=05143528095796312344240412212014&UserID=0512********&STBID=381001000000004000001A2B3C4D5E6F HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ztebw V1.0)
Host: 58.223.251.175:8080
Accept: */*
Accept-Encoding: identity
Referer: http://58.223.251.139:8298/getServiceList
Accept-Language: zh-cn

S->C:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=F6293F7D4812343329B63D6D09607640; Path=/iptvepg
Content-Type: text/html;charset=GBK
Content-Length: 606
Date: Tue, 12 Apr 2011 13:20:14 GMT
Connection: close

<!-- get balanced epg -->

       <html>
       <head>
       <script language="javascript" type="">
       function gotoBalancedEPG()
       {
           top.document.location = 'http://58.223.132.211:8080/iptvepg/function/index.jsp?haslogin=1&stb_id=381001000000004000001A2B3C4D5E6F&UserIP=121.239.89.123&UserID=0512********&UserToken=05143528095796312344240412212014&STBID=381001000000004000001A2B3C4D5E6F&LastTermno=612&emg=0';
       }
       </script>
       </head>
       <body bgcolor="#000000" onload="gotoBalancedEPG()">
       </body>
       </html>

C->S:

GET /iptvepg/function/index.jsp?haslogin=1&stb_id=381001000000004000001A2B3C4D5E6F&UserIP=121.239.89.123&UserID=0512********&UserToken=05143528095796312344240412212014&STBID=381001000000004000001A2B3C4D5E6F&LastTermno=612&emg=0 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ztebw V1.0)
Host: 58.223.132.211:8080
Accept: */*
Accept-Encoding: identity
Referer: http://58.223.251.175:8080/iptvepg/function/index.jsp?UserGroupNMB=20000022&EPGGroupNMB=%20&UserToken=05143528095796312344240412212014&UserID=0512********&STBID=381001000000004000001A2B3C4D5E6F
Accept-Language: zh-cn

S->C:

HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=5D8488A123486165D886D30332AF32F7; Path=/iptvepg
Location: http://58.223.132.211:8080/iptvepg/function/funcportalauth.jsp?LastTermno=612
Content-Type: text/html;charset=GBK
Content-Length: 0
Date: Tue, 12 Apr 2011 13:20:15 GMT

C->S:

GET /iptvepg/function/funcportalauth.jsp?LastTermno=612 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ztebw V1.0)
Host: 58.223.132.211:8080
Accept: */*
Accept-Encoding: identity
Referer: http://58.223.251.175:8080/iptvepg/function/index.jsp?UserGroupNMB=20000022&EPGGroupNMB=%20&UserToken=05143528095796312344240412212014&UserID=0512********&STBID=381001000000004000001A2B3C4D5E6F
Cookie: JSESSIONID=5D8488A123486165D886D30332AF32F7
Accept-Language: zh-cn

S->C:

HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Location: http://58.223.132.211:8080/iptvepg/function/frame.jsp
Content-Type: text/html;charset=GBK
Content-Length: 0
Date: Tue, 12 Apr 2011 13:20:15 GMT

C->S:

GET /iptvepg/function/frame.jsp HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ztebw V1.0)
Host: 58.223.132.211:8080
Accept: */*
Accept-Encoding: identity
Referer: http://58.223.251.175:8080/iptvepg/function/index.jsp?UserGroupNMB=20000022&EPGGroupNMB=%20&UserToken=05143528095796312344240412212014&UserID=0512********&STBID=381001000000004000001A2B3C4D5E6F
Cookie: JSESSIONID=5D8488A123486165D886D30332AF32F7
Accept-Language: zh-cn

S->C:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=GBK
Content-Length: 191
Date: Tue, 12 Apr 2011 13:20:15 GMT

<html>
<head>
<title>frame</title>
</head>
<body bgcolor="#000000">
<script type="" language="javascript">
window.location = "frameset_judger.jsp";
</script>
</body>
</html>

C->S:

GET /iptvepg/function/frameset_judger.jsp HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ztebw V1.0)
Host: 58.223.132.211:8080
Accept: */*
Accept-Encoding: identity
Referer: http://58.223.132.211:8080/iptvepg/function/frame.jsp
Cookie: JSESSIONID=5D8488A123486165D886D30332AF32F7
Accept-Language: zh-cn

S->C:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=GBK
Content-Length: 773
Date: Tue, 12 Apr 2011 13:20:15 GMT

<html>
<head>
<title>
frameset_judger
</title>
</head>
<body bgcolor="#000000">
<form name="mainWinSrcForm" method="post" action="frameset_builder.jsp" target="_top">
<input type="hidden" name="MAIN_WIN_SRC" value="http://58.223.132.211:8080/iptvepg/frame69/channel_start.jsp?tempno=-1">
<input type="hidden" name="NEED_UPDATE_STB" value="1">
<input type="hidden" name="BUILD_ACTION" value="FRAMESET_BUILDER">
</form>
<script language="javascript" type="">

  if (typeof(top.browserType) == "undefined" || top.browserType == null){
 
mainWinSrcForm.submit();
  }
  else{

    top.jsSetControl("vas_frameset_create_flag","0");
    window.location = "http://58.223.132.211:8080/iptvepg/frame69/channel_start.jsp?tempno=-1";
  }
  </script>
</body>
</html>
C->S:
POST /iptvepg/function/frameset_builder.jsp HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ztebw V1.0)
Host: 58.223.132.211:8080
Accept: */*
Accept-Encoding: identity
Referer: http://58.223.132.211:8080/iptvepg/function/frameset_judger.jsp
Cookie: JSESSIONID=5D8488A123486165D886D30332AF32F7
Accept-Language: zh-cn
Content-Length: 149
Content-Type: application/x-www-form-urlencoded

MAIN_WIN_SRC=http%3A%2F%2F58.223.132.211%3A8080%2Fiptvepg%2Fframe69%2Fchannel_start.jsp%3Ftempno%3D-1&NEED_UPDATE_STB=1&BUILD_ACTION=FRAMESET_BUILDER

S->C:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=GBK
Transfer-Encoding: chunked
Date: Tue, 12 Apr 2011 13:20:15 GMT

B700V2Y登录EPG服务器过程