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

Source: Internet
Author: User
Tags getbase

Spent a year to do a network disk download site, interested friends can look at the station name: to the Turntable network link: www.quzhuanpan.com One of the requirements is to simulate Baidu Network disk invite Friends registration function, think for a long time indeed, "emperor", finally sorted out a thought, and attached code, I hope you have a lot of friends spit groove. My idea is basically to use the network-wide unique string UUID to invite friends, the inviter to a status bit 1 on behalf of the inviter, and to bind him a unique uuid. The invitee gives an identity bit 0 for the invitee, and if he is registered successfully,

Can be based on 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;

}


This article is from the "Yellow Break" blog, please be sure to keep this source http://5912119.blog.51cto.com/5902119/1731795

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.