ソースを参照

腾讯地图接口

小么熊🐻 1 年間 前
コミット
b009ca9fa3

+ 16 - 27
nbjk-admin/src/main/java/com/miaxis/app/controller/wx/WxMapController.java

@@ -13,9 +13,7 @@ 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 org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -28,8 +26,8 @@ import java.util.TreeMap;
  * @date 2021-10-20
  */
 @RestController
-@RequestMapping(Constants.STUDENT_PREFIX+"/wxmap")
-@Api(tags={"【APP-地图接口】"})
+@RequestMapping(Constants.STUDENT_PREFIX + "/wxmap")
+@Api(tags = {"【APP-地图接口】"})
 public class WxMapController extends BaseController {
     @Autowired
     private IWxMapService wxMapService;
@@ -40,13 +38,11 @@ public class WxMapController extends BaseController {
     @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) {
+    @ApiOperation("获取考场位置信息")
+    public Response getLocation(@RequestParam(required = true,value = "location") String location) {
         Map<String, Object> params = new HashMap<String, Object>();
-       // String location = "39.984154,116.307490";
+        // String location = "39.984154,116.307490";
         String apiName = "/ws/geocoder/v1?";
 
         params.put("key", txMapConfig.getKey());
@@ -58,14 +54,13 @@ public class WxMapController extends BaseController {
         System.out.println("sign = " + sign);
         System.out.println("sig = " + sig);
 
-        String result = wxMapService.getLocation(txMapConfig.getKey(),location,sig);
-        System.out.println(result);
+        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");
+        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();
@@ -77,15 +72,15 @@ public class WxMapController extends BaseController {
 
             //   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());
+            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,"腾讯地图接口请求错误");
+            Response response = new Response(502, "腾讯地图接口请求错误");
             return response;
         }
     }
@@ -110,11 +105,5 @@ public class WxMapController extends BaseController {
     }
 
 
-
-
-
-
-
-
 }
 

+ 106 - 0
nbjk-admin/src/main/java/com/miaxis/app/controller/wx/WxMenuController.java

@@ -0,0 +1,106 @@
+package com.miaxis.app.controller.wx;
+
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.wx.service.IWxMenuService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author wwl
+ * @version 1.0
+ * @date 2021/11/3 9:18
+ */
+@RestController
+@RequestMapping("/pc/menu")
+@Api(tags={"【H5-微信公众号菜单】"})
+@AllArgsConstructor
+public class WxMenuController extends BaseController {
+
+    private final IWxMenuService wxMenuService;
+
+
+//    /**
+//     * 查询微信公众号菜单列表
+//     */
+//    @PreAuthorize("@ss.hasPermi('menu:info:list')")
+//    @GetMapping("/list")
+//    @ApiOperation("查询微信公众号菜单列表")
+//    public Response<List<WxMenuVo>> list(){
+//        return wxMenuService.selectWxMenuTreeList();
+//    }
+//
+//
+//    /**
+//     * 获取微信公众号菜单详细信息
+//     */
+//    @PreAuthorize("@ss.hasPermi('menu:info:query')")
+//    @GetMapping(value = "/{id}")
+//    @ApiOperation("获取微信公众号菜单详细信息")
+//    public Response<WxMenu> getInfo(
+//            @ApiParam(name = "id", value = "微信公众号菜单参数", required = true)
+//            @PathVariable("id") Long id
+//    ){
+//        return Response.success(wxMenuService.getById(id));
+//    }
+//
+//    /**
+//     * 新增微信公众号菜单
+//     */
+//    @PreAuthorize("@ss.hasPermi('menu:info:add')")
+//    @Log(title = "微信公众号菜单", businessType = BusinessTypeEnum.INSERT)
+//    @PostMapping
+//    @ApiOperation("新增微信公众号菜单")
+//    public Response add(@RequestBody WxMenu wxMenu){
+//        return wxMenuService.saveMenu(wxMenu);
+//    }
+//
+//    /**
+//     * 修改微信公众号菜单
+//     */
+//    @PreAuthorize("@ss.hasPermi('menu:info:edit')")
+//    @Log(title = "微信公众号菜单", businessType = BusinessTypeEnum.UPDATE)
+//    @PutMapping
+//    @ApiOperation("修改微信公众号菜单")
+//    public Response edit(@RequestBody WxMenu wxMenu){
+//        return wxMenuService.updateMenuById(wxMenu);
+//    }
+//
+//    /**
+//     * 删除微信公众号菜单
+//     */
+//    @PreAuthorize("@ss.hasPermi('menu:info:remove')")
+//    @Log(title = "微信公众号菜单", businessType = BusinessTypeEnum.DELETE)
+//    @DeleteMapping("/{ids}")
+//    @ApiOperation("删除微信公众号菜单")
+//    public  Response remove(
+//            @ApiParam(name = "ids", value = "微信公众号菜单ids参数", required = true)
+//            @PathVariable Long[] ids
+//    ){
+//        return wxMenuService.removeMenuByIds(ids);
+//    }
+
+    /**
+     * 一键更新公众号菜单
+     */
+    @GetMapping("/sendMenu")
+    @ApiOperation("一键更新公众号菜单--手动修改数据库操作")
+    public Response sendMenu(){
+        return wxMenuService.sendMenuBySql();
+    }
+
+
+    /**
+     * 获取公众号菜单
+     */
+    @GetMapping("/getMenu")
+    @ApiOperation("获取公众号菜单")
+    public Response getMenu(){
+        return wxMenuService.getMenu();
+    }
+
+}

+ 11 - 0
nbjk-service/src/main/java/com/miaxis/feign/service/IWxSendService.java

@@ -66,6 +66,17 @@ public interface IWxSendService {
     String createMenu(@RequestParam("access_token") String accessToken, JSONObject jsonObject);
 
 
+
+    /**
+     * 创建菜单接口
+     *      -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Querying_Custom_Menus.html
+     * @param accessToken
+     * @return
+     */
+    @GetMapping(value = "/menu/get")
+    @ResponseBody
+    String getMenu(@RequestParam("access_token") String accessToken);
+
     /**
      * 新增永久图文素材
      *      -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html

+ 54 - 0
nbjk-service/src/main/java/com/miaxis/wx/service/IWxMenuService.java

@@ -0,0 +1,54 @@
+package com.miaxis.wx.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.wx.domain.WxMenu;
+import com.miaxis.wx.vo.WxMenuVo;
+
+import java.util.List;
+
+/**
+ * 微信公众号菜单Service接口
+ * @author wwl
+ * @version 1.0
+ * @date 2021/11/3 9:23
+ */
+public interface IWxMenuService extends IService<WxMenu> {
+
+    /**
+     * 查询微信公众号菜单列表
+     *
+     * @return 微信公众号菜单集合
+     */
+    Response<List<WxMenuVo>> selectWxMenuTreeList();
+
+    /**
+     * 新增微信公众号菜单
+     * @param wxMenu
+     * @return
+     */
+    Response saveMenu(WxMenu wxMenu);
+
+
+    /**
+     * 修改微信公众号菜单
+     * @param wxMenu
+     * @return
+     */
+    Response updateMenuById(WxMenu wxMenu);
+
+    /**
+     * 删除微信公众号菜单
+     * @param ids
+     * @return
+     */
+    Response removeMenuByIds(Long[] ids);
+
+    /**
+     * 一键发送数据库菜单
+     * @return
+     */
+    Response sendMenuBySql();
+
+    Response getMenu();
+}

+ 219 - 0
nbjk-service/src/main/java/com/miaxis/wx/service/impl/WxMenuServiceImpl.java

@@ -0,0 +1,219 @@
+package com.miaxis.wx.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.exception.CustomException;
+import com.miaxis.common.sign.VerifyUtil;
+import com.miaxis.feign.service.IWxSendService;
+import com.miaxis.wx.domain.WxMenu;
+import com.miaxis.wx.mapper.WxMenuMapper;
+import com.miaxis.wx.service.IWxGzhService;
+import com.miaxis.wx.service.IWxMenuService;
+import com.miaxis.wx.vo.WxMenuVo;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * 微信公众号菜单Service业务层处理
+ * @author wwl
+ * @version 1.0
+ * @date 2021/11/3 9:24
+ */
+@Service
+@AllArgsConstructor
+@Slf4j
+public class WxMenuServiceImpl extends ServiceImpl<WxMenuMapper, WxMenu> implements IWxMenuService {
+
+    private final WxMenuMapper wxMenuMapper;
+
+    private final IWxGzhService wxGzhService;
+
+    private final IWxSendService wxSendService;
+
+    /**
+     * 查询微信公众号菜单列表
+     *
+     * @return 微信公众号菜单
+     */
+    @Override
+    public Response<List<WxMenuVo>> selectWxMenuTreeList(){
+        List<WxMenuVo> menuList = wxMenuMapper.selectWxMenuList();
+        return Response.success(builTree(menuList));
+    }
+
+    //建立树形结构
+    public List<WxMenuVo> builTree(List<WxMenuVo> menuList){
+        List<WxMenuVo> infoVos =new ArrayList<>();
+        //获取根节点
+        List<WxMenuVo> rootMenuLists =new  ArrayList<>();
+        for(WxMenuVo menuVo : menuList) {
+            if(menuVo.getParentId().toString().equals("0")) {
+                rootMenuLists.add(menuVo);
+            }
+        }
+        for(WxMenuVo wxMenuVo : rootMenuLists) {
+            wxMenuVo=getTree(wxMenuVo,menuList);
+            infoVos.add(wxMenuVo);
+        }
+        return infoVos;
+    }
+    //递归,建立子树形结构
+    private WxMenuVo getTree(WxMenuVo wxMenuVo, List<WxMenuVo> menuList){
+        List<WxMenuVo> infoVos = new ArrayList<>();
+        for (WxMenuVo menuVo : menuList) {
+            if (menuVo.getParentId().toString().equals(wxMenuVo.getId().toString())){
+                infoVos.add(getTree(menuVo,menuList));
+            }
+        }
+        wxMenuVo.setChildren(infoVos);
+        return wxMenuVo;
+    }
+
+
+    /**
+     * 新增微信公众号菜单
+     * @param wxMenu
+     * @return
+     */
+    @Override
+    public Response saveMenu(WxMenu wxMenu) {
+        try {
+            wxMenuMapper.insert(wxMenu);
+            sendMenu();
+            return Response.success();
+        }catch (Exception e){
+            throw new CustomException("系统异常");
+        }
+    }
+
+    /**
+     * 修改微信公众号菜单
+     * @param wxMenu
+     * @return
+     */
+    @Override
+    public Response updateMenuById(WxMenu wxMenu) {
+        try {
+            wxMenuMapper.updateById(wxMenu);
+            sendMenu();
+            return Response.success();
+        }catch (Exception e){
+            throw new CustomException("系统异常");
+        }
+    }
+
+    /**
+     * 删除微信公众号菜单
+     * @param ids
+     * @return
+     */
+    @Override
+    public Response removeMenuByIds(Long[] ids) {
+        try {
+            this.removeByIds(Arrays.asList(ids));
+            sendMenu();
+            return Response.success();
+        }catch (Exception e){
+            throw new CustomException("系统异常");
+        }
+    }
+
+    /**
+     * 一键发送数据库菜单
+     * @return
+     */
+    @Override
+    public Response sendMenuBySql() {
+        sendMenu();
+        return Response.success();
+    }
+
+
+    /**
+     * 获取公众号菜单
+     * @return
+     */
+    @Override
+    public Response getMenu() {
+        String token = wxGzhService.getGzhToken();
+        String result = wxSendService.getMenu(token);
+        return Response.success(result);
+    }
+
+
+    /**
+     * 发送菜单至微信
+     * @return
+     */
+    private String sendMenu(){
+        JSONObject wxMenuJson = getWxMenuJson();
+        String token = wxGzhService.getGzhToken();
+        String result = wxSendService.createMenu(token,wxMenuJson);
+        log.info("-----sendMenu-----"+ result);
+        return result;
+    }
+
+
+    /**
+     * 查询微信菜单数据
+     * @return
+     */
+    private JSONObject getWxMenuJson() {
+
+        JSONObject menuJson = new JSONObject();
+        //获取父类
+        List<WxMenu> menuList = wxMenuMapper.selectByMap(new HashMap<String,Object>(){{
+            put("parent_id",0);
+        }});
+        JSONArray button=new JSONArray();
+        for(WxMenu menu : menuList){
+            if(!VerifyUtil.verifyString(menu.getType())){
+                JSONObject childButton = new JSONObject();
+                childButton.put("name", menu.getMenuName());
+                //父类
+                JSONArray sub_button = new JSONArray();
+                List<WxMenu> childMenuList = wxMenuMapper.selectList(new QueryWrapper<WxMenu>().eq("parent_id", menu.getId()).orderByAsc("sort"));
+
+                for (WxMenu childMenu : childMenuList) {
+                    sub_button.add(getChildMenuJson(childMenu));
+                }
+                childButton.put("sub_button", sub_button);
+                button.add(childButton);
+            }else{
+                button.add(getChildMenuJson(menu));
+            }
+        }
+
+        menuJson.put("button", button);
+        return menuJson;
+    }
+
+
+    private JSONObject getChildMenuJson(WxMenu menu){
+        JSONObject menuJson = new JSONObject();
+        menuJson.put("type", menu.getType());
+        menuJson.put("name", menu.getMenuName());
+        if(menu.getType().equals("view")){
+            menuJson.put("url", menu.getUrl());
+        }else if(menu.getType().equals("click")){
+            menuJson.put("key", menu.getClickKey());
+        }else if(menu.getType().equals("miniprogram")){
+            menuJson.put("url", menu.getUrl());
+            menuJson.put("key", menu.getClickKey());
+            menuJson.put("appid", menu.getAppid());
+            menuJson.put("pagepath", menu.getPagePath());
+        }
+        return menuJson;
+    }
+
+
+}