在跨域请求中添加key识别判断,判断不通过则返回校验失败
<--------------------跨域访问------------------------------->
| | |
| | | public class ActionUtil extends ActionSupport{
|
| | | public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
|
| | |
|
| | | public final static String CROSS_DOMAIN_KEY = "44c4a294cb66d13727c14b065dbe8548"; //跨域请求 key
|
| | |
|
| | | public String key; //跨域识别码
|
| | |
|
| | | /*
|
| | | * 获取HttpServletRequest
|
| | |
| | | return new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss").format(c.getTime());
|
| | | }
|
| | |
|
| | | public static void main(String[] args) {
|
| | | System.out.println(ActionUtil.EncryptionMD5("vip"));
|
| | | }
|
| | |
|
| | | //获取时间的年份
|
| | | public static int getDateYear(Date date){
|
| | |
| | | res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,token");
|
| | | res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
|
| | | }
|
| | | |
| | | |
| | | |
| | | public void setKey(String key) {
|
| | | this.key = key;
|
| | | }
|
| | |
|
| | | public static void main(String[] args) { |
| | | String str = "福光电子";
|
| | | System.out.println(EncryptionMD5(EncryptionMD5(str)));
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | //跨域访问获取所有电池组的信息<-------跨域----------->
|
| | | public String searchInform_ky(){
|
| | | HttpServletResponse res = ActionUtil.getResponse();
|
| | | res.setHeader("Access-Control-Allow-Origin", "*"); //允许跨域访问
|
| | | res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,token");
|
| | | res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
|
| | | ServiceModel model;
|
| | | model = service.searchInform_ky();
|
| | | isAllowHeaders(); //允许跨域访问
|
| | | //System.out.println(key+"@@@@@@@@@@@@@@@@@@@@@@");
|
| | | ServiceModel model = new ServiceModel();
|
| | | if(key != null && CROSS_DOMAIN_KEY.equals(key)){
|
| | | model = service.searchInform_ky(); |
| | | }else{ |
| | | model.setCode(0);
|
| | | model.setMsg("识别码错误");
|
| | | }
|
| | | result = ActionUtil.tojson(model);
|
| | | return SUCCESS;
|
| | | }
|
| | |
| | | //跨域访问查询电池组的单体数据 < ! ---- ---- 跨域访问 ------------>
|
| | | public String serchByCondition_ky(){
|
| | | ActionUtil.isAllowHeaders();
|
| | | Batt_rtdata rtdata=getGson("yyyy-MM-dd HH:mm:ss").fromJson(json, Batt_rtdata.class);
|
| | | ServiceModel model=service.serchByCondition_ky(rtdata);
|
| | | ServiceModel model = new ServiceModel();
|
| | | if(key != null && CROSS_DOMAIN_KEY.equals(key)){ |
| | | Batt_rtdata rtdata=getGson("yyyy-MM-dd HH:mm:ss").fromJson(json, Batt_rtdata.class);
|
| | | model=service.serchByCondition_ky(rtdata); |
| | | }else{
|
| | | model.setCode(0);
|
| | | model.setMsg("识别码错误");
|
| | | }
|
| | | result=ActionUtil.tojson(model);
|
| | | return SUCCESS;
|
| | | }
|
| | |
| | | import com.fgkj.services.Batt_rtstateService;
|
| | | import com.opensymphony.xwork2.ActionSupport;
|
| | |
|
| | | public class Batt_rtstateAction extends ActionSupport{
|
| | | public class Batt_rtstateAction extends ActionUtil{
|
| | | private Batt_rtstateService service=new Batt_rtstateService();
|
| | | private ServiceModel model;
|
| | | private Batt_rtstate rtstate;
|
| | |
| | | //实时监测中的查询实时组端信息 <!-- 跨域访问 --->
|
| | | public String serchByCondition_ky(){
|
| | | ActionUtil.isAllowHeaders(); //允许跨域访问
|
| | | //System.out.println("开始查询rtstate");
|
| | | rtstate = ActionUtil.getGson().fromJson(json, Batt_rtstate.class);
|
| | | model=service.serchByCondition_ky(rtstate);
|
| | | model = new ServiceModel();
|
| | | if(key != null && CROSS_DOMAIN_KEY.equals(key)){
|
| | | //System.out.println("开始查询rtstate");
|
| | | rtstate = ActionUtil.getGson().fromJson(json, Batt_rtstate.class);
|
| | | model=service.serchByCondition_ky(rtstate); |
| | | }else{
|
| | | model.setCode(0);
|
| | | model.setMsg("识别码错误");
|
| | | }
|
| | | //System.out.println(model);
|
| | | result = ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").toJson(model);
|
| | | return SUCCESS;
|
| | |
| | | import com.fgkj.services.Batttestdata_infService;
|
| | | import com.opensymphony.xwork2.ActionSupport;
|
| | |
|
| | | public class BatttestdataAction extends ActionSupport {
|
| | | public class BatttestdataAction extends ActionUtil{
|
| | | private BatttestdataService service = new BatttestdataService();
|
| | | private String result;
|
| | | private Batttestdata btd;
|
| | |
| | | * @return
|
| | | */
|
| | | public String findhistory_ky(){
|
| | | ActionUtil.isAllowHeaders();
|
| | | Batttestdata btd = ActionUtil.getGson().fromJson(json, Batttestdata.class);
|
| | | //System.out.println(btd);
|
| | | ServiceModel model = service.serchByCondition_ky(btd);
|
| | | isAllowHeaders();
|
| | | ServiceModel model = new ServiceModel();
|
| | | if(key !=null && CROSS_DOMAIN_KEY.equals(key)){ |
| | | Batttestdata btd = ActionUtil.getGson().fromJson(json, Batttestdata.class);
|
| | | //System.out.println(btd);
|
| | | model = service.serchByCondition_ky(btd);
|
| | | }else{
|
| | | model.setCode(0);
|
| | | model.setMsg("识别码错误");
|
| | | }
|
| | | result = ActionUtil.tojson(model);
|
| | | //System.out.println("*************************");
|
| | | return SUCCESS;
|
| | |
| | | import com.fgkj.services.Batttestdata_infService;
|
| | | import com.opensymphony.xwork2.ActionSupport;
|
| | |
|
| | | public class Batttestdata_infAction extends ActionSupport{
|
| | | public class Batttestdata_infAction extends ActionUtil{
|
| | | private Batttestdata_inf bti;
|
| | | private Batt_Maint_Dealarm bmd;
|
| | | private ServiceModel model;
|
| | |
| | | * 根据电池组id查询电池组的inf表中的放电信息 <!------ 跨域访问 --------->
|
| | | */
|
| | | public String searchBattTestInfDataById_ky(){
|
| | | ActionUtil.isAllowHeaders();
|
| | | Batttestdata_inf bti = ActionUtil.getGson().fromJson(json, Batttestdata_inf.class);
|
| | | model=service.serchByCondition_ky(bti);
|
| | | isAllowHeaders();
|
| | | if(key != null && CROSS_DOMAIN_KEY.equals(key)){
|
| | | Batttestdata_inf bti = ActionUtil.getGson().fromJson(json, Batttestdata_inf.class);
|
| | | model=service.serchByCondition_ky(bti); |
| | | }else{
|
| | | model = new ServiceModel();
|
| | | model.setCode(0);
|
| | | model.setMsg("识别码错误");
|
| | | }
|
| | | result=ActionUtil.tojson(model);
|
| | | return SUCCESS;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | //11.1FBS9100设备通信状态查询 <-- 跨域 -->
|
| | | public String serchByCondition_ky(){
|
| | | HttpServletResponse res = ActionUtil.getResponse();
|
| | | res.setHeader("Access-Control-Allow-Origin", "*"); //允许跨域访问
|
| | | res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,token");
|
| | | res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
|
| | | ServiceModel model = service.serchByCondition_ky();
|
| | | public String serchByCondition_ky(){ |
| | | isAllowHeaders(); //允许跨域访问
|
| | | ServiceModel model = new ServiceModel();
|
| | | if(key != null && CROSS_DOMAIN_KEY.equals(key)){
|
| | | model = service.serchByCondition_ky(); |
| | | }else{
|
| | | model.setCode(0);
|
| | | model.setMsg("识别码错误");
|
| | | } |
| | | result = tojson(model);
|
| | | return SUCCESS;
|
| | | }
|