1 package com.foxinmy.weixin4j.mp.model;
2
3 import java.io.Serializable;
4
5 import com.alibaba.fastjson.JSONObject;
6 import com.foxinmy.weixin4j.mp.type.SemCategory;
7
8
9
10
11
12
13
14
15
16
17 public class SemQuery implements Serializable {
18
19 private static final long serialVersionUID = 679548284525912436L;
20 private JSONObject jsonObj;
21
22
23
24
25
26
27 public SemQuery(String query) {
28 jsonObj = new JSONObject();
29 jsonObj.put("query", query);
30 }
31
32
33
34
35
36
37
38 public SemQuery city(String city) {
39 jsonObj.put("city", city);
40 return this;
41 }
42
43
44
45
46
47
48
49 public SemQuery category(SemCategory... categorys) {
50 StringBuilder category = new StringBuilder();
51 if (categorys.length == 1) {
52 category.append(categorys[0].name());
53 } else {
54 for (int i = 0; i < categorys.length - 1; i++) {
55 category.append(categorys[i].name()).append(",");
56 }
57 category.append(categorys[categorys.length - 1].name());
58 }
59 jsonObj.put("category", category.toString());
60 return this;
61 }
62
63
64
65
66
67
68
69 public SemQuery appid(String appid) {
70 jsonObj.put("appid", appid);
71 return this;
72 }
73
74
75
76
77
78
79
80
81 public SemQuery uid(String uid) {
82 jsonObj.put("uid", uid);
83 return this;
84 }
85
86
87
88
89
90
91
92 public SemQuery region(String region) {
93 jsonObj.put("region", region);
94 return this;
95 }
96
97
98
99
100
101
102
103
104 public SemQuery location(float latitude, float longitude) {
105 jsonObj.put("latitude", latitude);
106 jsonObj.put("longitude", longitude);
107 return this;
108 }
109
110
111
112
113
114
115
116 public static SemQuery build(String query) {
117 return new SemQuery(query);
118 }
119
120 public String toJson() {
121 return jsonObj.toJSONString();
122 }
123
124 @Override
125 public String toString() {
126 return "SemQuery " + jsonObj;
127 }
128 }