Skip to content

Commit a44c18a

Browse files
committed
issue binarywang#28 添加语义理解接口
1 parent 415ea95 commit a44c18a

4 files changed

Lines changed: 216 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package me.chanjar.weixin.mp.bean;
2+
3+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
4+
5+
/**
6+
* 语义理解查询用对象
7+
*
8+
* http://mp.weixin.qq.com/wiki/index.php?title=语义理解
9+
*
10+
* @author Daniel Qian
11+
*/
12+
public class WxMpSemanticQuery {
13+
14+
private String query;
15+
private String category;
16+
private Float latitude;
17+
private Float longitude;
18+
private String city;
19+
private String region;
20+
private String appid;
21+
private String uid;
22+
23+
public String getQuery() {
24+
return query;
25+
}
26+
27+
public void setQuery(String query) {
28+
this.query = query;
29+
}
30+
31+
public String getCategory() {
32+
return category;
33+
}
34+
35+
public void setCategory(String category) {
36+
this.category = category;
37+
}
38+
39+
public Float getLatitude() {
40+
return latitude;
41+
}
42+
43+
public void setLatitude(Float latitude) {
44+
this.latitude = latitude;
45+
}
46+
47+
public Float getLongitude() {
48+
return longitude;
49+
}
50+
51+
public void setLongitude(Float longitude) {
52+
this.longitude = longitude;
53+
}
54+
55+
public String getCity() {
56+
return city;
57+
}
58+
59+
public void setCity(String city) {
60+
this.city = city;
61+
}
62+
63+
public String getRegion() {
64+
return region;
65+
}
66+
67+
public void setRegion(String region) {
68+
this.region = region;
69+
}
70+
71+
public String getAppid() {
72+
return appid;
73+
}
74+
75+
public void setAppid(String appid) {
76+
this.appid = appid;
77+
}
78+
79+
public String getUid() {
80+
return uid;
81+
}
82+
83+
public void setUid(String uid) {
84+
this.uid = uid;
85+
}
86+
87+
public String toJson() {
88+
return WxMpGsonBuilder.create().toJson(this);
89+
}
90+
91+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package me.chanjar.weixin.mp.bean.result;
2+
3+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
4+
5+
/**
6+
* 语义理解查询结果对象
7+
*
8+
* http://mp.weixin.qq.com/wiki/index.php?title=语义理解
9+
*
10+
* @author Daniel Qian
11+
*/
12+
public class WxMpSemanticQueryResult {
13+
14+
private String query;
15+
private String type;
16+
private String semantic;
17+
private String result;
18+
private String answer;
19+
private String text;
20+
21+
public String getQuery() {
22+
return query;
23+
}
24+
25+
public void setQuery(String query) {
26+
this.query = query;
27+
}
28+
29+
public String getType() {
30+
return type;
31+
}
32+
33+
public void setType(String type) {
34+
this.type = type;
35+
}
36+
37+
public String getSemantic() {
38+
return semantic;
39+
}
40+
41+
public void setSemantic(String semantic) {
42+
this.semantic = semantic;
43+
}
44+
45+
public String getResult() {
46+
return result;
47+
}
48+
49+
public void setResult(String result) {
50+
this.result = result;
51+
}
52+
53+
public String getAnswer() {
54+
return answer;
55+
}
56+
57+
public void setAnswer(String answer) {
58+
this.answer = answer;
59+
}
60+
61+
public String getText() {
62+
return text;
63+
}
64+
65+
public void setText(String text) {
66+
this.text = text;
67+
}
68+
69+
public static WxMpSemanticQueryResult fromJson(String json) {
70+
return WxMpGsonBuilder.create().fromJson(json, WxMpSemanticQueryResult.class);
71+
}
72+
73+
}

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class WxMpGsonBuilder {
2323
INSTANCE.registerTypeAdapter(WxMpMassUploadResult.class, new WxMpMassUploadResultAdapter());
2424
INSTANCE.registerTypeAdapter(WxMpQrCodeTicket.class, new WxQrCodeTicketAdapter());
2525
INSTANCE.registerTypeAdapter(WxMpTemplateMessage.class, new WxMpTemplateMessageGsonAdapter());
26+
INSTANCE.registerTypeAdapter(WxMpSemanticQueryResult.class, new WxMpSemanticQueryResultAdapter());
2627
}
2728

2829
public static Gson create() {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
3+
*
4+
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
5+
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
6+
* arose from modification of the original source, or other redistribution of this source
7+
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
8+
*/
9+
package me.chanjar.weixin.mp.util.json;
10+
11+
import com.google.gson.*;
12+
import me.chanjar.weixin.common.util.json.GsonHelper;
13+
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
14+
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
15+
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
16+
17+
import java.lang.reflect.Type;
18+
19+
/**
20+
*
21+
* @author Daniel Qian
22+
*
23+
*/
24+
public class WxMpSemanticQueryResultAdapter implements JsonDeserializer<WxMpSemanticQueryResult> {
25+
26+
public WxMpSemanticQueryResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
27+
WxMpSemanticQueryResult result = new WxMpSemanticQueryResult();
28+
JsonObject resultJsonObject = json.getAsJsonObject();
29+
30+
if (GsonHelper.getString(resultJsonObject, "query") != null) {
31+
result.setQuery(GsonHelper.getString(resultJsonObject, "query"));
32+
}
33+
if (GsonHelper.getString(resultJsonObject, "type") != null) {
34+
result.setType(GsonHelper.getString(resultJsonObject, "type"));
35+
}
36+
if (resultJsonObject.get("semantic") != null) {
37+
result.setSemantic(resultJsonObject.get("semantic").toString());
38+
}
39+
if (resultJsonObject.get("result") != null) {
40+
result.setResult(resultJsonObject.get("result").toString());
41+
}
42+
if (GsonHelper.getString(resultJsonObject, "answer") != null) {
43+
result.setAnswer(GsonHelper.getString(resultJsonObject, "answer"));
44+
}
45+
if (GsonHelper.getString(resultJsonObject, "text") != null) {
46+
result.setText(GsonHelper.getString(resultJsonObject, "text"));
47+
}
48+
return result;
49+
}
50+
51+
}

0 commit comments

Comments
 (0)