mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-30 18:19:04 +08:00 
			
		
		
		
	添加删除模板的接口方法实现 for issue #63
This commit is contained in:
		| @ -1,12 +1,12 @@ | ||||
| package me.chanjar.weixin.mp.api; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplate; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * <pre> | ||||
|  * 模板消息接口 | ||||
| @ -72,4 +72,16 @@ public interface WxMpTemplateMsgService { | ||||
|    * @return templateId 模板Id | ||||
|    */ | ||||
|   List<WxMpTemplate> getAllPrivateTemplate() throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 删除模板 | ||||
|    * 删除模板可在MP中完成,为方便第三方开发者,提供通过接口调用的方式来删除某帐号下的模板 | ||||
|    * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN | ||||
|    * 接口地址格式:https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=ACCESS_TOKEN | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param templateId 模板Id | ||||
|    */ | ||||
|   boolean delPrivateTemplate(String templateId) throws WxErrorException; | ||||
| } | ||||
|  | ||||
| @ -1,10 +1,7 @@ | ||||
| package me.chanjar.weixin.mp.api.impl; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | ||||
|  | ||||
| import me.chanjar.weixin.common.bean.result.WxError; | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | ||||
| @ -13,6 +10,8 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplate; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * <pre> | ||||
|  * Created by Binary Wang on 2016-10-14. | ||||
| @ -79,4 +78,18 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { | ||||
|     return WxMpTemplate.fromJson(this.wxMpService.get(url, null)); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public boolean delPrivateTemplate(String templateId) throws WxErrorException { | ||||
|     String url = API_URL_PREFIX + "/del_private_template"; | ||||
|     JsonObject jsonObject = new JsonObject(); | ||||
|     jsonObject.addProperty("template_id", templateId); | ||||
|     String responseContent = this.wxMpService.post(url, jsonObject.toString()); | ||||
|     WxError error = WxError.fromJson(responseContent); | ||||
|     if (error.getErrorCode() == 0) { | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
|     throw new WxErrorException(error); | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -1,15 +1,6 @@ | ||||
| package me.chanjar.weixin.mp.api.impl; | ||||
|  | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| import org.testng.Assert; | ||||
| import org.testng.annotations.Guice; | ||||
| import org.testng.annotations.Test; | ||||
|  | ||||
| import com.google.inject.Inject; | ||||
|  | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.ApiTestModule; | ||||
| import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; | ||||
| @ -17,6 +8,13 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplate; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | ||||
| import org.testng.Assert; | ||||
| import org.testng.annotations.Guice; | ||||
| import org.testng.annotations.Test; | ||||
|  | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * <pre> | ||||
| @ -74,4 +72,11 @@ public class WxMpTemplateMsgServiceImplTest { | ||||
|     System.err.println(result); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testDelPrivateTemplate() throws Exception { | ||||
|     String templateId = "RPcTe7-4BkU5A2J3imC6W0b4JbjEERcJg0whOMKJKIc"; | ||||
|     boolean result = this.wxService.getTemplateMsgService().delPrivateTemplate(templateId); | ||||
|     Assert.assertTrue(result); | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang