WebService Instance-CRM system provides webservice to realize user registration function

Source: Internet
Author: User

<-start->
Write the WebService interface of CRM to realize the saving operation of customer information. A new service interface is added to the CustomerService interface to add customer registration information.

1 @Path ("/customer")2@POST3 @Consumes ({"Application/xml", " Application/json " })4publicvoid regist (customer customer);

In the implementation class, you only need to call the DAO's Save method to save the following.

1 @Override 2  Public void Regist (Customer customer) {3    System.out.println (customer); 4     Customerrepository.save (customer); 5 }

Because the Save method has default on the JPA interface, no customization is required to create the method.
The next step is to invoke the service in the Customeraction class.
Call WebService Connect CRM to save customer information: Send JSON type of data, call the Post method to pass the customer in the past, client registration will be saved to the background database, so use the Post method to add.

1@ParentPackage ("Json-default")2@Namespace ("/")3 @Controller4@Scope ("Prototype")5  Public classCustomerAction2extendsBaseaction<customer> {6@Action (value= "Customer_sendsms")7      PublicString sendsms ()throwsioexception{8         //Generate SMS Verification code9String Randomcode = randomstringutils.randomnumeric (4);Ten         //Save the SMS verification code to the session One servletactioncontext.getrequest (). GetSession (). SetAttribute (Model.gettelephone (), randomcode); A         //Edit SMS Content -String msg = "Hello!" Verify code bit for this acquisition: "+Randomcode; -         //Call SMS Service to send SMS the         //String result = Smsutils.sendsmsbyhttp (Model.gettelephone (), msg); -String result = "000/xxx"; -         if(Result.startswith ("000")){ -             //starting with "000" indicates success of SMS sending +             returnNONE; -}Else{ +             //send failed, throw a run-time exception A             Throw NewRuntimeException ("SMS send failed, Info code:" +result); at         } -     } -  -     //Property-driven verification code for receiving page completion -     PrivateString Checkcode; -      Public voidSetcheckcode (String checkcode) { in          This. Checkcode =Checkcode; -     } to@Action (value= "Customer_regist", results={@Result (name= "Success", type= "redirect", location= "signup_success.html"), +@Result (name= "input", type= "redirect", location= "signup.html")}) -      PublicString regist () { the         //first check the SMS verification code, if not through the jump back to the login page *         //obtain a previously generated SMS verification code from the session $String checkcodesession =(String) servletactioncontext.getrequest (). getattribute (Model.gettelephone ());Panax Notoginseng         if(checkcodesession==NULL||!checkcodesession.equals (Checkcode)) { -SYSTEM.OUT.PRINTLN ("SMS Verification code Error! "); the             //SMS Verification Code error +             returnINPUT; A         } the         //call WebService to connect CRM to save customer information +Webclient.create ("Http://localhost:9002/crm_management/services/customerService/customer"). Type (mediatype.application_xml) - . Post (model); $SYSTEM.OUT.PRINTLN ("Customer Registration successful ..."); $         returnSUCCESS; -     } -}

<-end->

WebService Instance-CRM system provides webservice to realize user registration function

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.