⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windows.jsp

📁 陕西电信sp客户端
💻 JSP
字号:
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.security.*"%>
<%@ page import="java.net.*"%>

<%!
	public static String byte2HEX(byte b) {
		return (""+"0123456789ABCDEF".charAt(0xf&b>>4)+"0123456789ABCDEF".charAt(b&0xF));
	}
	public static byte stringHEX2bytes(String str) {
		return (byte) ("0123456789ABCDEF".indexOf(str.substring(0,1))*16 + "0123456789ABCDEF".indexOf(str.substring(1)));
	}
	public static String md5bytes2string(byte[] bytes){
		String result = "";
		for(int i=0; i<bytes.length; i++){
			result += byte2HEX(bytes[i]);
		}
		return result;
	}
	public static byte[] md5string2bytes(String str){
		byte[] b = new byte[str.length()/2];
		for(int i=0; i<b.length; i++){
			String s = str.substring(i*2,i*2+2);
			b[i] = stringHEX2bytes(s);
		}
		return b;
	}
	/**
	 * 从response字符串中,取出key字段的值,如果key指定的字段不存在,返回null
	 * @param key -- 字段名称
	 * @param response -- Time接口返回的内容。
	 * @return 字段的值,如果字段不存在返回null.
	 */
	public static String get(String key, String response)
	{
		String POSTFIX = "=\"";
		String RIGTH_PARENTHESIS = "\"";
		String field = key + POSTFIX;
		String result = null;
		if(response == null || response.trim().length() == 0)
		{
			return null;
		}
		if(response.indexOf(field) < 0)
		{
			return null;
		}
		int pre = response.indexOf(field) + field.length();
		int post = response.indexOf(RIGTH_PARENTHESIS, pre);
		if(post < 0)
		{
			return null;
		}
		result = response.substring(pre, post);
		if(result != null && result.trim().length() == 0)
		{
			return null;
		}
		return result;
	}

%>
<%
	String userName = request.getParameter("username");
	String password = request.getParameter("password");
	String serviceCode = request.getParameter("serviceCode");
	if(userName == null || userName.length()==0){
		//初始页面
%>
<html>
<head>
<title>
检查用户是否包月
</title>
</head>
<body>
检查用户是否正确,是否已包月
<form method="post" name="form1" action="windows.jsp">

用户名  :<input name="username" type="text" value="icptest@GD.chinavnet.com"><BR>
密码    :<input name="password" type="text" value="test"><BR>
服务代码:<input name="serviceCode" type="text" value="45454"><BR>
<input  type="submit" >

</form>
</body>
</html>
<%
}else {

	MessageDigest aMD5Digest = MessageDigest.getInstance("MD5");
	aMD5Digest.update(password.getBytes());
	String md5edPass = md5bytes2string(aMD5Digest.digest());
	//利用Object的hashCode生成随机数
	String challenge = new Object().hashCode()+"";
	aMD5Digest.update((challenge + md5edPass).getBytes());
	md5edPass = md5bytes2string(aMD5Digest.digest());

	String serverURL="http://gd.chinavnet.com:8590/aaa/servlet/TimeInterface?user=" + userName + "&challenge=" + challenge + "&password="+md5edPass+"&serviceCode=" + serviceCode;
	System.out.println(serverURL);

	//invoke jsp pages here
	URL aurl = new URL(serverURL);
	BufferedReader in = new BufferedReader(new InputStreamReader(aurl.openStream()));
	String body="";
	String str=null;
	while((str=in.readLine())!=null){
		System.out.println(str);
		body += str;
	}

%>
服务器端返回结果:<BR>
result = <%=get("result",body)%><BR>
location = <%=get("location",body)%><BR>
password = <%=get("password",body)%><BR>
userType = <%=get("userType",body)%><BR>
billingMode = <%=get("billingMode",body)%><BR>
subscribeResult = <%=get("subscribeResult",body)%><BR>


<%
}
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -