自动回复消息,Linux下电信网通双线路实现方式

  Linux下邮电通讯网通双线路实现格局是那般,三块网卡,eth0 为LAN口,eth1
为率先个WAN口,接邮电通讯线路,eth2为第贰个WAN口,接网通线路。作者这里都以依据牢固IP格局配置的,借使是要PPPOE则温馨布署PPPOE部分,作者这里首即便给我们提供计策部分。

Java学习笔记八—类的静态变量与静态方法的访谈与调用格局,java学习笔记

静态变量又称类变量,静态方法又称类方法,它们统称为静态成员或类成员。静态成员由static修饰,是属于全体类的,全体的目的分享这么些静态成员。不须求创制任何对象,静态成员在类装载时就已先河化了,整个运转期间其内部存储器地方不改变,直到类卸载。鉴于静态成员的那个特点,访谈静态变量以及定义或调用静态方法时与非静态成员也是有区别之处。上面分别做出表明。

1.静态变量

  • 类的非静态方法、静态方法都能够直接访问静态变量
  • 另外类要访谈某些类的静态变量,既可以够经超过实际例名访谈,也能够直接用类名来访问,推荐用类名访问的法子,那样能越来越直观的认证访问的变量是静态变量

2.静态方法

  • 不能够一直访谈非静态变量,也无法直接调用非静态方法,需求实例化一个指标,再经过该目的来访谈要访问的非静态变量或要调用的非静态方法。也正是说,静态方法不可能从来利用非静态成员。个人领悟是,非静态成员是寄托对象而存在的,当未有实例一个指标时,非静态成员是一贯不分配内部存款和储蓄器空间的,静态方法要动用非静态成员不精通要到何地去找,当然就无法平素动用非静态成员了。
  • 别的类要调用有个别类的静态方法,既可以够透超过实际例名调用,也能够直接用类名来调用,推荐用类名调用的点子,那样能越来越直观的表明调用的主意是静态方法

 

3.底下以简练的代码验证方面包车型大巴结论

概念了三个Person类,类的代码见最末尾。

 

(1).类的静态方法能够一贯访谈静态变量

  • 静态方法staticMethod访谈了静态变量citizenship
  • 概念并动用了一部分变量testY

staticMethod()方法如下:

public static void staticMethod() {
  int testY = 20;

  System.out.println("She has applied for " + citizenship + " citizenship"); //static variable access
  System.out.println("She's now " + testY + " years old");  //local variable access
 }

main()方法如下:

public static void main(String[] args) {
  Person xiaoxi = new Person("xiaoxi",29,"female","piano");

  xiaoxi.informationPrint();

  staticMethod();
 }

输出结果如下:

My name is xiaoxi
I am 29 years old
I am a girl
My hobby is piano
I am a chinese
She has applied for Chinese citizenship
She's now 20 years old

结果剖析:

  • 静态方法能够向来访谈静态变量
  • 静态方法能够自定义局地变量

 

(2),静态方法不能直接访问非静态变量

 [1].staticMethod直接访谈静态变量citizenship,现身谬误

  • 静态方法staticMethod访问了静态变量citizenship
  • 概念并采纳了一些变量testY
  • 访谈了非静态变量hobby

staticMethod()方法如下:

public static void staticMethod() {
  int testY = 20;

  System.out.println("She has applied for " + citizenship + " citizenship"); //static variable access
  System.out.println("She's now " + testY + " years old");  //local variable access
  System.out.println("She doesn't like " + hobby); //nonstatic variable access
 }

main方法同上。

出口结果如下:

My name is xiaoxi
I am 29 years old
I am a girl
My hobby is piano
I am a chinese
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
 Cannot make a static reference to the non-static field hobby

 at human.Person.staticMethod(Person.java:99)
 at human.Person.main(Person.java:107)

结果分析:

  • 静态方法不可能一贯访问非静态变量,不然会现出“Cannot make a static
    reference to the non-static 田野先生 hobby” 的不当。

 

 [2].staticMethod()成立二个对象testP,由testP采访非静态变量hobby,成功推行

 

  • 静态方法staticMethod使用了静态变量citizenship
  • 概念并应用了有些变量testY
  • 创立多个Person实例testP,并采纳了testP的变量hobby

 

staticMethod()方法如下:

public static void staticMethod() {
  int testY = 20;
  Person testP = new Person();

  System.out.println("She has applied for " + citizenship + " citizenship"); //static variable access
  System.out.println("She's now " + testY + " years old");  //local variable access
  System.out.println("She doesn't like " + testP.hobby); // nonstatic variable access via object instance testP
 }

main方法同上。

出口结果如下:

My name is xiaoxi
I am 29 years old
I am a girl
My hobby is piano
I am a chinese
She has applied for Chinese citizenship
She's now 20 years old
She doesn't like null

结果剖判:

  • 静态方法要拜候非静态变量,能够先实例化三个对象,再通过对象访谈。

 

(3),静态方法不得以一向调用非静态方法

 [1].staticMethod()直接访谈非静态方法informationPrint(),现身谬误

  • 静态方法staticMethod使用了静态变量citizenship
  • 概念并应用了部分变量testY
  • 开创一个Person实例testP,并选取了testP的hoppy变量
  • 直接调用非静态方法informationPrint()

staticMethod()方法如下:

 public static void staticMethod() {
  int testY = 20;
  Person testP = new Person();

  System.out.println("She has applied for " + citizenship + " citizenship"); //static variable access
  System.out.println("She's now " + testY + " years old");  //local variable access
  //System.out.println("She doesn't like " + testP.hobby); //nonstatic variable access
  System.out.println("She doesn't like " + testP.hobby); // nonstatic variable access via object instance testP
  System.out.println("Her personal information is as follows:");
  informationPrint();
 }

main()方法同上。

出口结果如下:

My name is xiaoxi
I am 29 years old
I am a girl
My hobby is piano
I am a chinese
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
 Cannot make a static reference to the non-static method informationPrint() from the type Person

 at human.Person.staticMethod(Person.java:103)
 at human.Person.main(Person.java:111)

结果分析:

  • 静态方法无法直接调用非静态方法,不然会现出与向来访谈非静态变量类似的不当,Cannot
    make a static reference to the non-static method informationPrint()
    from the type Person。

 

 [2].通过已有指标testP来调用informationPrint()方法,成功实行

  • 静态方法staticMethod使用了静态变量citizenship
  • 概念并选取了有些变量testY
  • 始建多少个Person实例testP,并动用了testP的hoppy变量
  • 通过testP调用非静态方法informationPrint()

staticMethod()方法如下:

 public static void staticMethod() {
  int testY = 20;
  Person testP = new Person();

  System.out.println("She has applied for " + citizenship + " citizenship"); //static variable access
  System.out.println("She's now " + testY + " years old");  //local variable access
  System.out.println("She doesn't like " + testP.hobby); // nonstatic variable access via object instance testP
  System.out.println("Her personal information is as follows:");
  //informationPrint();
  testP.informationPrint();
 }

main()方法同上。

输出结果如下:

My name is xiaoxi
I am 29 years old
I am a girl
My hobby is piano
I am a chinese
She has applied for Chinese citizenship
She's now 20 years old
She doesn't like null
Her personal information is as follows:
My name is null
I am 0 years old
Something is wrong!
My hobby is null
I am a chinese

结果深入分析:

  • 静态方法要调用非静态方法,能够先实例化贰个目的,再经过该对象来调用。

 

附Person类:

package human;

public class Person {
 String name;
 int age;
 String gender;

 private String hobby;
 protected String residence;

 static String citizenship = "Chinese";

 public Person() {

 }

 public Person(String n, String g) {
  this.name = n;
  this.gender = g;
 }

 public Person(String n, int a, String g, String h) {
  this.name = n;
  this.age = a;
  this.gender = g;
  this.hobby = h;

  //test:静态变量初始化的时机是否在构造方法之前
  System.out.println("constructor:");
  System.out.println("change value of the static variable citizenship " + "\"" + citizenship + "\"");
  citizenship = "US";
  System.out.println(" to " + "\"" + citizenship + "\"");
 } 

 public Person(String n, int a, String g, String h, String r) {
  this.name = n;
  this.age = a;
  this.gender = g;
  this.hobby = h;
  this.residence = r;
 } 

 public void setName(String n) {
  this.name = n;
 }

 public void setAge(int a) {
  this.age = a;
 }

 public void setGender(String g) {
  this.gender = g;
 }

 public void setHobby(String h) {
  this.hobby = h;
 }

 public void setResidence(String r) {
  this.residence = r;
 }

 public String getName() {
  return this.name;
 }

 public int getAge() {
  return this.age;
 }

