首页>代码>ssm(spring mvc+mybatis)+netty4开发qiqiim即时聊天实例>/qiqiim-server/src/main/java/com/qiqiim/rebot/proxy/impl/MLRebotProxy.java
/**
 ***************************************************************************************
 *  @Author     1044053532@qq.com   
 *  @License    http://www.apache.org/licenses/LICENSE-2.0
 ***************************************************************************************
 */
package com.qiqiim.rebot.proxy.impl;
/**
 * 茉莉机器人回复
 */
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.time.DateFormatUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.qiqiim.constant.Constants;
import com.qiqiim.rebot.model.RobotMessage;
import com.qiqiim.rebot.model.RobotMessageArticle;
import com.qiqiim.rebot.proxy.RebotProxy;
import com.qiqiim.server.model.MessageWrapper;
import com.qiqiim.server.model.proto.MessageBodyProto;
import com.qiqiim.server.model.proto.MessageProto;

public class MLRebotProxy implements RebotProxy {
	  private final static Logger log = LoggerFactory.getLogger(MLRebotProxy.class);
	private String apiUrl;//机器人apiurl
	private String key="";//秘钥    请自行申请机器人KEY
	private String secret="";

	@Override
	public MessageWrapper botMessageReply(String user, String content) {
		log.info("MLRebot reply user -->"+user +"--mes:"+content);
		String message = "";
		 try{
			    //只实现了基础的  具体的请自行修改
			    Document doc = Jsoup.connect(apiUrl).timeout(62000).data("api_key",key).data("api_secret",secret).data("limit","5").data("question",content).post();
				message = doc.select("body").html(); 
			}catch(Exception e){
				e.printStackTrace();
			}
		 MessageProto.Model.Builder  result = MessageProto.Model.newBuilder();
		 result.setCmd(Constants.CmdType.MESSAGE);
		 result.setMsgtype(Constants.ProtobufType.REPLY);
		 result.setSender(Constants.ImserverConfig.REBOT_SESSIONID);//机器人ID
		 result.setReceiver(user);//回复人
		 result.setTimeStamp(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
		 MessageBodyProto.MessageBody.Builder  msgbody =  MessageBodyProto.MessageBody.newBuilder();
		 msgbody.setContent(message); 
	     result.setContent(msgbody.build().toByteString());
		 return new MessageWrapper(MessageWrapper.MessageProtocol.REPLY, Constants.ImserverConfig.REBOT_SESSIONID, user,result.build());
	}

	public void setApiUrl(String apiUrl) {
		this.apiUrl = apiUrl;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}
	  
}
最近下载更多
阿凡达  LV9 4月18日
ewan007  LV29 2023年4月21日
wujiahua  LV3 2022年12月8日
zz1230012300  LV11 2022年8月23日
落后就要挨打  LV26 2022年7月27日
xuweisong2010  LV27 2022年5月18日
最代码安逸  LV15 2022年5月15日
FreddieLee  LV3 2022年4月1日
wanglinddad  LV54 2021年10月22日
无名氏111  LV32 2021年9月10日
最近浏览更多
阿凡达  LV9 4月18日
3334004690  LV3 3月20日
yhwyhw1  LV2 2023年12月21日
shuangfu  LV24 2023年12月2日
wanfeng_233  LV4 2023年8月29日
uni-code_0123  LV1 2023年8月1日
yangbulx  LV3 2023年5月25日
173745830  LV11 2023年5月8日
微信网友_6444139264921600  LV6 2023年4月30日
ewan007  LV29 2023年4月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友