webservice.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getRequest = exports.infocode = exports.services = undefined;
  6. var _forOwn = require('lodash/forOwn');
  7. var _forOwn2 = babelHelpers.interopRequireDefault(_forOwn);
  8. var _isEqual = require('lodash/isEqual');
  9. var _isEqual2 = babelHelpers.interopRequireDefault(_isEqual);
  10. var _isNil = require('lodash/isNil');
  11. var _isNil2 = babelHelpers.interopRequireDefault(_isNil);
  12. var _isUndefined = require('lodash/isUndefined');
  13. var _isUndefined2 = babelHelpers.interopRequireDefault(_isUndefined);
  14. // M: Mandatory,必选
  15. // api调用限流说明: https://lbs.amap.com/api/webservice/guide/tools/flowlevel
  16. var services = exports.services = {
  17. // 地理/逆地理编码: https://lbs.amap.com/api/webservice/guide/api/georegeo
  18. geocode_geo: {
  19. name: '地理编码',
  20. method: 'GET',
  21. url: 'https://restapi.amap.com/v3/geocode/geo',
  22. parameters: {
  23. key: undefined, // M
  24. address: undefined, // M
  25. city: undefined, // M
  26. batch: false,
  27. sig: undefined,
  28. output: 'JSON',
  29. callback: null
  30. }
  31. },
  32. geocode_regeo: {
  33. name: '逆地理编码',
  34. method: 'GET',
  35. url: 'https://restapi.amap.com/v3/geocode/regeo',
  36. parameters: {
  37. key: undefined, // M
  38. location: undefined, // M
  39. poitype: undefined,
  40. radius: 1000,
  41. extensions: 'base',
  42. batch: false,
  43. roadlevel: undefined,
  44. sig: undefined,
  45. output: 'JSON',
  46. callback: null,
  47. homeorcorp: 0
  48. }
  49. },
  50. // 路径规划: https://lbs.amap.com/api/webservice/guide/api/direction
  51. direction_walking: {
  52. name: '步行路径规划',
  53. method: 'GET',
  54. url: 'https://restapi.amap.com/v3/direction/walking',
  55. parameters: {
  56. key: undefined, // M
  57. origin: undefined, // M
  58. destination: undefined, // M
  59. sig: undefined,
  60. output: 'JSON',
  61. callback: null
  62. }
  63. },
  64. direction_transit_integrated: {
  65. name: '公交路径规划',
  66. method: 'GET',
  67. url: 'https://restapi.amap.com/v3/direction/transit/integrated',
  68. parameters: {
  69. key: undefined // M
  70. }
  71. },
  72. direction_driving: {
  73. name: '驾车路径规划',
  74. method: 'GET',
  75. url: 'https://restapi.amap.com/v3/direction/driving',
  76. parameters: {
  77. key: undefined // M
  78. }
  79. },
  80. direction_bicycling: {
  81. name: '骑行路径规划',
  82. method: 'GET',
  83. url: 'https://restapi.amap.com/v4/direction/bicycling',
  84. parameters: {
  85. key: undefined // M
  86. }
  87. },
  88. direction_truck: {
  89. name: '货车路径规划',
  90. method: 'GET',
  91. url: 'https://restapi.amap.com/v4/direction/truck',
  92. parameters: {
  93. key: undefined // M
  94. }
  95. },
  96. distance: {
  97. name: '距离测量',
  98. method: 'GET',
  99. url: 'https://restapi.amap.com/v3/distance',
  100. parameters: {
  101. key: undefined // M
  102. }
  103. },
  104. // 行政区域查询: https://lbs.amap.com/api/webservice/guide/api/district
  105. config_district: {
  106. name: '行政区域查询',
  107. method: 'GET',
  108. url: 'https://restapi.amap.com/v3/config/district',
  109. parameters: {
  110. key: undefined // M
  111. }
  112. },
  113. // 搜索POI: https://lbs.amap.com/api/webservice/guide/api/search
  114. place_text: {
  115. name: '关键字搜索',
  116. method: 'GET',
  117. url: 'https://restapi.amap.com/v3/place/text',
  118. parameters: {
  119. key: undefined // M
  120. }
  121. },
  122. place_around: {
  123. name: '周边搜索',
  124. method: 'GET',
  125. url: 'https://restapi.amap.com/v3/place/around',
  126. parameters: {
  127. key: undefined // M
  128. }
  129. },
  130. place_polygon: {
  131. name: '多边形搜索',
  132. method: 'GET',
  133. url: 'https://restapi.amap.com/v3/place/polygon',
  134. parameters: {
  135. key: undefined // M
  136. }
  137. },
  138. place_detail: {
  139. name: 'ID查询',
  140. method: 'GET',
  141. url: 'https://restapi.amap.com/v3/place/detail',
  142. parameters: {
  143. key: undefined // M
  144. }
  145. },
  146. // IP定位: https://lbs.amap.com/api/webservice/guide/api/ipconfig
  147. ip: {
  148. name: 'IP定位',
  149. method: 'GET',
  150. url: 'https://restapi.amap.com/v3/ip',
  151. parameters: {
  152. key: undefined // M
  153. }
  154. },
  155. // 抓路服务: https://lbs.amap.com/api/webservice/guide/api/autograsp
  156. autograsp: {
  157. name: '抓路服务',
  158. method: 'GET',
  159. url: 'https://restapi.amap.com/v3/autograsp',
  160. parameters: {
  161. key: undefined // M
  162. }
  163. },
  164. // 批量请求接口: https://lbs.amap.com/api/webservice/guide/api/batchrequest
  165. batch: {
  166. name: '批量请求接口',
  167. method: 'POST',
  168. url: 'https://restapi.amap.com/v3/batch',
  169. parameters: {
  170. key: undefined // M
  171. },
  172. body: {
  173. "ops": [{
  174. "url": "/v3/place/around?offset=10&page=1&key=<您的key>&location=116.50394379585519,39.278209477408794&output=json&radius=100000&types=080000"
  175. }, {
  176. "url": "/v3/place/around?offset=10&page=1&key=<您的key>&location=118.50394379585519,39.278209477408794&output=json&radius=100000&types=080000"
  177. }]
  178. }
  179. },
  180. // 静态地图: https://lbs.amap.com/api/webservice/guide/api/staticmaps
  181. staticmap: {
  182. name: '静态地图',
  183. method: 'GET',
  184. url: 'https://restapi.amap.com/v3/staticmap',
  185. parameters: {
  186. key: undefined // M
  187. }
  188. },
  189. // 坐标转换: https://lbs.amap.com/api/webservice/guide/api/convert
  190. assistant_coordinate_convert: {
  191. name: '坐标转换',
  192. method: 'GET',
  193. url: 'https://restapi.amap.com/v3/assistant/coordinate/convert',
  194. parameters: {
  195. key: undefined // M
  196. }
  197. },
  198. // 天气查询: https://lbs.amap.com/api/webservice/guide/api/weatherinfo
  199. weather_weatherInfo: {
  200. name: '天气查询',
  201. method: 'GET',
  202. url: 'https://restapi.amap.com/v3/weather/weatherInfo',
  203. parameters: {
  204. key: undefined // M
  205. }
  206. },
  207. // 输入提示: https://lbs.amap.com/api/webservice/guide/api/inputtips
  208. assistant_inputtips: {
  209. name: '输入提示',
  210. method: 'GET',
  211. url: 'https://restapi.amap.com/v3/assistant/inputtips',
  212. parameters: {
  213. key: undefined // M
  214. }
  215. },
  216. // 交通态势: https://lbs.amap.com/api/webservice/guide/api/trafficstatus
  217. traffic_status_rectangle: {
  218. name: '矩形区域交通态势',
  219. method: 'GET',
  220. url: 'https://restapi.amap.com/v3/traffic/status/rectangle',
  221. parameters: {
  222. key: undefined // M
  223. }
  224. },
  225. traffic_status_circle: {
  226. name: '圆形区域交通态势',
  227. method: 'GET',
  228. url: 'https://restapi.amap.com/v3/traffic/status/circle',
  229. parameters: {
  230. key: undefined // M
  231. }
  232. },
  233. traffic_status_road: {
  234. name: '指定线路交通态势',
  235. method: 'GET',
  236. url: 'https://restapi.amap.com/v3/traffic/status/road',
  237. parameters: {
  238. key: undefined // M
  239. }
  240. },
  241. // 地理围栏: https://lbs.amap.com/api/webservice/guide/api/geofence_service
  242. geofence_meta_post: {
  243. name: '创建围栏',
  244. method: 'POST',
  245. url: 'https://restapi.amap.com/v4/geofence/meta',
  246. parameters: {
  247. key: undefined // M
  248. },
  249. body: {
  250. name: undefined //M
  251. }
  252. },
  253. geofence_meta_get: {
  254. name: '查询围栏',
  255. method: 'GET',
  256. url: 'https://restapi.amap.com/v4/geofence/meta',
  257. parameters: {
  258. key: undefined // M
  259. }
  260. },
  261. geofence_meta_patch: {
  262. name: '更新围栏',
  263. method: 'POST ', // PATCH
  264. url: 'https://restapi.amap.com/v4/geofence/meta',
  265. parameters: {
  266. key: undefined, // M
  267. gid: undefined, // M
  268. method: undefined // 'patch'
  269. },
  270. body: {
  271. name: undefined //M
  272. }
  273. },
  274. geofence_meta_patch2: {
  275. name: '围栏启动&停止',
  276. method: 'POST ', // PATCH
  277. url: 'https://restapi.amap.com/v4/geofence/meta',
  278. parameters: {
  279. key: undefined, // M
  280. gid: undefined, //M
  281. method: undefined //'patch'
  282. },
  283. body: {
  284. name: undefined //M
  285. }
  286. },
  287. geofence_meta_delete: {
  288. name: '删除围栏',
  289. method: 'DELETE ', // POST
  290. url: 'https://restapi.amap.com/v4/geofence/meta',
  291. parameters: {
  292. key: undefined, // M
  293. gid: undefined, //M
  294. method: undefined //'delete'
  295. },
  296. body: {
  297. name: undefined //M
  298. }
  299. },
  300. geofence_status: {
  301. name: '围栏设备监控',
  302. method: 'GET',
  303. url: 'https://restapi.amap.com/v4/geofence/status',
  304. parameters: {
  305. key: undefined, // M
  306. diu: undefined, // M
  307. uid: undefined,
  308. locations: undefined, // M
  309. sig: undefined
  310. }
  311. },
  312. // 轨迹纠偏: https://lbs.amap.com/api/webservice/guide/api/grasproad
  313. grasproad_driving: {
  314. name: '轨迹纠偏',
  315. method: 'POST',
  316. url: 'https://restapi.amap.com/v4/grasproad/driving',
  317. parameters: {
  318. key: undefined // M
  319. },
  320. body: {
  321. x: undefined, // M
  322. y: undefined, // M
  323. ag: undefined, // M
  324. tm: undefined, // M
  325. sp: undefined // M
  326. }
  327. }
  328. };
  329. var infocode = exports.infocode = {
  330. "10000": {
  331. info: 'OK',
  332. desc: '请求正常',
  333. suggest: '请求正常'
  334. },
  335. "10001": {
  336. info: 'INVALID_USER_KEY',
  337. desc: 'key不正确或过期',
  338. suggest: '开发者发起请求时,传入的key不正确或者过期 '
  339. },
  340. "10002": {
  341. info: 'SERVICE_NOT_AVAILABLE',
  342. desc: '没有权限使用相应的服务或者请求接口的路径拼写错误',
  343. suggest: '1.开发者没有权限使用相应的服务,例如:开发者申请了WEB定位功能的key,却使用该key访问逆地理编码功能时,就会返回该错误。反之亦然。2.开发者请求接口的路径拼写错误。例如:正确的https://restapi.amap.com/v3/ip在程序中被拼装写了https://restapi.amap.com/vv3/ip"'
  344. }
  345. };
  346. var getRequest = exports.getRequest = function getRequest(service, parameters, body) {
  347. if (!service) return null;
  348. var option = {};
  349. var name = service.name,
  350. url = service.url,
  351. method = service.method,
  352. dfParameters = service.parameters,
  353. dfBody = service.body;
  354. var destParameters = babelHelpers.extends({}, dfParameters || {}, parameters || {});
  355. // 组建url中参数
  356. var paramArr = [];
  357. (0, _forOwn2.default)(destParameters, function (value, key) {
  358. if (!(0, _isNil2.default)(value)) {
  359. paramArr.push(key + '=' + value);
  360. }
  361. });
  362. if (paramArr.length > 0) {
  363. url += '?' + paramArr.join('&');
  364. }
  365. // 组建option
  366. if (method === 'GET') {
  367. option = {
  368. credentials: 'include',
  369. method: method,
  370. headers: { 'Content-Type': 'application/json' }
  371. };
  372. } else if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
  373. var destBody = babelHelpers.extends({}, dfBody || {}, body || {});
  374. option = {
  375. credentials: 'include',
  376. method: method,
  377. headers: { 'Content-Type': 'application/json' },
  378. body: destBody
  379. };
  380. } else {
  381. console.log('error! not support method=' + method + ' of ' + name);
  382. }
  383. return {
  384. url: url,
  385. option: option
  386. };
  387. };