How to invite friends to sign up for your website (simulate Baidu network disk)

Source: Internet
Author: User
Tags getbase uuid

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.