|
@@ -0,0 +1,120 @@
|
|
|
+package com.miaxis.app.controller.wx;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.miaxis.common.config.TxMapConfig;
|
|
|
+import com.miaxis.common.constant.Constants;
|
|
|
+import com.miaxis.common.core.controller.BaseController;
|
|
|
+import com.miaxis.common.core.domain.Response;
|
|
|
+import com.miaxis.common.sms.MD5Utils;
|
|
|
+import com.miaxis.dict.domain.DictCity;
|
|
|
+import com.miaxis.dict.service.IDictCityService;
|
|
|
+import com.miaxis.feign.service.IWxMapService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 【APP-地图接口】Controller
|
|
|
+ *
|
|
|
+ * @author miaxis
|
|
|
+ * @date 2021-10-20
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping(Constants.STUDENT_PREFIX+"/wxmap")
|
|
|
+@Api(tags={"【APP-地图接口】"})
|
|
|
+public class WxMapController extends BaseController {
|
|
|
+ @Autowired
|
|
|
+ private IWxMapService wxMapService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDictCityService dictCityService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TxMapConfig txMapConfig;
|
|
|
+
|
|
|
+ //经纬度(GCJ02坐标系),格式:
|
|
|
+ //location=lat<纬度>,lng<经度>
|
|
|
+ @GetMapping(value = "/getLocation")
|
|
|
+ @ApiOperation("获取题库详细信息")
|
|
|
+ public Response getLocation(@ApiParam(value = "格式为 lat<纬度>,lng<经度>。例如:39.984154,116.307490")String location) {
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ // String location = "39.984154,116.307490";
|
|
|
+ String apiName = "/ws/geocoder/v1?";
|
|
|
+
|
|
|
+ params.put("key", txMapConfig.getKey());
|
|
|
+ params.put("location", location);
|
|
|
+
|
|
|
+ String sign = this.getSign(params, txMapConfig.getSecret(), apiName);
|
|
|
+ String sig = MD5Utils.MD5Encode(sign);
|
|
|
+
|
|
|
+ System.out.println("sign = " + sign);
|
|
|
+ System.out.println("sig = " + sig);
|
|
|
+
|
|
|
+ String result = wxMapService.getLocation(txMapConfig.getKey(),location,sig);
|
|
|
+ System.out.println(result);
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ String status = json.get("status").toString();
|
|
|
+ System.out.println("status = " + status);
|
|
|
+
|
|
|
+ if(status.equals("0")) { //调用成功
|
|
|
+ JSONObject resultNode = (JSONObject)json.get("result");
|
|
|
+ JSONObject addressComponent = (JSONObject) resultNode.get("address_component");
|
|
|
+ String province = addressComponent.get("province").toString();
|
|
|
+ String city = addressComponent.get("city").toString();
|
|
|
+ System.out.println("province = " + province);
|
|
|
+ System.out.println("city = " + city);
|
|
|
+ DictCity dictCity = dictCityService.getDictCityByName(city);
|
|
|
+ System.out.println("parentCcode = " + dictCity.getParentcode());
|
|
|
+ System.out.println("code = " + dictCity.getCode());
|
|
|
+
|
|
|
+ // List<Map<String,Object>> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<String,Object>();
|
|
|
+ map.put("province",province);
|
|
|
+ map.put("city",city);
|
|
|
+ map.put("provinceCode",dictCity.getParentcode());
|
|
|
+ map.put("cityCode",dictCity.getCode());
|
|
|
+ System.out.println(map);
|
|
|
+ return Response.success(map);
|
|
|
+ } else {
|
|
|
+ Response response = new Response(200,"腾讯地图接口请求错误");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static String getSign(Map<String, Object> params, String secret, String apiName) {
|
|
|
+ Map<String, Object> sortMap = new TreeMap<String, Object>();
|
|
|
+ sortMap.putAll(params);
|
|
|
+ // 以k1=v1&k2=v2...方式拼接参数
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ for (Map.Entry<String, Object> s : sortMap.entrySet()) {
|
|
|
+ String k = s.getKey();
|
|
|
+ Object v = s.getValue();
|
|
|
+ builder.append(k).append("=").append(v).append("&");
|
|
|
+ }
|
|
|
+ if (!sortMap.isEmpty()) {
|
|
|
+ builder.deleteCharAt(builder.length() - 1);
|
|
|
+ }
|
|
|
+ builder.append(secret);
|
|
|
+ builder.insert(0, apiName);
|
|
|
+ return builder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|