JSNOP调用。。。

HTML:

//登录
function login(){

var URL = "http://127.0.0.1:8080/miugogate/GateWay";

//RSA私钥设置
setMaxDigits(130);
var key = new RSAKeyPair("8b33d1d7027cb8f910d538d6cd1e0c7344b3fc3728c83f39fec7d4149a4332f740ba6867ce585addbd3c6e3df6cac316956fc316843cb62604495fdfbd11ab607b9696e04ca7e1afda894d39f240431d3ae9b8fe3af6d3c6f352e4cd70f2c55669bb4e0d77ec22b56c00e412b52ec7e1f092b124d4bd67754b7bb43bddca8441");

var service = "login"; //登录标识
var name = "wasuadmin"; //用户名
var pass = "21218CCA77804D2BA1922C33E0151105";//密码
var tid = "112"; //设备编号
var data = "service="+service+"&name="+name+"&pass="+pass+"&tid="+tid; //需要签名的字段(RSA签名)
var sign = hex_md5(data); //签名后的串
$("#signstr").val(sign);
$.ajax({ 
type : "post",
async:false, 
url : encodeURI(URL), //跨域请求的URL 
data: encodeURI(data+"&sign="+sign),
dataType : "jsonp", 
//传递给请求处理程序,用以获得jsonp回调函数名的参数名(默认为:callback) 
jsonp: "jsoncallback", 
success : function(json){ 
alert(json[0].uuid+"|"+
json[0].phone_no+"|"+
json[0].cust_name+"|"+
json[0].nick_name+"|"+
json[0].acct_bal+"|"+
json[0].acct_bal_valid+"|"+
json[0].return_sign+"|"+
json[0].return_code+"|"+
json[0].return_msg); 


});

}

 

 

ACTION:


logger.info("SmartTV调用登录接口");
 String jsoncallback = request.getParameter("jsoncallback");  
String name = request.getParameter("name");
String pass = request.getParameter("pass");
String tid = request.getParameter("tid");
String sign = request.getParameter("sign");

//必填字段验证
if(StringUtil.isEmpty(name)||StringUtil.isEmpty(pass)||StringUtil.isEmpty(tid)||StringUtil.isEmpty(sign)){
isError = true;
return_code = RETURN_CODE_0002;
return_msg = RETURN_MSG_0002;
}

//需要MD5验签的字符串
String to_sign = "service="+service+"&name="+name+"&pass="+pass+"&tid="+tid;

//验签
if(!sign.toUpperCase().equals(MD5.getEncodeString(to_sign))){
isError = true;
return_code = RETURN_CODE_0003;
return_msg = RETURN_MSG_0003;
}


//验证商户信息
if(!isError){
if (!StringUtil.isEmpty(name) && !StringUtil.isEmpty(pass) && !cheackMchnt(name, pass)) {
isError = true;
return_code = RETURN_CODE_0004;
return_msg = RETURN_MSG_0004;
}
}


//返回JSON字段
String uuid = "";
String card_no = "";
String phone_no = "";
String cust_name= "";
String nick_name= "";
String acct_bal = "";
String acct_bal_valid = "";
//登录
if(!isError){
M9011 m9011 = new M9011();
m9011.setSTD_ID(tid);
try {
m9011.execute();
return_code = m9011.getResult_no();
return_msg = m9011.getResultDescription();
logger.debug("核心return_code:"+return_code);
logger.debug("核心return_msg:"+return_msg);
if(m9011.getResult_no().equals("0000") || m9011.getResult_no().equals("0326")){
M9011VO m9011VO = m9011.getReturnList().get(0);
uuid = m9011VO.getUUID();
card_no = m9011VO.getCARDNO();
phone_no = m9011VO.getCONTACT_PHONE();
cust_name= m9011VO.getCUST_NAME();
nick_name= m9011VO.getNICK_NAME();
acct_bal = m9011VO.getACCT_BAL();
acct_bal_valid = m9011VO.getACCT_BAL_VALID();
}
} catch (Exception e) {
e.printStackTrace();
}
}

//返回JSON信息
String return_sign = MD5.getEncodeString("uuid="+uuid+"&card_no="+card_no+"&phone_no="+phone_no+"&acct_bal="+acct_bal+"&acct_bal_valid="+acct_bal_valid);
Gson gson = new Gson();
Map<String, String> map = new HashMap<String, String>();
map.put("uuid",uuid);
map.put("card_no",card_no);
map.put("phone_no",phone_no);
map.put("cust_name",cust_name);
map.put("nick_name",nick_name);
map.put("acct_bal",acct_bal);
map.put("acct_bal_valid",acct_bal_valid);
map.put("return_sign",return_sign);
map.put("return_code",return_code);
map.put("return_msg",return_msg);
//out.print(jsoncallback+"([{ name:'John',age:'19'},{ name:'joe',age:'20'}])"); 
//out.print(jsoncallback+"([{\"return_sign\":\"4C6D28C33A036AD8EF5FC8FE8E07D334\",\"return_msg\":\"错误的签名信息\",\"uuid\":\"\",\"return_code\":\"0003\",\"phoneno\":\"\"}])");
String jsonStr = gson.toJson(map);
logger.debug("返回json:"+jsonStr);
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
out.print(jsoncallback+"(["+jsonStr+"])");

posted @ 2013-03-08 14:39  七郎  Views(706)  Comments(0Edit  收藏  举报