package com.yihu.wlyy.web.common.im;


import io.swagger.annotations.Api;
import org.json.JSONObject;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.web.BaseController;

@RestController
@RequestMapping(value = "common", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "IM-即时消息")
public class imController extends BaseController {
	
	private static String host = "http://172.19.103.76:3000";
	
	@RequestMapping(value="/send_bus_msg")
	public String sendBusinessMsg(String userId,String content)
	{
		try{
			String _url = host+"/api/v1/chats/sm";
			String param = "user_id="+userId+"&content="+content;
			String result = HttpUtil.sendPost(_url, param);
		
			JSONObject jb = new JSONObject(result);
			String errno = jb.get("errno").toString();
			String errorMsg = jb.get("errmsg").toString();
			if(!errno.equals("0"))
			{
				return error(-1,errorMsg);
			}
			
			return success("推送成功!");
		}
		catch(Exception ex)
		{
			error(ex);
			return invalidUserException(ex, -1, "保存失败！");
		}
	}
	
	@RequestMapping(value="/send_chat_msg")
	public String sendChatMsg(String userId,String content)
	{
		return "";
	}
}
