|
@@ -108,19 +108,25 @@ public class MpUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public void getMpAccessToken(){
|
|
|
- log.info("获取accessToken");
|
|
|
- String requestUrl = domain+String.format(accessTokenUrl, mpAppid, mpSecret);
|
|
|
- // 发起GET请求获取凭证
|
|
|
- log.info(requestUrl);
|
|
|
- ResponseEntity<String> response = restTemplate.getForEntity(requestUrl, String.class);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
- if(!jsonObject.containsKey("errcode")){
|
|
|
- redisTemplate.opsForValue().set("access_token",jsonObject.getString("access_token"));
|
|
|
- }else {
|
|
|
- log.error("获取accessToken异常:");
|
|
|
- log.error("errcode:"+jsonObject.getString("errcode"));
|
|
|
- log.error("errmsg:"+jsonObject.getString("errmsg"));
|
|
|
+ try {
|
|
|
+ log.info("获取accessToken");
|
|
|
+ String requestUrl = domain+String.format(accessTokenUrl, mpAppid, mpSecret);
|
|
|
+ // 发起GET请求获取凭证
|
|
|
+ log.info(requestUrl);
|
|
|
+ ResponseEntity<String> response = restTemplate.getForEntity(requestUrl, String.class);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
+ if(!jsonObject.containsKey("errcode")){
|
|
|
+ redisTemplate.opsForValue().set("access_token",jsonObject.getString("access_token"));
|
|
|
+ }else {
|
|
|
+ log.error("获取accessToken异常:");
|
|
|
+ log.error("errcode:"+jsonObject.getString("errcode"));
|
|
|
+ log.error("errmsg:"+jsonObject.getString("errmsg"));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -128,22 +134,28 @@ public class MpUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public void getMpJsapiTicket(){
|
|
|
- log.info("获取jsapi_ticket");
|
|
|
- String mpWebAccessToken = redisTemplate.opsForValue().get("access_token");
|
|
|
- if(StringUtils.isNotEmpty(mpWebAccessToken)){
|
|
|
- String requestUrl = domain +String.format(mpJsapiTicketUrl,mpWebAccessToken);
|
|
|
- ResponseEntity<String> response = restTemplate.getForEntity(requestUrl, String.class);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
- if(jsonObject.getIntValue("errcode") == 0){
|
|
|
- redisTemplate.opsForValue().set("jsapi_ticket",jsonObject.getString("ticket"));
|
|
|
- }else {
|
|
|
- log.error("获取jsapi_ticket异常:");
|
|
|
- log.error("errcode:"+jsonObject.getString("errcode"));
|
|
|
- log.error("errmsg:"+jsonObject.getString("errmsg"));
|
|
|
+ try {
|
|
|
+ log.info("获取jsapi_ticket");
|
|
|
+ String mpWebAccessToken = redisTemplate.opsForValue().get("access_token");
|
|
|
+ if(StringUtils.isNotEmpty(mpWebAccessToken)){
|
|
|
+ String requestUrl = domain +String.format(mpJsapiTicketUrl,mpWebAccessToken);
|
|
|
+ ResponseEntity<String> response = restTemplate.getForEntity(requestUrl, String.class);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
+ if(jsonObject.getIntValue("errcode") == 0){
|
|
|
+ redisTemplate.opsForValue().set("jsapi_ticket",jsonObject.getString("ticket"));
|
|
|
+ }else {
|
|
|
+ log.error("获取jsapi_ticket异常:");
|
|
|
+ log.error("errcode:"+jsonObject.getString("errcode"));
|
|
|
+ log.error("errmsg:"+jsonObject.getString("errmsg"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("access_token 为空,将不再获取jsapi_ticket");
|
|
|
}
|
|
|
- }else{
|
|
|
- log.error("access_token 为空,将不再获取jsapi_ticket");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
}
|