package com.wc.action;
import java.io.File;
import java.io.InputStream;
import java.sql.Timestamp;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataBodyPart;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.FormDataParam;
import com.wc.bean.OfUser;
import com.wc.bean.WcFile;
import com.wc.bean.WcLoginInfo;
import com.wc.bean.WcUser;
import com.wc.dao.OfUserDAO;
import com.wc.dao.WcFileDAO;
import com.wc.dao.WcLoginInfoDAO;
import com.wc.dao.WcUserDAO;
import com.wc.tools.Blowfish;
import com.wc.tools.FileUtil;
import com.wc.tools.SimpleJSONArray;
import com.wc.tools.SimpleJSONObject;
import com.wc.tools.StringUtil;
@Produces("application/json;charset=UTF-8")
// @Consumes("charset=UTF-8")
@Path("")
public class MainActions {
/* dao组 */
private WcUserDAO uDao = new WcUserDAO();
private OfUserDAO ofDAO=new OfUserDAO();
private WcFileDAO fileDao=new WcFileDAO();
private WcLoginInfoDAO logDao=new WcLoginInfoDAO();
private SimpleJSONObject res = new SimpleJSONObject();
private static Blowfish _blow = new Blowfish("weChat4.0");
private static Blowfish _of = new Blowfish("4H709fjyRIPOVvK");
/* 用户模块 */
/* 登陆接口 */
@POST
@Path("login.do")
public String login(@FormParam("mobile") String mobile,
@FormParam("uPass") String uPass,
@FormParam("versionInfo") String versionInfo,
@FormParam("deviceInfo") String deviceInfo,
@Context HttpServletRequest request) {
WcUser user = uDao.findByMobile(mobile);
if (user == null) {
// 注册失败,用户名已存在
res.add("status", -1);
res.add("msg", "登陆失败,该用户名不存在,您可以先注册");
return res.toString();
}
if (user.getUserPassword().equalsIgnoreCase(uPass)) {
user.setApiKey(_blow.encryptString(mobile + uPass
+ System.currentTimeMillis()));
user = uDao.update(user);
res.add("status", 1);
res.add("msg", "登陆成功");
res.add("apiKey", user.getApiKey());
SimpleJSONObject userJson = user.toJSON();
res.add("userInfo", userJson);
WcLoginInfo log=new WcLoginInfo();
log.setLoginDevice(deviceInfo);
log.setLoginResult("登陆成功");
log.setLoginTime(new Timestamp(System.currentTimeMillis()));
log.setLoginVersion(versionInfo);
log.setUserLoginName(mobile);
logDao.save(log);
} else {
res.add("status", -2);
res.add("msg", "密码错误");
}
return res.toString();
}
/* 注册接口 */
@POST
@Path("register.do")
public String register(@FormParam("mobile") String mobile,
@FormParam("uPass") String uPass,
@FormParam("description") String description,
@FormParam("userHead") String userHead,
@FormParam("nickName") String nickName,
@Context HttpServletRequest request) {
if (uDao.findByUserName(mobile).size() != 0) {
// 注册失败,用户名已存在
res.add("status", -2);
res.add("msg", "注册失败,该手机号已注册");
return res.toString();
}
WcFile file=fileDao.findById(userHead);
WcUser user = new WcUser();
user.setUserName(mobile);
user.setUserPassword(uPass);
user.setUserDescription(description);
user.setUserNickname(nickName);
if(file!=null)
user.setUserHead(file);
user.setApiKey(_blow.encryptString(mobile + uPass
+ System.currentTimeMillis()));
uDao.save(user);
registerOpenFireUser(user);
res.add("status", 1);
res.add("msg", "注册成功");
res.add("apiKey", user.getApiKey());
res.add("userInfo", user.toJSON());
return res.toString();
}
/*
* 注册openFire
*
* */
private boolean registerOpenFireUser(WcUser user) {
// TODO Auto-generated method stub
String encodedStr=_of.encryptString(user.getUserPassword());
OfUser openFireUser=new OfUser(user.getUserId(), user.getUserPassword(), encodedStr, "", "", String.format("00%d", System.currentTimeMillis()), String.format("00%d", System.currentTimeMillis()));
ofDAO.save(openFireUser);
return true;
}
/*附件相关
*
*
*/
// 上传文件接口
@POST
@Path("uploadFile.do")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String uploadFile(@FormDataParam("apiKey") String apiKey,
/* 任意数量的文件,图片请设置mediaType为 image/xxxx 语音请设置为audio/xxxx 参数名都是file */
FormDataMultiPart form) {
SimpleJSONObject res = new SimpleJSONObject();
WcUser me = uDao.findByApiKey(apiKey);
// 获取工程根目录
String rootPath = new File("").getAbsolutePath();
// rootPath=FileUtil.getParent(rootPath)+ File.separator+"webapps";
rootPath += File.separator + "webapps";
// ArrayList<VsFile> files = new ArrayList<VsFile>();
SimpleJSONArray fileArr = new SimpleJSONArray();
List<FormDataBodyPart> l = form.getFields("file");
for (FormDataBodyPart p : l) {
InputStream is = p.getValueAs(InputStream.class);
FormDataContentDisposition detail = p
.getFormDataContentDisposition();
MediaType type = p.getMediaType();
System.out.println("发现文件" + type.getType());
String fileLocation = rootPath + File.separator + "res"
+ File.separator + System.currentTimeMillis() + "."
+ FileUtil.getEndWith(detail.getFileName());
File file = FileUtil.writeToFile(is, fileLocation);
if (file != null) {
WcFile imageFile = new WcFile();
imageFile.setUploadUser(me);
imageFile.setFullPath(fileLocation);
imageFile.setShortPath("res/"+file.getName());
imageFile.setFileType(type.getType().equals("image") ? 1 : 2);
fileDao.save(imageFile);
fileArr.add(imageFile.toJSON());
}
}
res.add("status", 1);
res.add("files", fileArr);
return res.toString();
}
/*社交相关*/
/* 搜索好友接口 */
@POST
@Path("findFriend.do")
public String findFriend(@FormParam("apiKey") String apiKey,
@FormParam("nickName") String nickName,
@FormParam("pageIndex") Integer pageIndex,
@FormParam("pageSize") Integer pageSize)
{
WcUser me=uDao.findByApiKey(apiKey);
if(me==null)
{
res.add("status", -100);
res.add("msg", "您的apiKey已过期,您的账户可能被别人登陆,请修改密码或重新登陆");
}
List<WcUser> ulist;
if(!StringUtil.isNullOrEmpty(nickName))
ulist=uDao.searchByUserNickname(nickName, (pageIndex-1)*pageSize,pageSize);
else
ulist=uDao.findAll((pageIndex-1)*pageSize,pageSize);
SimpleJSONArray userArr=new SimpleJSONArray();
for (WcUser u : ulist) {
userArr.add(u.toJSON());
}
res.add("status", 1);
res.add("msg", "搜索好友成功");
res.add("userList", userArr);
return res.toString();
}
/* 添加好友接口 */
@POST
@Path("addFriend.do")
public String addFriend(@FormParam("apiKey") String apiKey,
@FormParam("userId") String userId)
{
WcUser me=uDao.findByApiKey(apiKey);
if(me==null)
{
res.add("status", -100);
res.add("msg", "您的apiKey已过期,您的账户可能被别人登陆,请修改密码或重新登陆");
}
if(me.getUserId().endsWith(userId))
{
res.add("status", -1);
res.add("msg", "不要添加自己为好友");
return res.toString();
}
WcUser u=uDao.findById(userId);
if(me.getFriends().contains(u))
{
res.add("status", -1);
res.add("msg", "添加好友失败,已经是你的好友了");
return res.toString();
}
me.getFriends().add(u);
u.getFriends().add(me);
uDao.update(me);
uDao.update(u);
res.add("status", 1);
res.add("msg", "添加好友成功");
// res.add("userList", userArr);
return res.toString();
}
/* 添加好友接口 */
@POST
@Path("deleteFriend.do")
public String deleteFriend(@FormParam("apiKey") String apiKey,
@FormParam("userId") String userId)
{
WcUser me=uDao.findByApiKey(apiKey);
if(me==null)
{
res.add("status", -100);
res.add("msg", "您的apiKey已过
没有合适的资源?快使用搜索试试~ 我知道了~
基于XMPP协议的IM实现
共1455个文件
png:238个
h:183个
m:162个
1星 需积分: 42 30 下载量 168 浏览量
2014-02-18
15:55:45
上传
评论 3
收藏 18.08MB ZIP 举报
温馨提示
1.新用户注册 2.登陆并连接XMPP服务器 握手 保持在线 2.查找最新注册用户:(下拉刷新 上拉翻页,做的比较匆忙,没操作提示) 3.点击某个用户即可对他发送消息 4.首页显示收到的和发送的所有消息 5.修复了注册延时时间,添加了切换账号功能,修复了输入框适配问题 6.微信页面和聊天页面界面已基本重做 。首页消息按联系人分组按时间逆序显示,聊天气泡有待优化,收发消息全部采用 NSNotifaction 不用担心消息发了页面不刷新。自动滚到最新一条。键盘监听效果更加友好,采用TableViewInset来错位。 7.添加好友功能,添加完后可以在好友列表查看到,若是在是注册的太早要翻很久,或者新注册用户刷新不出来,可以通过webview直接添加,但是需到控制台查看互相的ID 4.User对象和Message对象采用FMDB+类java的Dao模式用静态方法固化,并且有个开发者自己写的对象to字典、字典to对象的两个超好用的方法,大家值得一看! 8.删除了XMPPManager单例中的一些废话和暂时用不着的内容,添加了很多注释,大家可以细细品读。
资源推荐
资源详情
资源评论
收起资源包目录
基于XMPP协议的IM实现 (1455个子文件)
005271dbe3a53b36043de04a74d246e5a8df93 150B
00638316fab05fea7b0efaca664eda70feeae5 21KB
00af514723d8241000d47f1a96ddaf3dc17f86 143B
01b3533dd894cb6a1f3b72b73efce65fbeb107 145B
01fae6dce3598b87cb1f0234637dbaa0bfd17d 10KB
01fe4ae0a8aec1d364ea701a40bf46eb7fd6b2 1KB
020a66c9b8f01648ea9219ec6f383b75ff186e 99B
02102144086d1211e5cccab93ce9d9a1a6bccf 5KB
02ab0b55783fdfd1b00a72a17e98440fc65a0e 394B
02d4e3303fbe5f0ac71ff72cf7d85d6a574ca8 1KB
02e4661273220b863c6456bcdf43eeac921fd8 834B
03567991c0b899f766ba76db3ee021238044b1 1KB
0383c32ce5eec1383b1f6933ebf73866b8d57e 101B
03920c1b0fa2d9bf3adb992bd85cc829260838 211B
03a6ecb40cb8069dd10bc447e4a27d53ddb595 3KB
03c69416a3d2fbdb268d567d6eff51f120f8bd 105B
03c8d6ed3eb284cb7f0c6da9743f675b1c7f1b 6KB
043552902bee6eaa515730c177681b701b859d 110B
0566f4d8350cb462194a8d8cedfb4c6e0aa721 4KB
05dd43c604a59afe631669df26d864d41768a8 3KB
07032b038f9098de6b61ebfcab80ed7d53b56d 820B
07c6c68d151bc8191520662bb3c28c3247d08d 146B
07f548aaedd53e6319a4223e84272c69ab5c38 687B
085e63833c6762bfd17bcca4c090269839f81e 157B
08ddfcf53c02e82d7eee2e57c38e5672ef89f6 255B
09793d1b304f22d541b765615f8e046cbf013c 2KB
097f751da633f54b6827bb0021536c61863060 150B
09837d3ee40e6fad33434d95b2dad7361491d0 4KB
09dd490e3b7c99bbbbe80044a3d9f4e155f996 104B
0a1525a26c303979c96e5614af0819f427d1c4 4KB
0a4396614116aa61adce61c563fdeb70d4da9c 151B
0a62cfe0e3a3348dad7913bc4254dd04ed2aac 149B
0a86cb07616547f84796bbdb2ce752f36aabb1 97B
0aa6c0bd9a95d1fb114151d1afbc3bd16bc707 130B
0abfde7648c619eb230c98090743c6376a2f06 97B
0c161b882479b70997b8b1472b5d0307147fe8 160B
0c6cef7e730ef2b199f3423b8adf3f2df73b5f 96B
0c802ca011db130dcaf6fdde6b58534f33ba52 301B
0cbe3a1a59a5930efb5079db3923d2e5fc0650 753B
0efdbe8befbe5057d789a2a8aef4d2c41baaba 2KB
0efdd09601759e9dd28a226ea80fcf175f05e9 148B
102561e6bf61d0edf561c9c7a37870cefdc12a 149B
10639a89e0773a36e533f2eb5220ba7c14558b 306B
109c2a9eeeb97b94026db51d5bb6561effdb1c 101B
10efb81ef29d9ce2d605eade8d52743b76d4f7 3KB
12367508a94b87c1f3e77c60cb1bb89872712d 99B
124952283163b8860a4d382eb41847adff4c99 2KB
125454bf097e3ce9f141948c6a84b23519a038 147B
12594301260a9f6c21652ad3c035a642ddf242 2KB
12bd0bec78016989fde1e0ca325a2272efce4b 25KB
133add8076a975d65cd8b730d2aba146cfaac2 2KB
15466c4ef5777fc3569ce391104c9a9ed0678f 150B
15ebc97ca1816389ebd5550557aa0484110057 131B
165f17b75cdc77ed3762026365bcb669e71233 156KB
169b9168f5293e684d3d92930c818f2cfbab6a 151B
16e5f76fa991885f0b88e8f1d33c582fd0e91f 99B
1721482ec86819a4dcf8a99847b0c8c643a03b 149B
1732cb6930b260e0753476f69481175cf9da05 96B
1735a5051249c114c3ba6fda328f562b28888c 104B
17a04cb10e43147ae865a8e660d73252e3d453 98B
17b0ba59f6ac78f7ddc2e8303a328875e6db6c 95B
18fb1f55da7c0bd26ad5376f83a848115a0a87 669B
18fe9af292c1a36b34934590873043b8902132 151B
19566b334d1718afaab6a221235f32755185e1 4KB
1a8438a72569f6a257a8c48c8cf7338735d7f9 1KB
1aaa4ed8c982e82018f9e183c25e06a17beb25 3KB
1c1044e45784432bb161510c3d7c8ed1898113 3KB
1c62f0b760aa92fae2353911eb7288364adf7a 92B
1c99964c55799628e171855fa53d3666f7f845 155B
1d79883a62238b2e627f9aaa02a246a3b8058f 108B
1e94c8b390275a62daaadcbabe081f923c55e0 105B
1f182ac8107891ed05df56b28501b23ad737e6 438B
1f4f6cb7e91b9e8d58b8d08ac1e48013afd512 103B
1fa2389d26f357da33d3068f386890838bfd07 95B
1ffb779199106c183264839c007b6eaf018edf 11KB
2085b1366ae1268a2bc5aa494e9e54276193e9 157B
20ed7a6d2b5223f9756f827eb77d877472dafe 3KB
21076a818e0166bb4992b5ce350b907132a315 97B
215cb959dbe96246b0e47fd0be8bde6e99d028 145B
2171e5a29a2da5b57d5ac0f6bbee8ca5665403 330B
22236593eaf0c9b3ecf411862e4feb802c17fc 7KB
2252002d1b33f955f73a428f7937be39bcf486 98B
22745fdd467ef157bade3bb84432ad6aa9c055 153B
22a1d428feadd88ed714cd76653c4b93bc68a5 1KB
22aa3af3bad04202354a1bee00b034f0f71700 144B
22b0aa99a880ec8809e149f077d608cb1ab7c0 144KB
22f173791871c735155fe793ef79504a53a0ea 145B
235464aeb7a51c18fe4e92ab347903b47234e6 151B
237fe143025a3bd48cac33cea254018558e5e1 93B
23c4fd153a90e58bd5cb5a0945fdce53d47c41 97B
240d4a22b8eeec11da753e85bab8f631d2a14e 4KB
247857c04e1139d7b939fd2cdae2c307230561 120B
24b06eb573277b41d33d47a2dcccabf0e8989c 3KB
256ef437ba33100d5e000ee3a4f573b3970017 3KB
263f63c71f717413fd91352e4aff01814d6776 434B
267247db51e54b96431b7fda720f793a246a43 837B
2688e9efe5257f74aa3711afc3a29be67a0862 15KB
26b8f08072c582e92fe89b6142169896ebb6dc 3KB
26ffd2cab667f65831a6b75d625c4598428575 96B
277115cf764f2598ef0df38dd77fce84fa716d 94B
共 1455 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
- @kyros2019-05-31你可以睡觉了。
51ios
- 粉丝: 224
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功