抖音开放平台, 企业号私信订阅服务 java(公开的)

抖音私信的订阅服务,我们需要去抖音开放平台-》管理中心-》webhooks,填入自己的外网地址,服务器必须支持https 服务,例如https://www.xx.com/xx, 后台代码如下:

    @RequestMapping(value = "/dy/message/im", method = RequestMethod.POST)
    @CrossOrigin(origins = "*", maxAge = 3600)
    public String getDyImMessage( HttpServletRequest request ){
        Map dataParams = FormatReqResDataParamsUtils.getRequestParams(request);
        String event = (String) dataParams.get("event");
        if(event.equals("verify_webhook")){
            Map content = (Map) dataParams.get("content");
            return JSON.toJSONString(content);
        }
        return JSON.toJSONString(new HashMap());
    }
    public static Map getRequestParams(HttpServletRequest request) {
        BufferedReader bufferReader;
        try {
            bufferReader = new BufferedReader(request.getReader());
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = bufferReader.readLine()) != null) {
                sb.append(line);
            }
            String decodeUrl = URLDecoder.decode(sb.toString(), "UTF-8");
            Map addReptitleData =  new Gson().fromJson(decodeUrl, Map.class);
            if (addReptitleData.containsKey("data")) {
                String allDataParams = URLDecoder.decode((String) addReptitleData.get("data"), "UTF-8");
                Map params = new Gson().fromJson(allDataParams, Map.class);
                return params;
            }
            return addReptitleData;
        }catch(Exception e) {
            return new HashMap();
        }
    }

 

你可能感兴趣的:(java,java,spring,boot)