mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 18:46:10 +08:00 
			
		
		
		
	创建菜单时添加日志记录功能
This commit is contained in:
		| @ -1,5 +1,8 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||||
|  |  | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.menu.WxMenu; | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | ||||||
| @ -12,6 +15,7 @@ import me.chanjar.weixin.mp.api.WxMpService; | |||||||
|  */ |  */ | ||||||
| public class WxMpMenuServiceImpl implements WxMpMenuService { | public class WxMpMenuServiceImpl implements WxMpMenuService { | ||||||
|   private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/menu"; |   private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/menu"; | ||||||
|  |   private static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class); | ||||||
|  |  | ||||||
|   private WxMpService wxMpService; |   private WxMpService wxMpService; | ||||||
|  |  | ||||||
| @ -21,25 +25,38 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { | |||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public void menuCreate(WxMenu menu) throws WxErrorException { |   public void menuCreate(WxMenu menu) throws WxErrorException { | ||||||
|     if (menu.getMatchRule() != null) { | 	String menuJson  = menu.toJson(); | ||||||
|       String url = API_URL_PREFIX + "/addconditional"; |  | ||||||
|       this.wxMpService.execute(new SimplePostRequestExecutor(), url, menu.toJson()); |  | ||||||
|     } else { |  | ||||||
| 	String url  =   API_URL_PREFIX + "/create"; | 	String url  =   API_URL_PREFIX + "/create"; | ||||||
|       this.wxMpService.execute(new SimplePostRequestExecutor(), url, menu.toJson()); |     if (menu.getMatchRule() != null) { | ||||||
|  |       url = API_URL_PREFIX + "/addconditional"; | ||||||
|  |     }  | ||||||
|  |     if(log.isTraceEnabled()){ | ||||||
|  |       log.trace("开始创建菜单:{}", menuJson); | ||||||
|  |     } | ||||||
|  |        | ||||||
|  |     String result = this.wxMpService.execute(new SimplePostRequestExecutor(), url,menuJson); | ||||||
|  |      | ||||||
|  |     if(log.isDebugEnabled()){ | ||||||
|  |       log.debug("创建菜单:{},结果:{}", menuJson, result); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public void menuDelete() throws WxErrorException { |   public void menuDelete() throws WxErrorException { | ||||||
|     String url = API_URL_PREFIX + "/delete"; |     String url = API_URL_PREFIX + "/delete"; | ||||||
|     this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); |     String result  = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); | ||||||
|  |     if(log.isDebugEnabled()){ | ||||||
|  |       log.debug("删除菜单结果:{}", result); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public void menuDelete(String menuid) throws WxErrorException { |   public void menuDelete(String menuid) throws WxErrorException { | ||||||
|     String url = API_URL_PREFIX + "/delconditional"; |     String url = API_URL_PREFIX + "/delconditional"; | ||||||
|     this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "menuid=" + menuid); |     String result  = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "menuid=" + menuid); | ||||||
|  |     if(log.isDebugEnabled()){ | ||||||
|  |       log.debug("根据MeunId({})删除菜单结果:{}", menuid,result); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 aimil
					aimil