1111 * Created by Binary Wang on 2016/7/21.
1212 */
1313public class WxMpMenuServiceImpl implements WxMpMenuService {
14+ private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/menu" ;
1415
1516 private WxMpService wxMpService ;
1617
@@ -21,29 +22,29 @@ public WxMpMenuServiceImpl(WxMpService wxMpService) {
2122 @ Override
2223 public void menuCreate (WxMenu menu ) throws WxErrorException {
2324 if (menu .getMatchRule () != null ) {
24- String url = "https://api.weixin.qq.com/cgi-bin/menu /addconditional" ;
25+ String url = API_URL_PREFIX + " /addconditional" ;
2526 this .wxMpService .execute (new SimplePostRequestExecutor (), url , menu .toJson ());
2627 } else {
27- String url = "https://api.weixin.qq.com/cgi-bin/menu /create" ;
28+ String url = API_URL_PREFIX + " /create" ;
2829 this .wxMpService .execute (new SimplePostRequestExecutor (), url , menu .toJson ());
2930 }
3031 }
3132
3233 @ Override
3334 public void menuDelete () throws WxErrorException {
34- String url = "https://api.weixin.qq.com/cgi-bin/menu /delete" ;
35+ String url = API_URL_PREFIX + " /delete" ;
3536 this .wxMpService .execute (new SimpleGetRequestExecutor (), url , null );
3637 }
3738
3839 @ Override
3940 public void menuDelete (String menuid ) throws WxErrorException {
40- String url = "https://api.weixin.qq.com/cgi-bin/menu /delconditional" ;
41+ String url = API_URL_PREFIX + " /delconditional" ;
4142 this .wxMpService .execute (new SimpleGetRequestExecutor (), url , "menuid=" + menuid );
4243 }
4344
4445 @ Override
4546 public WxMenu menuGet () throws WxErrorException {
46- String url = "https://api.weixin.qq.com/cgi-bin/menu /get" ;
47+ String url = API_URL_PREFIX + " /get" ;
4748 try {
4849 String resultContent = this .wxMpService .execute (new SimpleGetRequestExecutor (), url , null );
4950 return WxMenu .fromJson (resultContent );
@@ -58,7 +59,7 @@ public WxMenu menuGet() throws WxErrorException {
5859
5960 @ Override
6061 public WxMenu menuTryMatch (String userid ) throws WxErrorException {
61- String url = "https://api.weixin.qq.com/cgi-bin/menu /trymatch" ;
62+ String url = API_URL_PREFIX + " /trymatch" ;
6263 try {
6364 String resultContent = this .wxMpService .execute (new SimpleGetRequestExecutor (), url , "user_id=" + userid );
6465 return WxMenu .fromJson (resultContent );
0 commit comments