Detect Sensitive Text in WeChat Mini Programs Using the Content Security API

The article explains how to leverage WeChat Mini Program's text security API to automatically filter sensitive, political, pornographic, gambling, and drug-related content in user-generated text, outlines typical use cases, rate limits, and provides a Java implementation with step-by-step code walkthrough.

Coder Trainee
Coder Trainee
Coder Trainee
Detect Sensitive Text in WeChat Mini Programs Using the Content Security API

Many developers encounter the need to filter sensitive words—political, pornographic, gambling, drug‑related—in notes or blog content within WeChat Mini Programs. This article introduces the text security detection service provided by WeChat, which can reduce manual effort by using the platform’s API to screen such content.

WeChat Documentation

The official interface documentation is shown in the image below.

WeChat API documentation
WeChat API documentation

Application Scenarios

User profile text compliance checking.

Media news articles and comment moderation.

User‑generated content uploaded after editing.

Precautions

WeChat imposes rate limits for security reasons: each appid can call the API up to 4,000 times per minute and 2,000,000 times per day.

Code Implementation

The following Java method calls the msg_sec_check endpoint, replaces placeholders with the actual openid and content, sends a POST request, parses the JSON response, and returns true if the suggestion is “pass”.

public static boolean msgSecCheck(String access_token,String openid,String content){
    System.out.println(access_token);
    String params = "{
" +
            "        \"openid\": \"OPENID\",
" +
            "        \"scene\": 1,
" +
            "        \"version\": 2,
" +
            "        \"content\":\"CONTENT_STR\"
" +
            "    }";
    String s = params.replaceAll("OPENID", openid).replaceAll("CONTENT_STR", content);
    String msg_sec_check = MSG_SEC_CHECK.replaceAll("ACCESS_TOKEN", access_token);
    String s1 = HttpUtils.httpsRequest(msg_sec_check, "POST", s);
    JSONObject jsonObject = JSONObject.parseObject(s1);
    JSONObject result = (JSONObject)jsonObject.get("result");
    String suggest = (String)result.get("suggest");
    System.out.println(suggest);

    System.out.println(s1);
    if("pass".equals(suggest)){
        return true;
    }
    return false;
}

Explanation of the steps:

Assemble the request payload by inserting the actual openid and content into the JSON string.

Replace the placeholder ACCESS_TOKEN in the request URL with the real access token.

Send a POST request to the WeChat server and obtain the response.

Parse the response into a JSONObject, extract the suggest field, and treat “pass” as a safe result.

With this implementation, developers can integrate WeChat’s text security check into their Mini Programs to automatically detect and block prohibited content.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

WeChat Mini ProgramAPIContent SecurityText Filtering
Coder Trainee
Written by

Coder Trainee

Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.