| 請求類型 | 請求地址 |
| --- | --- |
| POST | http://send.6web.cn/api/Check/words|
| 參數名 | 類型 | 描述 |
| --- | --- | --- |
| user| String | 平臺用戶名 |
| key| String | 平臺用戶密碼 |
| content| String | 查詢的內容 |
```
請求失敗 -> 返回碼
{
"code": "0",
"msg": "錯誤信息",
}
```
~~~
合規 -> 返回碼
{
"code": "1",
"msg": "無違禁詞",
}
```
~~~
```
違規 -> 返回碼
{
"code": "2",
"msg": "違禁詞、違禁詞",
}
```
~~~
參照代碼(PHP)
~~~
~~~
<?php
$url =http:// send.6web.cn/api/Check/words';
$content= '查詢的內容';
$postdata = [
'user' =>'平臺用戶名',
'key' => '平臺用戶密碼',
'content' => $content
];
$result = request_post($url,$postdata);
$status = json_decode($result,true);
if($status['code'] == '2'){
//含有違禁詞,參考返回的msg
}else($status['code'] == '1'){
//無違禁詞
}else{
//請求失敗,參考返回的msg
}
function request_post($url = '', $post_data =0) {
if (empty($url) || empty($post_data)) {
return false;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$httpheader[] = "Accept:*/*";
$httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Connection:close";
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($post_data) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
~~~
~~~
參照代碼(JAVA)
~~~
~~~
import java.io.*;
import java.net.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
String url = "http://send.6web.cn/api/Check/words";
String content = "查詢的內容";
Map<String, String> postdata = new HashMap<String, String>();
postdata.put("user", "平臺用戶名");
postdata.put("key", "平臺用戶密碼");
postdata.put("content", content);
String result = requestPost(url, postdata);
Map<String, Object> status = new HashMap<String, Object>();
try {
status = new ObjectMapper().readValue(result, new TypeReference<Map<String, Object>>() {});
} catch (IOException e) {
e.printStackTrace();
}
if (status.get("code").equals("2")) {
// 含有違禁詞,參考返回的msg
} else if (status.get("code").equals("1")) {
// 無違禁詞
} else {
// 請求失敗,參考返回的msg
}
}
private static String requestPost(String url, Map<String, String> postdata) {
StringBuilder result = new StringBuilder();
HttpURLConnection conn = null;
OutputStreamWriter osw = null;
BufferedReader br = null;
try {
URL realUrl = new URL(url);
conn = (HttpURLConnection) realUrl.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Charset", "utf-8");
conn.setUseCaches(false);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
if (postdata != null && !postdata.isEmpty()) {
osw = new OutputStreamWriter(conn.getOutputStream());
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : postdata.entrySet()) {
sb.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "utf-8"))
.append("&");
}
String param = sb.toString();
param = param.substring(0, param.length() - 1);
osw.write(param);
osw.flush();
}
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (osw != null) {
osw.close();
}
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (conn != null) {
conn.disconnect();
}
}
return result.toString();
}
}