一 前端代码
var wurl=location.href.split("#")[0];
console.log(wurl);
var code = GetQueryString("code");
var state = GetQueryString("state");
console.log("url=============================="+url);**/
var wtitle="分享标题";
var wdesc="分享描述";
var wimgUrl="http://xxxx/xxxx.jpg";
$.ajax({
url:'/hd/getCommonShare',
data:{targetUrl:'http://zm.hnbxwhy.com/huodong/sqgcw.html',code:code,state:state},
type: "post",
success: function(data){
wx.config({
//debug: true,
appId:data.appId,
timestamp:data.timestamp,
nonceStr:data.nonceStr,
signature:encodeURIComponent(data.signature),
// jsApiList:data.jsApiList
jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline']
});
wx.ready(function(){
wx.onMenuShareAppMessage({
title: wtitle,
desc: wdesc,
link:location.href.split("#")[0],
imgUrl:wimgUrl,
trigger: function (res) {
// 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
},
success: function (res) {
console.log('已分享!')
//alert('已分享');
},
cancel: function (res) {
console.log('已取消!')
//alert('已取消');
},
fail: function (res) {
//alert(JSON.stringify(res));
}
});
wx.onMenuShareTimeline({
title: wtitle,
desc: wdesc,
link: location.href.split("#")[0],
imgUrl:wimgUrl,
trigger: function (res) {
//alert('用户点击分享到朋友圈');
},
success: function (res) {
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
//alert(res.errMsg)
}
});
wx.error(function (res) {
// alert(res.errMsg);
});
});
},
error: function() {
//alert('ajax request failed!!!!');
return;
}
});
}
注意,传递参数的时候,要把当前页面的参数传完全,保证后端生成的key的URL和前端的URL一样,由于上个帖子中,当前页面增加了微信认证用户信息,所以当前的URL中会带有code和state参数.传到后台,后台做拼接.(也可以直接获取完整URL直接传到后台,但这种处理不能用get方式,只能使用post).
二 后端代码
2)工具类部分
(由于微信限定每天获取的key有次数限制,本地没有使用redis,使用JWT做缓存处理存万能正代码如下)
public class WeiXinUtil {
private static Logger log = LoggerFactory.getLogger(WeiXinUtil.class);
//微信的请求url
//企业号获取access_token的接口地址(GET) 限200(次/天) 缓存处理
public final static String access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={APPID}&secret={APPSECRET}";
//服务号获取jsapi_ticket的接口地址(GET) 限200(次/天)
public final static String jsapi_ticket_url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={ACCESS_TOKEN}&type=jsapi";
//微信map
private static Map
private static String appid = "xxxxxx";//服务号appid
private static String appsecret = "xxxxxx";//秘钥
private static String stringKey = "xxxxx";
/**
* 1.发起https请求并获取结果
*
* @param requestUrl 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param outputStr 提交的数据
* @return JSONObject(通过JSONObject.get ( key)的方式获取json对象的属性值)
* @author sgy
*/
public static JSONObject httpRequest(String requestUrl, String requestMethod, String outputStr) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
try {
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager[] tm = {new MyX509TrustManager()};
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setSSLSocketFactory(ssf);
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
} catch (ConnectException ce) {
log.error("Weixin server connection timed out.");
} catch (Exception e) {
log.error("https request error:{}", e);
}
return jsonObject;
}
/**
* 2.发送https请求之获取临时素材
*
* @param requestUrl
* @param savePath 文件的保存路径,此时还缺一个扩展名
* @return
* @throws Exception
*/
public static File getFile(String requestUrl, String savePath) throws Exception {
//String path=System.getProperty("user.dir")+"/img//1.png";
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager[] tm = {new MyX509TrustManager()};
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setSSLSocketFactory(ssf);
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod("GET");
httpUrlConn.connect();
//获取文件扩展名
String ext = getExt(httpUrlConn.getContentType());
savePath = savePath + ext;
System.out.println("savePath" + savePath);
//下载文件到f文件
File file = new File(savePath);
// 获取微信返回的输入流
InputStream in = httpUrlConn.getInputStream();
//输出流,将微信返回的输入流内容写到文件中
FileOutputStream out = new FileOutputStream(file);
int length = 100 * 1024;
byte[] byteBuffer = new byte[length]; //存储文件内容
int byteread = 0;
int bytesum = 0;
while ((byteread = in.read(byteBuffer)) != -1) {
bytesum += byteread; //字节数 文件大小
out.write(byteBuffer, 0, byteread);
}
System.out.println("bytesum: " + bytesum);
in.close();
// 释放资源
out.close();
in = null;
out = null;
httpUrlConn.disconnect();
return file;
}
/**
* @param requestUrl 微信上传临时素材的接口url
* @param file 要上传的文件
* @return String 上传成功后,微信服务器返回的消息
* @desc :2.微信上传素材的请求方法
* @author sgy
*/
public static String httpRequest(String requestUrl, File file) {
StringBuffer buffer = new StringBuffer();
try {
//1.建立连接
URL url = new URL(requestUrl);
HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection(); //打开链接
//1.1输入输出设置
httpUrlConn.setDoInput(true);
httpUrlConn.setDoOutput(true);
httpUrlConn.setUseCaches(false); // post方式不能使用缓存
//1.2设置请求头信息
httpUrlConn.setRequestProperty("Connection", "Keep-Alive");
httpUrlConn.setRequestProperty("Charset", "UTF-8");
//1.3设置边界
String BOUNDARY = "----------" + System.currentTimeMillis();
httpUrlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
// 请求正文信息
// 第一部分:
//2.将文件头输出到微信服务器
StringBuilder sb = new StringBuilder();
sb.append("--"); // 必须多两道线
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition: form-data;name=\"media\";filelength=\"" + file.length()
+ "\";filename=\"" + file.getName() + "\"\r\n");
sb.append("Content-Type:application/octet-stream\r\n\r\n");
byte[] head = sb.toString().getBytes("utf-8");
// 获得输出流
OutputStream outputStream = new DataOutputStream(httpUrlConn.getOutputStream());
// 将表头写入输出流中:输出表头
outputStream.write(head);
//3.将文件正文部分输出到微信服务器
// 把文件以流文件的方式 写入到微信服务器中
DataInputStream in = new DataInputStream(new FileInputStream(file));
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
outputStream.write(bufferOut, 0, bytes);
}
in.close();
//4.将结尾部分输出到微信服务器
byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线
outputStream.write(foot);
outputStream.flush();
outputStream.close();
//5.将微信服务器返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
} catch (IOException e) {
System.out.println("发送POST请求出现异常!" + e);
e.printStackTrace();
}
return buffer.toString();
}
/**
* 2.发起http请求获取返回结果
*
* @param requestUrl 请求地址
* @return
*/
public static String httpRequest(String requestUrl) {
StringBuffer buffer = new StringBuffer();
try {
URL url = new URL(requestUrl);
HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection();
httpUrlConn.setDoOutput(false);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
httpUrlConn.setRequestMethod("GET");
httpUrlConn.connect();
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
//InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
} catch (Exception e) {
}
return buffer.toString();
}
/**
* 3.获取access_token
*
* @param appid 凭证
* @param appsecret 密钥
* @return
*/
public static AccessToken getAccessToken(String appid, String appsecret) {
AccessToken accessToken = null;
String requestUrl = access_token_url.replace("{APPID}", appid).replace("{APPSECRET}", appsecret);
JSONObject jsonObject = httpRequest(requestUrl, "GET", null);
/*String json = "{\"access_token\":\"12_IBD8SscpyRbqnkdfb33Jlev_-GAl80BD0ueR9U7hvV0ieHzUJbRZyh34sCdyhEmV5do0l7I_UJzppShUxzN9zV8G5843riSyo9DkOeBOcQXyYQnMaW3g_XQNG7Zd_16RBP6WfiBIuq4MpoMbNWAdAGAYHL\",\"expires_in\": 7200}";
jsonObject = (JSONObject) JSONObject.parse(json);*/
// 如果请求成功
if (null != jsonObject) {
try {
accessToken = new AccessToken();
accessToken.setToken(jsonObject.getString("access_token"));
accessToken.setExpiresIn(jsonObject.getIntValue("expires_in"));
} catch (JSONException e) {
accessToken = null;
// 获取token失败
log.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getIntValue("errcode"), jsonObject.getString("errmsg"));
}
}
return accessToken;
}
/**
* 4. 获取JsapiTicket
*
* @param accessToken
* @return
* @author sgy
*/
public static WechatSdkTicketVo getJsapiTicket(String accessToken) {
WechatSdkTicketVo sdkTicket = null;
//https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxca57e6589ccebff0&secret=b7d7c5df24644563be32bd84b90c8bf6
//https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx3aad5abe62f2e5f6&secret=a1524ace0200b5580ea99eb5a045f049
String requestUrl = jsapi_ticket_url.replace("{ACCESS_TOKEN}", accessToken);
JSONObject jsonObject = httpRequest(requestUrl, "GET", null);
// 如果请求成功
/*String json = "{\"errcode\": 0,\"errmsg\": \"ok\",\"ticket\": \"kgt8ON7yVITDhtdwci0qeZh1YPznJusDPJ0hi73XsIM2QbUZfpbBsF_fxDZ9Ny-c32a4ju1kBkAY0VeSmf1Dtg\",\"expires_in\": 7200}";
jsonObject = (JSONObject) JSONObject.parse(json);*/
if (null != jsonObject) {
try {
sdkTicket = new WechatSdkTicketVo();
sdkTicket.setTicket(jsonObject.getString("ticket"));
sdkTicket.setExpires_in(jsonObject.getIntValue("expires_in"));
} catch (JSONException e) {
// 获取token失败
log.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getIntValue("errcode"), jsonObject.getString("errmsg"));
}
}
return sdkTicket;
}
/**
* 3.获取企业微信的JSSDK配置信息
*
* @param request
* @return
* @author sgy
*/
public static JsSDKConfig getWxConfig(HttpServletRequest request, String targetUrl, String appid) {
JsSDKConfig jsSDKConfig = new JsSDKConfig();
//1.准备好参与签名的字段
String nonceStr = UUID.randomUUID().toString(); // 必填,生成签名的随机串
String accessToken = WeiXinUtil.getAccessToken(targetUrl);
System.out.println("---------------------------accessToken=" + accessToken);
//首选缓存map中获取
String jsapi_ticket = "";
if (wxMap.get(accessToken) == null) {
//if(true){
WechatSdkTicketVo sdkTicket = getJsapiTicket(accessToken);// 必填,生成签名的H5应用调用企业微信JS接口的临时票据
jsapi_ticket = sdkTicket.getTicket();
System.out.println(sdkTicket.getExpires_in());
wxMap.put(accessToken, jsapi_ticket);
System.out.println("---------------------------jsapi_ticket=" + jsapi_ticket);
} else {
jsapi_ticket = wxMap.get(accessToken);
}
String timestamp = Long.toString(System.currentTimeMillis() / 1000); // 必填,生成签名的时间戳
//2.字典序 ,注意这里参数名必须全部小写,且必须有序
String sign = "jsapi_ticket=" + jsapi_ticket + "&noncestr=" + nonceStr + "×tamp=" + timestamp + "&url=" + targetUrl;
//3.sha1签名
String signature = "";
try {
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(sign.getBytes("UTF-8"));
signature = byteToHex(crypt.digest());
//System.out.println("signature:"+signature);
} catch (Exception e) {
e.printStackTrace();
return null;
}
jsSDKConfig.setAppId(appid);
jsSDKConfig.setTimestamp(timestamp);
jsSDKConfig.setNonceStr(nonceStr);
jsSDKConfig.setSignature(signature);
log.info(jsSDKConfig.toString());
return jsSDKConfig;
}
/**
* 方法名:byteToHex
* 详述:字符串加密辅助方法
* 开发人员:sgy
*
* @param hash
* @return 说明返回值含义
* @throws 说明发生此异常的条件
*/
private static String byteToHex(final byte[] hash) {
Formatter formatter = new Formatter();
for (byte b : hash) {
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}
private static String getExt(String contentType) {
if ("image/jpeg".equals(contentType)) {
return ".jpg";
} else if ("image/png".equals(contentType)) {
return ".png";
} else if ("image/gif".equals(contentType)) {
return ".gif";
}
return null;
}
/**
* 从缓存map中获取accesstoken,否则调微信接口获取
*
* @return
* @author sgy
*/
public static String getAccessToken(String targetUrl) {
String accessToken = "";
if (wxMap.get(targetUrl) == null) {
//if(true){
accessToken = getActiveAccessToken(targetUrl);
} else {
String accessTokenJwt = wxMap.get(targetUrl);
try {
Claims claims = parseJWT(accessTokenJwt);
accessToken = claims.getSubject();
} catch (Exception e) {
//过期清空
wxMap.clear();
//过期 重新获取
accessToken = getActiveAccessToken(targetUrl);
}
}
return accessToken;
}
/**
* 获取实时accesstoken
*
* @return
* @author sgy
*/
public static String getActiveAccessToken(String targetUrl) {
AccessToken token = WeiXinUtil.getAccessToken(appid, appsecret);
String accessToken = token.getToken();
String accessTokenJwt = creatJwt(token);
wxMap.put(targetUrl, accessTokenJwt);
return accessToken;
}
/**
* 解密jwt
*
* @param jwt
* @return
* @throws IllegalArgumentException
* @author sgy
*/
public static Claims parseJWT(String jwt) throws Exception {
SecretKey key = generalKey(); //签名秘钥,和生成的签名的秘钥一模一样
Claims claims = Jwts.parser() //得到DefaultJwtParser
.setSigningKey(key) //设置签名的秘钥
.parseClaimsJws(jwt).getBody();//设置需要解析的jwt
return claims;
}
/**
* 加密jwt
*
* @param jwt
* @return
* @throws IllegalArgumentException
*/
private static String creatJwt(AccessToken token) {
log.info("加密接口初始化参数开始!");
String accessToken = token.getToken();
int time = token.getExpiresIn();
//设置时间为1分钟
String userId = accessToken;
long ttlMillis = (time - 2000) * 1000;
//指定签名的时候使用的签名算法,也就是header那部分,jjwt已经将这部分内容封装好了。
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
long nowMillis = System.currentTimeMillis();//生成JWT的时间(当前计算机元年毫秒数)
Date now = new Date(nowMillis);
String prjLable = UUIDGenerator.getUUID32();
SecretKey key = generalKey();//生成签名的时候使用的秘钥secret,这个方法本地封装了的,一般可以从本地配置文件中读取,切记这个秘钥不能外露哦。它就是你服务端的私钥,在任何场景都不应该流露出去。一旦客户端得知这个secret, 那就意味着客户端是可以自我签发jwt了。
log.info("加密接口初始化参数结束!");
//下面就是在为payload添加各种标准声明和私有声明了
JwtBuilder builder = Jwts.builder()
//.setClaims(claims) //如果有私有声明,一定要先设置这个自己创建的私有的声明,这个是给builder的claim赋值,一旦写在标准的声明赋值之后,就是覆盖了那些标准的声明的
.setId(prjLable)
.setIssuedAt(now) //iat: jwt的签发时间
.setSubject(userId) //sub(Subject):代表这个JWT的主体,即它的所有人,这个是一个json格式的字符串,可以存放什么userid,roldid之类的,作为什么用户的唯一标志。
.signWith(signatureAlgorithm, key);//设置签名使用的签名算法和签名使用的秘钥
//如果过期时间不为0 则设置过期时间
if (ttlMillis >= 0) {
long expMillis = nowMillis + ttlMillis;
Date exp = new Date(expMillis);
builder.setExpiration(exp); //设置过期时间
}
return builder.compact();
}
/**
* 由字符串生成加密key
*
* @return
* @author sgy
*/
public static SecretKey generalKey() {
byte[] encodedKey = Base64.decodeBase64(stringKey);//本地的密码解码
SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");// 根据给定的字节数组使用AES加密算法构造一个密钥,使用 encodedKey中的始于且包含 0 到前 leng 个字节这是当然是所有。(后面的文章中马上回推出讲解Java加密和解密的一些算法)
return key;
}
public static String getAppid() {
return appid;
}
public static void setAppid(String appid) {
WeiXinUtil.appid = appid;
}
public static String getAppsecret() {
return appsecret;
}
public static void setAppsecret(String appsecret) {
WeiXinUtil.appsecret = appsecret;
}
/**
* 1.发起https请求并获取结果
*
* @param requestUrl 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param outputStr 提交的数据
* @return JSONObject(通过JSONObject.get ( key)的方式获取json对象的属性值)
* @author sgy
*/
public static JSONObject getCode(String requestUrl, String requestMethod, String outputStr) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
try {
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
} catch (ConnectException ce) {
log.error("Weixin server connection timed out.");
} catch (Exception e) {
log.error("https request error:{}", e);
}
return jsonObject;
}
/**
* 1.发起https请求并获取结果
*
* @param requestUrl 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param outputStr 提交的数据
* @return JSONObject(通过JSONObject.get ( key)的方式获取json对象的属性值)
* @author sgy
*/
public static String getWeixinCode(String requestUrl, String requestMethod, String outputStr) {
StringBuffer buffer = new StringBuffer();
try {
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
} catch (ConnectException ce) {
log.error("Weixin server connection timed out.");
} catch (Exception e) {
log.error("https request error:{}", e);
}
return buffer.toString();
}
}
3)实体类
/**
* @author sgy
* @date
*/
public class WechatSdkTicketVo extends WechatErrorVo {
private String ticket;
private int expires_in;
public String getTicket() {
return ticket;
}
public void setTicket(String ticket) {
this.ticket = ticket;
}
public int getExpires_in() {
return expires_in;
}
public void setExpires_in(int expires_in) {
this.expires_in = expires_in;
}
}
有疑问,请求留言 交流QQ :1360215811