Day Wing mobile phone verification Code Save Async problem

Source: Internet
Author: User
Tags dateformat


Question: is the captcha insertion unsuccessful?

Find the problem: in the days of the Call method code Verificationcode vcode First insert database, so save in the database, if this is called the Update method, is not stored in the database.

Workaround:So, according to Vcode, if the database exists, use the Insert method if the update does not exist.


ID type verificationcode verificationphone vcode status Create_date

513294 15507559401 Rl0104 1 2015-09-02 16:38:00

165 register null 18370662763 yx5535 0 2015-12-24 16:37:16


/**
* Register account, get verification code
*
* @param request
* @return
* @throws IOException
*/
@RequestMapping (value = "GetCode", method = Requestmethod.get)
@ResponseBody
public void GetCode (HttpServletRequest request) throws IOException {

Jsonmessage jmessage = new Jsonmessage ();

try {
String phone = request.getparameter ("username"). toString ();

int num = 0; User_logic.getcurdaycodenum (phone);

if (num > 10)

{
Jmessage = new Jsonmessage (1, "The verification code you obtained has exceeded the limit, please obtain the Verification code tomorrow)";
} else {
OPEN189SDK opensms = Open189sdk.getinstance ();
Accesstokenstatus tokenobj = Opensms.gettoken ();
if (tokenobj.gettoken () = null) {
String callback = "Http://apis.i-comm.cn:8080/KSO/PutCode";

String callback =
"Http://120.24.57.64/homeapi/api/User/PutCode";
Sendsmsstatus sendvcodeobj = Opensms.sendrandcode (Tokenobj.gettoken (), phone, callback);
if (Sendvcodeobj.getidentifier (). Length () > 0) {
String identifier = Sendvcodeobj.getidentifier ();
Date date = new Date ();
SimpleDateFormat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String timestamp = Dateformat.format (date);

Map<string, object> maps = new hashmap<string, object> ();
Maps.put ("type", "register");
Maps.put ("Verificationphone", phone);
Maps.put ("Vcode", identifier);
Maps.put ("status", 0);
Maps.put ("Create_date", timestamp);

Insert Phone Verification Code
int resultid = 0; User_logic.upuservcode ("register", identifier,
Phone, create2);
ResultId = memberservice.insertsmsverification (maps);

if (ResultId > 0) {
Jmessage = new Jsonmessage (1, "Verification code obtained successfully");
} else {
Jmessage = new Jsonmessage (1, "Verification code obtained successfully");
}
} else {
Jmessage = new Jsonmessage (0, "Verification Code acquisition failed");
}
} else {
Jmessage = new Jsonmessage (0, "Verification Code acquisition failed");
}

}
} catch (Exception ex) {
Jmessage = new Jsonmessage (0, "Verification Code acquisition failed");
}

}





/////////////////////////////////////////////////////////////////////////////////////////////////////




Insert Phone Verification Code
public int insertsmsverification (map<string, object> maps) {
Sms_verification SV = new Sms_verification ();
String type = string.valueof (Maps.get ("type"));
String Vcode = string.valueof (Maps.get ("Vcode"));
String Verificationphone = string.valueof (Maps.get ("Verificationphone"));
int status = integer.valueof ((int) maps.get ("status"));
String create_date = string.valueof (Maps.get ("create_date"));


Sv.settype (type);
Sv.setvcode (Vcode);
Sv.setverificationphone (Verificationphone);
Sv.setstatus (status);
Sv.setcreate_date (create_date);


String select = "from Sms_verification s WHERE s.vcode=" + "'" + vcode+ "'";


String update = "Update sms_verification s SET s.type="
+ "'" + type+ "'"
+ ", S.verificationphone ="
+ "'" +verificationphone+ "'" + ", S.status ="
+ "'" +status+ "'" + ", S.create_date ="
+ "'" +create_date+ "'"
+ "WHERE s.vcode=" + "'" + vcode+ "'";

query query = NULL;
int resultid = 0;
query = Session (). CreateQuery (select);
List list= query.list ();
if (List.size () >0) {
query = Session (). CreateQuery (update);
ResultId = Query.executeupdate ();
return resultid;

}else{
Session (). Saveorupdate (SV);
ResultId = Sv.getid ();
return resultid;
}


}



Insert Verification Code
public void Updatesmsverification (map<string, object> maps) {

Sms_verification SV = new Sms_verification ();
String Verificationcode = string.valueof (Maps.get ("Verificationcode"));
String Vcode = string.valueof (Maps.get ("Vcode"));


String select = "from Sms_verification s WHERE s.vcode=" + "'" + vcode+ "'";

String update = "Update sms_verification s SET s.verificationcode=" + verificationcode
+ "WHERE s.vcode=" + "'" + vcode+ "'";


query query = NULL;

query = Session (). CreateQuery (select);
List list= query.list ();

if (List.size () >0) {
query = Session (). CreateQuery (update);
Query.executeupdate ();
}else{
Sv.setverificationcode (Verificationcode);
Sv.setvcode (Vcode);
Session (). Saveorupdate (SV);
}

}

This article is from the "Pcaijian" blog, make sure to keep this source http://pcaijian.blog.51cto.com/7401276/1734793

Day Wing mobile phone verification Code Save Async problem

Related Article

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.