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