 public String getGender() {
  return this.gender;
 }

 public String getHobby() {
  return this.hobby;
 }

 public String getResidence() {
  return this.residence;
 }

 public void informationPrint() {
  System.out.println("My name is " + getName());
  System.out.println("I am " + getAge() + " years old");

  if(getGender() == "female")
   System.out.println("I am a girl");
  else
   if(getGender() == "male")
    System.out.println("I am a boy");
   else
    System.out.println("Something is wrong!");
  System.out.println("My hobby is " + hobby);

  if(citizenship == "Chinese")
   System.out.println("I am a chinese");
  //test:静态变量是否在构造方法之前初始化
  else
   if(citizenship == "US")
    System.out.println("I am an American");
   else
    System.out.println("Oh,something is wrong");
 }

 public static void staticMethod() {
  int testY = 20;
  Person testP = new Person();

  System.out.println("She has applied for " + citizenship + " citizenship"); //static variable access
  System.out.println("She's now " + testY + " years old");  //local variable access
  System.out.println("She doesn't like " + testP.hobby); // nonstatic variable access via object instance testP
  System.out.println("Her personal information is as follows:");
  //informationPrint();
  testP.informationPrint();
 }

 public static void main(String[] args) {
  Person xiaoxi = new Person("xiaoxi",29,"female","piano");

  xiaoxi.informationPrint();

  staticMethod();
 }
}

  

静态变量又称类变量,静态方法又称类方法,它们统称为静态成…

2、自动回复音讯,自动恢复生机信息

上一篇已经接入大伙儿平台,现在的话下新闻回复

连接大伙儿平台与消息管理分裂:

接通民众平台 : method = RequestMethod.GET;

音讯管理       : method = RequestMethod.POST

上边都是以文件新闻为例子,其余新闻查看文书档案 :

由上航海用教室,大家已经理解了 普通微信顾客向民众账号发信息XML结构

1、XmlMessageEntity 实体类

package com.wenxi.Entity;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlMessageEntity {

 private String ToUserName;
 private String FromUserName;
 private Long CreateTime;
 private String MsgType;
 private String Content;
 private String Event;
 private Long MsgId;

 public String getEvent() {
  return Event;
 }

 public void setEvent(String event) {
  Event = event;
 }

 public String getToUserName() {
  return ToUserName;
 }

 public void setToUserName(String toUserName) {
  ToUserName = toUserName;
 }

 public String getFromUserName() {
  return FromUserName;
 }

 public void setFromUserName(String fromUserName) {
  FromUserName = fromUserName;
 }

 public Long getCreateTime() {
  return CreateTime;
 }

 public void setCreateTime(Long createTime) {
  CreateTime = createTime;
 }

 public String getMsgType() {
  return MsgType;
 }

 public void setMsgType(String msgType) {
  MsgType = msgType;
 }

 public String getContent() {
  return Content;
 }

 public void setContent(String content) {
  Content = content;
 }

 public Long getMsgId() {
  return MsgId;
 }

 public void setMsgId(Long msgId) {
  MsgId = msgId;
 }

 @Override
 public String toString() {
  return "XmlMessageEntity [ToUserName=" + ToUserName + ", FromUserName="
    + FromUserName + ", Event=" + Event + ", MsgType=" + MsgType
    + ", Content=" + Content + ", MsgId=" + MsgId + "]";
 }

}

2、管理音信并再次来到

package com.wenxi.controller;

import com.wenxi.Entity.XmlMessageEntity;
import com.wenxi.utils.SecurityUtil;
import com.wenxi.utils.WeixinUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.Date;

@Controller
public class ValidateController {

    @RequestMapping(value = "/weixinValidate",method = RequestMethod.GET)
    @ResponseBody
    public String weixinValidate(String signature, String timestamp, String nonce, String echostr ){

        // 1)将token、timestamp、nonce三个参数进行字典序排序
        String[] arrs = {WeixinUtil.TOKEN,timestamp,nonce}; //WeixinUtil.TOKEN: 抽取出来的TOKEN,为了重用
        Arrays.sort(arrs);
        // 2)将三个参数字符串拼接成一个字符串进行sha1加密
        String str = arrs[0] + arrs[1] + arrs[2];
        // 3)开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
        if (signature.equals(SecurityUtil.SHA1(str))){
            //确认此次GET请求来自微信服务器,返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败
            return echostr;
        }else
            return null;
    }

    /**
     * 自动回复信息
     */
    @RequestMapping(value = "weixinValidate",method = RequestMethod.POST)
    @ResponseBody
    public XmlMessageEntity weixinValidate(@RequestBody XmlMessageEntity entity){
        System.out.println(entity);
        XmlMessageEntity returnMessageEntity = new XmlMessageEntity();
        returnMessageEntity.setFromUserName(entity.getToUserName());
        returnMessageEntity.setToUserName(entity.getFromUserName());
        returnMessageEntity.setContent("谢谢大家关注!");
        returnMessageEntity.setCreateTime(new Date().getTime());
        returnMessageEntity.setMsgType("text");

        return returnMessageEntity;
    }
}

以下是还原的XML结构,其余音信查看文档:

3、测试

一、关注公众号: 在你的测试账号页面,扫描图下的地方二维码,然后点击关注

控制台打印:
XmlMessageEntity [ToUserName=xxxxxa436, FromUserName=xxxxxxxxxlJdq9AY2E, Event=subscribe, MsgType=event, Content=null, MsgId=null]
这里ToUserName(开发者微信号)可以在测试页面顶部查看,如下图

FromUserName(微信用户OpenID)可以在 测试号二维码 中 用户列表找到


微信显示:

二、取消关注公众号
控制台打印:
XmlMessageEntity [ToUserName=xxxxxa436, FromUserName=xxxxxxxxxlJdq9AY2E, Event=unsubscribe, MsgType=event, Content=null, MsgId=null]

互相的区分: 伊夫nt

unsubscribe:  撤废关怀公众号

subscribe:     关切公众号

三,在公众号发消息
由于程序还没对MsgType进行分类处理,所以都是回复谢谢大家关注(下篇再处理)

控制台打印:
XmlMessageEntity [ToUserName=xxxxxa436, FromUserName=xxxxxxxxxlJdq9AY2E, Event=null, MsgType=text, Content=测试一下, MsgId=6479560144755671793]

关注(撤消) 与 普通音讯发送不一致:

伊芙nt:       关注(撤废)为subscribe大概unsubscribe,
而普通音讯发送为null;

MsgType:   关怀(打消)为event, 而普通音讯发送为text;

Content:    关注(撤除)为null, 而普通音讯发送为现实的音讯;

MsgId:       关怀(撤除)为null, 而普通音讯发送为现实的ID;

1、关于重试的消息排重,推荐使用msgid排重。
2、微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次。假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试。详情请见“发送消息-被动回复消息”。

上一篇已经接入公众平台,今后的话下消息回复 接入民众平台与新闻处理分裂:
接入公众平台 : method…

  将从五个WAN口出去的数据包MASQUERADE
  /sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
  /sbin/iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

  然后,给系统扩大三个标识为100的路由表,扩展一个私下认可网关,那些默许网关是网通提供的网关。呵呵,为啥自身的帖子里的多路由表总用100吗,呵呵。
  ip route add 0/0 via 218.59.*.* table 100
  然后给系统主路由表配置网关,那个网关是电信的网关
  ip route add 0/0 via 219.146.*.*
  然后增添路由准则,让具有通向网通的数据查询标示为100的路由表:
  ip rule add to 60.0.0.0/13 table 100
ip rule add to 60.8.0.0/15 table 100
ip rule add to 60.10.0.0/16 table 100
……….
  准则非常多,大约有100多条,应该是全部的席卷了网通的有所IP子网,小编会付出完整法规。
  那样,通向网通的数据会查询路由表100,而通往别的的地点的数额,这里内定邮电通讯,则会朝着邮电通讯。当然,如若有更扑朔迷离的运用,比如还应该有教育网的线路,小编深信不疑大家也领悟如何做了,再充实路由表,再充实战术就足以了。
  这些布局情势给北方的意中人使用了,感到效果很好,笔者期待对我们也是有利于。要小心的是,在配备网卡的时候,先不用铺排网关,不要选拔老的ifconfig命令来布局网关,而要使用iproute2来配置网关,不然会促成争执,大概使用 ip route replace 命令来替换 ip route add 命令。
  整个配置文件如下:(并不曾包含端口过滤的布局,大家依据供给本人安插)居然附属类小部件只可以上传jpg和
gif 呵呵,小编把脚本后缀加了个.jpg
,通过右键属性,把文件下下来,自身改回来吧。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

标签:
网站地图xml地图