收藏
回答

mediaCheckAsync接收不到数据?

ResponseData : {"errcode":0,"errmsg":"ok","trace_id":"645afea0-76a6d9aa-3ad43c68"},服务器是配置成功的,配了url,taken,和EncodingAESKey选的是兼容模式,数据格式选的是json 麻烦帮忙查一下这个trace_id的状态

获取trace_id接口

public ObjectResponseModel imgSecCheck2(@RequestBody @Valid ImgSecCheckRequest request) throws Exception {

    String appId =null;
    String secret=null;
    MiniAppParameterEntity miniAppParameterEntity = new MiniAppParameterEntity();
    miniAppParameterEntity.setBrandId(request.getBrandId());
    MiniAppParameterEntity obj =
                miniAppParameterServiceImpl.selectMiniAppParameterByBrandId(miniAppParameterEntity);
    if (Objects.nonNull(obj)) {
         appId = obj.getAppId();
         secret = obj.getSecret();
    }

    ResponseUtils.checkParamNull(appId, "appId");

    ObjectResponseModel response = new ObjectResponseModel();
    WechatConfigEntity entity = new WechatConfigEntity();
    entity.setAppId(appId);
    entity.setSecret(secret);
    entity.setWxType("qrcode_xcx_access_token");
    WechatResponse wechat = getWxToken(entity);
    String accessToken = wechat.getAccess_token();

    HashMap params = new HashMap<>();
    String imgSecCheckUrl = wechatConfig.getImgSecCheck2() + accessToken;
    params.put("media_url", request.getMediaUrl());
    params.put("media_type", 2);
    params.put("version", 2);
    params.put("scene", 1);
    params.put("openid", request.getOpenid());

    logger.info("开始调微信api进行图片安全内容检测:" + DateUtils.getCurrentTime());
    String post = restTemplateUtils.post(imgSecCheckUrl, params, String.class);
    JSONObject jsonObject = JSON.parseObject(post);
    String trace_id = jsonObject.getString("trace_id");
    logger.info("调微信api进行图片安全内容检测结束:" + DateUtils.getCurrentTime() + ",结果为:" + ObjectUtils.objectParseJsonStr(trace_id));
    response.setSingle(trace_id);


    return response;
}


接受腾讯推送数据接口(配置接口)

public String receiveImgSecCheck(HttpServletRequest request) throws Exception {
    logger.info("腾讯回调数据时间:"+System.currentTimeMillis());
    ValueOperations valueOperations = cacheTemplate.getRedisTemplate().opsForValue();
    valueOperations.set(System.currentTimeMillis()+"_"+"receiveImgSecCheckGet",JSON.toJSONString(request));
    boolean isGet = request.getMethod().equalsIgnoreCase("GET");
    if (isGet){
        String signature = request.getParameter("signature");
        String timestamp = request.getParameter("timestamp");
        String nonce = request.getParameter("nonce");
        String echostr = request.getParameter("echostr");
        String[] array = new String[] { token, timestamp, nonce};
        StringBuffer sb = new StringBuffer();
        // 字符串排序
        Arrays.sort(array);
        for (int i = 0; i < 3; i++) {
            sb.append(array[i]);
        }
        String sortStr = sb.toString();
        String sha1Hex = DigestUtils.sha1Hex(sortStr);

        if (signature.equals(sha1Hex)){
            return echostr;
        }else {
            return null;
        }
    }
    BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));
    StringBuilder responseStrBuilder = new StringBuilder();
    String inputStr;
    while ((inputStr = streamReader.readLine()) != null){
        responseStrBuilder.append(inputStr);
    }

    JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
    String param= jsonObject.toJSONString();
    logger.info("转出来的数据:"+param);
    String key  = "Tencent:imgSecCheck:"+jsonObject.getString("trace_id");
    valueOperations.set(key,param,5, TimeUnit.MINUTES);
    return "success";

}


最后一次编辑于  2023-05-10
回答关注问题邀请回答
收藏

2 个回答

  • Diligent
    Diligent
    2023-05-10

    提供get和post代码截图看看

    2023-05-10
    有用
    回复 6
    • Diligent
      Diligent
      2023-05-10回复🍀假装深沉
      这个接口返回图片是否违规是异步的,不是在这个接口里面返回没做过接口里面只返回这次trace_id
      2023-05-10
      回复
    • 🍀假装深沉
      🍀假装深沉
      2023-05-10回复Diligent
      返回trace_id的是另外一个接口,这个用来接收回调数据的
      2023-05-10
      回复
    • Diligent
      Diligent
      2023-05-10回复🍀假装深沉
      这个是接收微信服务器信息的接口吗
      2023-05-10
      回复
    • 🍀假装深沉
      🍀假装深沉
      2023-05-10
      上面那个
      2023-05-10
      回复
    • 🍀假装深沉
      🍀假装深沉
      2023-05-10
      这个是拿trace_id的
      2023-05-10
      回复
    查看更多(1)
  • 🍀假装深沉
    🍀假装深沉
    2023-05-10

    请问这个配置开放post接受模式是指代码层面的,还是说手动配置接口的时候配置的,我现在是代码层面兼容了get和post,是手动配置的时候需要配置其他的吗

    2023-05-10
    有用
    回复
登录 后发表内容