1 package com.foxinmy.weixin4j.api;
2
3 import java.util.ResourceBundle;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7 import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
8
9
10
11
12
13
14
15
16
17
18
19 public abstract class BaseApi {
20
21 protected final WeixinRequestExecutor weixinExecutor;
22
23 private final Pattern uriPattern = Pattern.compile("(\\{[^\\}]*\\})");
24
25 public BaseApi() {
26 this.weixinExecutor = new WeixinRequestExecutor();
27 }
28
29 protected abstract ResourceBundle weixinBundle();
30
31 protected String getRequestUri(String key) {
32 String url = weixinBundle().getString(key);
33 Matcher m = uriPattern.matcher(url);
34 StringBuffer sb = new StringBuffer();
35 String sub = null;
36 while (m.find()) {
37 sub = m.group();
38 m.appendReplacement(sb,
39 getRequestUri(sub.substring(1, sub.length() - 1)));
40 }
41 m.appendTail(sb);
42 return sb.toString();
43 }
44 }