package com.sino.rrs.action;


import com.alibaba.fastjson.JSONObject;
import com.sino.publicclass.base.BaseAction;
import com.sino.weixin.oauth.util.AdvancedUtil;
import com.sino.weixin.oauth.util.Constants;

public class ApiSignatureAction extends BaseAction{
	private AdvancedUtil util = new AdvancedUtil();
	
	public void signature() throws Exception {
		String url = request.getParameter("url");
		int index = url.indexOf("#");
        if (index > 0) {
        	url = url.substring(0, index);
        }
        
        System.out.println("Constants.API_TICKET=="+Constants.API_TICKET+"<"+Constants.TIME_STAMP);

        String timestap = Long.toString(System.currentTimeMillis() / 1000);
	    String signature = util.getSha1Signature(Constants.API_TICKET, Constants.NONCESTR,timestap,url);
	    
	    JSONObject jsonObject = new JSONObject();
	    jsonObject.put("appId",Constants.AppId); 
	    jsonObject.put("nonce",Constants.NONCESTR); 
	    jsonObject.put("timestamp",timestap); 
	    jsonObject.put("signature",signature); 
		response.getWriter().print(jsonObject.toJSONString());
		setNext(false);
		
	}
}
