一、什么是Simsimi?
simsimi公司是提供智能服務,其中一個服務是simsimi聊天機器人服務,每天有超過百萬的用戶聊天,國內最大的搜索引擎——百度的產品siri使用的就是simsimi提供的api。
你可以在網址http://www.simsimi.com/talk.htm# 進行體驗
SimSimi inc. is specialized in collective intelligence service. All kinds of services we provide generates unique entertainment and values through systemized collective intelligence.
One of our services, a chatting robot SimSimi exceeds the limitation of technology of natural-language processing system by collective intelligence and it has a chat with over millions user per day. Our Premium knowledge providing service “Jisikman” creates millions of valuable knowledges a day.
We invite you to our realm of service which is available through our cloud of collective intelligence, Crowd Cloud that SimSimi inc. creates.
二、Simsimi小黃雞API
在 去年的這個時候,小黃雞的非官方api一度被大家瘋狂的在微信公眾號上使用,一時間不知道成就了多少微信營銷號,同時,華科某位大四學生利用這個api, 結合人人網開發平台,制作了一個小黃雞的人人號,@小黃雞之后,就可以利用api自動進行回復,是的這個人人號瞬間粉絲陡增。
然而大家使用的都是非官方的API,所謂非官方,就是不是simsimi公司提供的合法使用途徑,API大致的原理是利用編程語言,模擬瀏覽器發送post請求到http://www.simsimi.com/talk.htm# 鏈 接,解析響應,然后作成相關的小黃雞API。這個方法后來被我在本博客中在博文中發布,導致使用人數激增,simsimi公司似乎察覺了什么,立馬對這種 模擬請求的方式做出了屏蔽,一旦某ip請求數量和頻率超過限制,則終端對它的請求。正式官方對非法API的封鎖,也使用國內的開發這關注到之前並不出名的 小i機器人,同樣使用語言模擬請求web聊天界面,時間沒有過很久,這個頁面就加入了圖片驗證碼防止程序模擬。
至此,兩個聊天機器人都走上了收費的道路...准確的說,應該是被這幫子開發者趕上了收費的道路,因為他們給它帶來了知名度。
三、SimsimiAPI使用
目前,小黃雞API已經公然收費(http://developer.simsimi.com/api)
不過,和之前一樣,會給注冊用戶提供30天的試用API。
API請求鏈接為:
Trial-key http://sandbox.api.simsimi.com/request.p
Paid-key http://api.simsimi.com/request.p
API請求參數為:
Parameter | Value | Required | Default | Description |
---|---|---|---|---|
key | String | Y | Your key value | |
text | String | Y | Query message | |
lc | String | Y | Language code(List) | |
ft | Double(0.0 ~ 1.0) | 0.0 | 可以設置一個過濾器 0.0:未過濾(包含詛咒,性內容) 1.0:過濾不文明字句(暫時只支持韓文) 過濾內容,請訪問下面的網站。 https://www.webpurify.com/ |
API返回格式為:
result:100-ok. 400-Bad Request. 401-Unauthorized. 404-Not found. 500-Server Error. 返回的code
id:Response id. (you can get only if returning result is 100)回復的id,由系統生成,當請求成功返回時才有這個字段。
response:Response message(you can get only if returning result is 100)返回的回復內容。
msg:Result msg(Description of result code) 返回的code對應的含義
四、Simsimi使用舉例
請求舉例:
Trial-key http://sandbox.api.simsimi.com/request.p?key=your_trial_key&lc=en&ft=1.0&text=hi
Paid-key http://api.simsimi.com/request.p?key=your_paid_key&lc=en&ft=1.0&text=hi
響應舉例:
{ "result": 100, "response": "Who are you?!", "id": 13185569, "msg": "OK." }
五、如何免費的使用Simsimi API
我想,大家都懂了,寫這篇文章的原因就是很多人搜索小黃雞 api到我的博客,我想大家都是要找免費的小黃雞API。這里提供給大家一個思路:
合作伙伴中,有人人網,為什么?本博文前面提高某大四學生做了一個人人號,@小黃雞之后,會自動進行回復,他使用的就是simsimi的官方正版付費API,既然人人網提供開發平台,可以對帳號進行回復,獲得回復等等操作,為什么不能使用程序,登錄帳號,然后@小黃雞,然后獲得它的回復,再返回給你自己的用戶呢?答案當然是可以的!!!
下面貼出一段可供參考的Java代碼,之所以為僅供參考,就是說只能參考思路,代碼運行是運行不起來的!!!
如果能夠幫助到你,希望回復點評一下,你懂的...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
import
java.o.IOException;
import
java.util.ArrayList;
import
java.util.List;
import
java.util.Scanner;
import
java.util.regex.Matcher;
import
java.util.regex.Pattern;
import
org.apache.http.Header;
import
org.apache.http.HttpResponse;
import
org.apache.http.NameValuePair;
import
org.apache.http.client.ClientProtocolException;
import
org.apache.http.client.ResponseHandler;
import
org.apache.http.client.entity.UrlEncodedFormEntity;
import
org.apache.http.client.methods.HttpGet;
import
org.apache.http.client.methods.HttpPost;
import
org.apache.http.impl.client.BasicResponseHandler;
import
org.apache.http.impl.client.DefaultHttpClient;
import
org.apache.http.message.BasicNameValuePair;
import
org.apache.http.protocol.HTTP;
import
org.apache.http.util.EntityUtils;
/**
* 利用httpclient操作人人網 比如登陸,發狀態,模擬你訪問任何人主頁等等
* @author: http://50vip.com
*
*/
public
class
RenRen {
private
String userName =
""
;
private
String password =
""
;
private
HttpResponse response;
private
DefaultHttpClient httpclient =
null
;
private
String requestToken =
null
;
private
String _rtk =
null
;
public
RenRen(String userName, String password) {
this
.userName = userName;
this
.password = password;
}
public
static
void
main(String[] args) {
RenRen rr =
null
;
rr =
new
RenRen(
"xxxxx@hotmail.com"
,
"yyyyy"
);
rr.login();
System.out.println(rr.talk(
"820"
));
}
/**
* 登陸
* @author: http://50vip.com
* @return
*/
public
boolean
login() {
if
(httpclient !=
null
) {
return
true
;
}
httpclient =
null
;
httpclient =
new
DefaultHttpClient();
HttpPost httpost =
new
HttpPost(renRenLoginURL);
// All the parameters post to the web site
List<NameValuePair> nvps =
new
ArrayList<NameValuePair>();
nvps.add(
new
BasicNameValuePair(
"origURL"
, redirectURL));
nvps.add(
new
BasicNameValuePair(
"domain"
,
"renren.com"
));
nvps.add(
new
BasicNameValuePair(
"autoLogin"
,
"true"
));
nvps.add(
new
BasicNameValuePair(
"formName"
,
""
));
nvps.add(
new
BasicNameValuePair(
"method"
,
""
));
nvps.add(
new
BasicNameValuePair(
"submit"
,
"登錄"
));
nvps.add(
new
BasicNameValuePair(
"email"
, userName));
nvps.add(
new
BasicNameValuePair(
"password"
, password));
try
{
httpost.setEntity(
new
UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
//System.out.println(response);
}
catch
(Exception e) {
e.printStackTrace();
return
false
;
}
finally
{
httpost.abort();
}
String redirectLocation = getRedirectLocation();
if
(redirectLocation !=
null
) {
// 跳到首頁,登錄完成
String indexHtml=getText(redirectLocation);
//獲取requestToken get_check:'-2062261917'
Pattern pattern1 = Pattern.compile(
"get_check:'(.*)',get_check_x"
);
Matcher m1 = pattern1.matcher(indexHtml);
if
(m1.find()) {
requestToken=m1.group(
1
);
}
else
{
System.out.println(
"獲取requestToken失敗!"
);
}
//"獲取_rtk失敗!"get_check_x:'50d55fbd'
Pattern pattern2 = Pattern.compile(
"get_check_x:'(.*)',env:"
);
Matcher m2 = pattern2.matcher(indexHtml);
if
(m2.find()) {
_rtk=m2.group(
1
);
}
else
{
System.out.println(
"獲取_rtk失敗!"
);
}
}
return
true
;
}
/**
* 和人人的小黃雞交談
* @author: http://50vip.com
* @param msg
* @return
*/
public
String talk(String msg) {
String repMsg=
""
;
//小黃的回復
HttpPost httpost =
new
HttpPost(talkUrl);
// All the parameters post to the web site
List<NameValuePair> nvps =
new
ArrayList<NameValuePair>();
nvps.add(
new
BasicNameValuePair(
"_rtk"
, _rtk));
nvps.add(
new
BasicNameValuePair(
"requestToken"
, requestToken));
nvps.add(
new
BasicNameValuePair(
"message"
, msg));
try
{
ResponseHandler<String> responseHandler =
new
BasicResponseHandler();
httpost.setEntity(
new
UrlEncodedFormEntity(nvps, HTTP.UTF_8));
repMsg=httpclient.execute(httpost, responseHandler);
}
catch
(Exception e) {
e.printStackTrace();
}
finally
{
httpost.abort();
}
return
repMsg;
}
/**
* 此處人人網會302跳轉
* @author: http://50vip.com
* @return
*/
private
String getRedirectLocation() {
Header locationHeader = response.getFirstHeader(
"Location"
);
if
(locationHeader ==
null
) {
return
null
;
}
return
locationHeader.getValue();
}
/**
* 讀取首頁內容
* @author: http://50vip.com
* @param redirectLocation
* @return
*/
private
String getText(String redirectLocation) {
HttpGet httpget =
new
HttpGet(redirectLocation);
// Create a response handler
ResponseHandler<String> responseHandler =
new
BasicResponseHandler();
String responseBody =
""
;
try
{
responseBody = httpclient.execute(httpget, responseHandler);
}
catch
(Exception e) {
e.printStackTrace();
responseBody =
null
;
}
finally
{
httpget.abort();
}
return
responseBody;
}
}
|