本文章只做个人记录使用,有需要可以参考,不明白下方留言
直接上代码,首先,传过来你要发送的消息
TencentAIAnswer 实体类
import java.io.Serializable;
/**
* 收到的微信消息
*
* @date 创建时间:2017年7月3日 下午10:28:06
* @version 1.0
*
*/
public class TencentAIAnswer implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String session;
private String answer;
public String getSession() {
return session;
}
public void setSession(String session) {
this.session = session;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}
RandomUtils 工具类
import java.util.Random;
public class RandomUtils {
public static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String LETTERCHAR = "abcdefghijkllmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String NUMBERCHAR = "0123456789";
public static final int[] NUMBERCHARARR = { 1, 2, 3, 4, 5, 6, 7 };
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public static String generateString(int length) {
StringBuffer sb = new StringBuffer();
Random random = new Random();
for (int i = 0; i < length; i++) {
sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length())));
}
return sb.toString();
}
/**
* 返回一个定长的随机纯字母字符串(只包含大小写字母)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public static String generateMixString(int length) {
StringBuffer sb = new StringBuffer();
Random random = new Random();
for (int i = 0; i < length; i++) {
sb.appe