微信小程序内容审核是确保小程序合规性、安全性和用户体验的重要环节。当小程序涉及自定义内容发布时,通常需要开发者自行接入内容审核 API。
本文以 SpringBoot 工程为例,介绍通过开源 SDK 简化接入流程。
一、引入微信小程序 Java SDK
开源地址:https://github.com/binarywang/WxJava
Maven 依赖:
<!-- 微信小程序 -->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java-miniapp-spring-boot-starter</artifactId>
<version>4.6.0</version>
</dependency>
二、SpringBoot 配置
wx:
miniapp:
appid: wx12345
secret: 12345abced
三、编写测试类
package cn.junki.project.server;
import cn.binarywang.wx.miniapp.api.WxMaService;
import me.chanjar.weixin.common.error.WxErrorException;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
@SpringBootTest
public class ServiceServerApplicationTests {
@Resource
private WxMaService wxMaService;
@Test
public void msgSecCheckText() {
String msg = "你好,测试文本";
boolean result;
try {
result = wxMaService.getSecCheckService().checkMessage(msg);
} catch (WxErrorException e) {
throw new RuntimeException(e);
}
System.out.println(result);
}
@Test
public void msgSecCheckImage() {
String image = "https://xxx.xxx.xxx.jpg";
boolean result;
try {
result = wxMaService.getSecCheckService().checkImage(image);
} catch (WxErrorException e) {
throw new RuntimeException(e);
}
System.out.println(result);
}
}