spent a year to do a network disk download site, interested friends can look at the station name:go to the turntable netOne of the requirements is to simulate Baidu Network disk invite Friends Registration function, thought for a long time indeed"Emperor ", finally sorted out a train of thought, and attached code, I hope you many netizens spit groove. My idea is basically to use the network-wide unique string UUID to invite friends, invitees to a status bit1represents the inviter and binds him to a unique UUID. The invitee gives an identification bit0 on behalf of the invitees, if he registered successfully, you can follow the invitation link to obtain the UUID to query the database to find the inviter, find and give the corresponding points, the code is as follows:
Public String invite () {
int invteorbeinted=1;//Inviter is 1, invited to 0
String Username=null;
String Temp=getparameter ("username");
if (temp!=null) {
try {
Username = new String (temp.getbytes ("iso-8859-1"), "Utf-8");
} catch (Unsupportedencodingexception e) {
E.printstacktrace ();
}
}
Username= (User) session.get (codeconst.userinsession)). GetUserName ();
if (username==null) {
Message= "no permission to invite users";
return ERROR;
}
Registerservice Registerservice = Servicefactory.getregisterservice ();
Userdao Userdao=null;
try {
Userdao = Registerservice.getuserdao ();
} catch (Exception E1) {
E1.printstacktrace ();
}
@SuppressWarnings ("Rawtypes")
Java.util.List List=null;
User U=null;
try {
List=userdao.findbyusername (username);
} catch (Exception e) {
E.printstacktrace ();
}
if (List!=null&&list.size () >0) {
u= (User) list.get (0);
}
if (U.getinvitecode ()!=null&&u.getinvitedorbeinvited () ==1) {//has invited
Invitecode=u.getinvitecode ();
}
else{
Invitecode=uuid.randomuuid (). toString ();//uuid uniqueness
}
String goodnews= "Network disk sharing, network disk download, here is to go to the turntable network." Click on the link below to register, mass network resources and you share ";
String url=goodnews+getbase () + "registermanager/inviteregister.action?invitecode=" +invitecode;
Note, here the GetBase () function is implemented by itself, is to obtain
Gethttprequest (). SetAttribute ("url", url);//Send to foreground
try {
Registerservice.updateinviteman (username, invitecode,invteorbeinted); Update inviter information, note that Invitecode is unique for UUID
Add points to the inviter based on Invitecode after the user has registered successfully.
} catch (Exception e) {
E.printstacktrace ();
}
return SUCCESS;
}
How to invite friends to sign up for your website (simulate Baidu network disk)