parent
							
								
									a019d38c45
								
							
						
					
					
						commit
						40ab0a4fb3
					
				
				 7 changed files with 266 additions and 46 deletions
			
			
		@ -0,0 +1,18 @@ | 
				
			|||||||
 | 
					package com.ynxbd.push.controller; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.ynxbd.push.httpRequest.xbd.wx.WxCacheRequest; | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.PostMapping; | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RequestMapping; | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RestController; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@RestController | 
				
			||||||
 | 
					@RequestMapping("api") | 
				
			||||||
 | 
					public class ApiController { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @PostMapping("reToken") | 
				
			||||||
 | 
					    public String reToken() { | 
				
			||||||
 | 
					        WxCacheRequest.clearWxAccessToken(); | 
				
			||||||
 | 
					        return "success"; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,10 +0,0 @@ | 
				
			|||||||
package com.ynxbd.push.entity.xbd.wx; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import lombok.Data; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@Data | 
					 | 
				
			||||||
public class AccessToken { | 
					 | 
				
			||||||
    private Integer code; | 
					 | 
				
			||||||
    private String data; | 
					 | 
				
			||||||
    private String message; | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -0,0 +1,16 @@ | 
				
			|||||||
 | 
					package com.ynxbd.push.entity.xbd.wx; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import lombok.Data; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.Serializable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Data | 
				
			||||||
 | 
					public class RespAccessToken implements Serializable { | 
				
			||||||
 | 
					    private static final long serialVersionUID = 36888886677781604L; | 
				
			||||||
 | 
					    // 授权token
 | 
				
			||||||
 | 
					    private String accessToken; | 
				
			||||||
 | 
					    // 有效时间(s)
 | 
				
			||||||
 | 
					    private Integer expiresIn; | 
				
			||||||
 | 
					    // 创建时间
 | 
				
			||||||
 | 
					    private String createTime; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,43 @@ | 
				
			|||||||
 | 
					package com.ynxbd.push.helper; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.text.SimpleDateFormat; | 
				
			||||||
 | 
					import java.util.Date; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class DateHelper { | 
				
			||||||
 | 
					    public static final String yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss"; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * [日期字符串]转日期 | 
				
			||||||
 | 
					     * | 
				
			||||||
 | 
					     * @param dateStr 日期字符串 | 
				
			||||||
 | 
					     * @param format  日期格式 | 
				
			||||||
 | 
					     * @return 日期/时间 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public static Date strToDate(String dateStr, String format) { | 
				
			||||||
 | 
					        try { | 
				
			||||||
 | 
					            if (dateStr == null || format == null) { | 
				
			||||||
 | 
					                return null; | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					            return new SimpleDateFormat(format).parse(dateStr); | 
				
			||||||
 | 
					        } catch (Exception e) { | 
				
			||||||
 | 
					            e.printStackTrace(); | 
				
			||||||
 | 
					            return null; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 时间点距离当前时间多少秒 | 
				
			||||||
 | 
					     * | 
				
			||||||
 | 
					     * @param dateStr 时间点字符串 | 
				
			||||||
 | 
					     * @return 日期/时间 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public static long differCurSecond(String dateStr) { | 
				
			||||||
 | 
					        Date date = strToDate(dateStr, yyyy_MM_dd_HH_mm_ss); | 
				
			||||||
 | 
					        if (date == null) { | 
				
			||||||
 | 
					            return 0L; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					        return new Date().getTime() - date.getTime(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,73 @@ | 
				
			|||||||
 | 
					//package com.ynxbd.push.httpRequest.xbd.wx;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//@Slf4j
 | 
				
			||||||
 | 
					//public class Test {
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//    private static int RETRY_INDEX = 0;
 | 
				
			||||||
 | 
					//    private static final int MAX_RETRY = 3;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//    public static String test02() {
 | 
				
			||||||
 | 
					//        try {
 | 
				
			||||||
 | 
					//            if (RETRY_INDEX != MAX_RETRY) {
 | 
				
			||||||
 | 
					//                System.out.println(1 / 0);
 | 
				
			||||||
 | 
					//                log.info("请求失败");
 | 
				
			||||||
 | 
					//            } else {
 | 
				
			||||||
 | 
					//                log.info("请求成功");
 | 
				
			||||||
 | 
					//            }
 | 
				
			||||||
 | 
					//            return "1";
 | 
				
			||||||
 | 
					//        } catch (Exception e) {
 | 
				
			||||||
 | 
					//            log.error(e.getMessage());
 | 
				
			||||||
 | 
					//            RETRY_INDEX++;
 | 
				
			||||||
 | 
					//            log.error("请求微信获取Token错误:{}", e.getMessage());
 | 
				
			||||||
 | 
					//            if (RETRY_INDEX > MAX_RETRY) {
 | 
				
			||||||
 | 
					//                log.error("多次请求后未获取到正确token,抛出异常");
 | 
				
			||||||
 | 
					//                return null;
 | 
				
			||||||
 | 
					//            }
 | 
				
			||||||
 | 
					//            log.error("重试请求第{}次", RETRY_INDEX);
 | 
				
			||||||
 | 
					//            return test02();
 | 
				
			||||||
 | 
					//        }
 | 
				
			||||||
 | 
					//    }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//    public static void main(String[] args) {
 | 
				
			||||||
 | 
					//        String s = test02();
 | 
				
			||||||
 | 
					//        System.out.println(s);
 | 
				
			||||||
 | 
					//    }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//    public static String test03() {
 | 
				
			||||||
 | 
					//        try {
 | 
				
			||||||
 | 
					//            if (RETRY_INDEX != MAX_RETRY) {
 | 
				
			||||||
 | 
					//                System.out.println(1 / 0);
 | 
				
			||||||
 | 
					//                log.info("请求失败");
 | 
				
			||||||
 | 
					//            } else {
 | 
				
			||||||
 | 
					//                log.info("请求成功");
 | 
				
			||||||
 | 
					//            }
 | 
				
			||||||
 | 
					//            return "1";
 | 
				
			||||||
 | 
					//        } catch (Exception e) {
 | 
				
			||||||
 | 
					//            log.error(e.getMessage());
 | 
				
			||||||
 | 
					//            test04();
 | 
				
			||||||
 | 
					//        }
 | 
				
			||||||
 | 
					//        return null;
 | 
				
			||||||
 | 
					//    }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//    public static String test04() {
 | 
				
			||||||
 | 
					//        try {
 | 
				
			||||||
 | 
					//            if (RETRY_INDEX != MAX_RETRY) {
 | 
				
			||||||
 | 
					//                System.out.println(1 / 0);
 | 
				
			||||||
 | 
					//                log.info("请求失败");
 | 
				
			||||||
 | 
					//            } else {
 | 
				
			||||||
 | 
					//                log.info("请求成功");
 | 
				
			||||||
 | 
					//            }
 | 
				
			||||||
 | 
					//            return "1";
 | 
				
			||||||
 | 
					//        } catch (Exception e) {
 | 
				
			||||||
 | 
					//            log.error(e.getMessage());
 | 
				
			||||||
 | 
					//        }
 | 
				
			||||||
 | 
					//        return null;
 | 
				
			||||||
 | 
					//    }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//}
 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue