Skip to content

Commit 28ea144

Browse files
committed
support semantic api
1 parent 9e2705f commit 28ea144

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

lib/api_semantic.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
var urllib = require('urllib');
2+
var util = require('./util');
3+
var wrapper = util.wrapper;
4+
var postJSON = util.postJSON;
5+
6+
/**
7+
* 发送语义理解请求
8+
* 详细请看:http://mp.weixin.qq.com/wiki/index.php?title=%E8%AF%AD%E4%B9%89%E7%90%86%E8%A7%A3
9+
*
10+
* Opts:
11+
* ```
12+
* {
13+
* "query":"查一下明天从北京到上海的南航机票",
14+
* "city":"北京",
15+
* "category": "flight,hotel",
16+
* "appid":"wxaaaaaaaaaaaaaaaa",
17+
* "uid":"123456"
18+
* }
19+
* ```
20+
* Examples:
21+
* ```
22+
* api.semantic(opts, callback);
23+
* ```
24+
* Callback:
25+
*
26+
* - `err`, 调用失败时得到的异常
27+
* - `result`, 调用正常时得到的对象
28+
*
29+
* Result:
30+
* ```
31+
* {
32+
* "errcode":0,
33+
* "query":"查一下明天从北京到上海的南航机票",
34+
* "type":"flight",
35+
* "semantic":{
36+
* "details":{
37+
* "start_loc":{
38+
* "type":"LOC_CITY",
39+
* "city":"北京市",
40+
* "city_simple":"北京",
41+
* "loc_ori":"北京"
42+
* },
43+
* "end_loc": {
44+
* "type":"LOC_CITY",
45+
* "city":"上海市",
46+
* "city_simple":"上海",
47+
* "loc_ori":"上海"
48+
* },
49+
* "start_date": {
50+
* "type":"DT_ORI",
51+
* "date":"2014-03-05",
52+
* "date_ori":"明天"
53+
* },
54+
* "airline":"中国南方航空公司"
55+
* },
56+
* "intent":"SEARCH"
57+
* }
58+
* ```
59+
* @param {Object} opts 查询条件
60+
* @param {Function} callback 回调函数
61+
*/
62+
exports.semantic = function (opts, callback) {
63+
this.preRequest(this._semantic, arguments);
64+
};
65+
66+
/*!
67+
* 发送语义理解请求的未封装版本
68+
*/
69+
exports._semantic = function (opts, callback) {
70+
// https://api.weixin.qq.com/semantic/semproxy/search?access_token=YOUR_ACCESS_TOKEN
71+
var url = this.prefix + 'semantic/semproxy/search?access_token=' + this.token.accessToken;
72+
urllib.request(url, postJSON(opts), wrapper(callback));
73+
};

0 commit comments

Comments
 (0)