小程序 内容安全 接口调用 一直返回"errcode": 48001是什么原因?
发布于 5 年前 作者 taoguo 14530 次浏览 来自 问答

接口文档地址https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html

一直返回错误

    “errcode”48001

    “errmsg”“api unauthorized hints: [dhLFroXIRa-NYTtUA!]”

服务端 java 调用 post https请求 token新生成的未过期 参数是content和access_token 也是付费的公众号

请问要调用内容安全接口还需要配置什么?

3 回复

找到原因了,accesstoken要用小程序的appid和密钥生成,而不是微信公众号的,另外accesstoken带在参数中,content要以json格式放在post请求的body中

public String test(String test) {
   // 第三方用户唯一凭证
   String appId = miniProgramAppId
   // 第三方用户唯一凭证密钥
   String appSecret = miniProgramSecret

   // 调用接口获取凭证
   Token token = CommonUtil.getTokenminiProgramAppId, miniProgramSecret);
   System.out.println(token.getAccessToken());
   JSONObject jsonObject = new JSONObject();
   jsonObject.put("content", 志愿兵维权);
   String o=""
   try 
      o = okHttpPost("https://api.weixin.qq.com/wxa/msg_sec_check?access_token="+token.getAccessToken(), jsonObject.toString());
   } catch (Exception e) {
      e.printStackTrace();
   }
   return o;

public String okHttpPost(String url, String json){
   OkHttpClient client = new OkHttpClient().newBuilder()
         .build();
   MediaType mediaType = MediaType.parse"application/json");
   okhttp3.RequestBody body = okhttp3.RequestBody.create(json,mediaType);
   Request request = new Request.Builder()
         .url(url)
         .method("POST", body)
         .addHeader("Content-Type", "application/json"
         .build();
   try 
      Response response = client.newCall(request).execute();
      return response.body().string();
   } catch (IOException e) {
      e.printStackTrace();
   }
   return null
}
dependency
    groupIdcom.squareup.okhttp3</groupId
    artifactIdokhttp</artifactId
    version4.2.2</version
</dependency

api未授权

api unauthorized hints 提示你没权限呢

回到顶部