zsf 3 недель назад
Родитель
Сommit
7d6291bef9

+ 5 - 1
src/main/java/com/rf/psychological/filter/JWTInterceptorPublicConfig.java

@@ -38,7 +38,11 @@ public class JWTInterceptorPublicConfig implements WebMvcConfigurer {
                 "/api/orderInfo/queryOrderDetail/**","/scaleExternalSource/save"};
         String[] wxPay = new String[]{"/api/wx-pay/native/notify","/api/wx-pay/refunds/notify",
                 "/api/wx-pay/getPhone/*","/api/wx-pay/code2openid","/api/wx-pay/h5Pay",
-                "/api/wx-pay/code2openid2","/api/wx-pay/queryOrder/**","/api/promotionInfo/queryPromotionDetail/**","/record/getWeiboRecordById","/record/getWeiboRecordById/**"};
+                "/api/wx-pay/code2openid2","/api/wx-pay/queryOrder/**",
+                "/api/promotionInfo/queryPromotionDetail/**",
+                "/record/getWeiboRecordById",
+                "/mp/api/message",
+                "/record/getWeiboRecordById/**"};
         String[] systemApi = new String[]{"/system/login","/system/loginH5","/system/forgotPassword","/system/registerUser","/system/temporaryUser","/api/douyin/code2Session","/result/**"};
         registry.addInterceptor(jwtInterceptor)
                 .addPathPatterns("/**")

+ 19 - 8
src/main/java/com/rf/psychological/mp/rest/MpController.java

@@ -56,12 +56,17 @@ public class MpController extends BaseController {
      */
     @GetMapping("/message")
     public String check(String signature,String timestamp,String nonce,String echostr){
-
-        log.info("signature:{} == timestamp:{} == nonce:{} == echostr:{}",signature,timestamp,nonce,echostr);
-        if (signature.equals(mpUtils.getSignature(mptoken,timestamp,nonce))){
-            return echostr;
+        try {
+            log.info("signature:{} == timestamp:{} == nonce:{} == echostr:{}",signature,timestamp,nonce,echostr);
+            if (signature.equals(mpUtils.getSignature(mptoken,timestamp,nonce))){
+                return echostr;
+            }
+            return "";
+        }catch (Exception e){
+            e.printStackTrace();
+            return "";
         }
-        return "";
+
     }
 
 
@@ -72,13 +77,19 @@ public class MpController extends BaseController {
     @ApiOperation("code2accesstoken")
     @SafetyProcess
     public Result code2accesstoken(@PathVariable String code){
-        JSONObject jsonObject = mpUtils.code2accesstoken(code);
-        return success(jsonObject);
+        try {
+            JSONObject jsonObject = mpUtils.code2accesstoken(code);
+            return success(jsonObject);
+        }catch (Exception e){
+            e.printStackTrace();
+            log.info(e.getMessage());
+            return fail();
+        }
+
     }
 
 
     @GetMapping("/signature2")
-    //@OperationLogAnnotation("获取JS-SDK签名")
     @ApiOperation(value = "获取JS-SDK签名")
     public Result signature2(String url) {
         String jsapiTicket = redisTemplate.opsForValue().get("jsapi_ticket");

+ 38 - 26
src/main/java/com/rf/psychological/mp/utils/MpUtils.java

@@ -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());
         }
 
+
     }
 }