天翼手機驗證碼儲存非同步問題

來源:互聯網
上載者:User

標籤:天翼手機驗證碼儲存非同步問題


問題:驗證碼插入不成功?

找出問題  :在天翼調用方法時驗證碼VerificationCode  vcode先插入資料庫,所以儲存在資料庫,如果這個是調用的  update方法,是不能儲存在資料庫裡面的。

解決方案:所以要根據vcode來查,如果資料庫存在該資料,就用update如果不存在就用insert方法。


id     type        VerificationCode   VerificationPhone   vcode   status   create_date

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

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


/**
     * 註冊帳號,擷取驗證碼
     *
     * @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, "您擷取的驗證碼已超過限制,請明天再擷取驗證碼");
            } 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);

                        // 插入手機驗證碼
                        int resultId = 0; // User_Logic.UpUserVcode("register",identifier,
                                            // phone, create2);
                        resultId = memberService.insertSmsVerification(maps);

                        if (resultId > 0) {
                            jMessage = new JSONMessage(1, "驗證碼擷取成功");
                        } else {
                            jMessage = new JSONMessage(1, "驗證碼擷取成功");
                        }
                    } else {
                        jMessage = new JSONMessage(0, "驗證碼擷取失敗");
                    }
                } else {
                    jMessage = new JSONMessage(0, "驗證碼擷取失敗");
                }

            }
        } catch (Exception ex) {
            jMessage = new JSONMessage(0, "驗證碼擷取失敗");
        }

    }





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




//插入手機驗證碼
    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;
        }
        
       
    }



    // 插入驗證碼
    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);
         }
        
    }

本文出自 “pcaijian” 部落格,請務必保留此出處http://pcaijian.blog.51cto.com/7401276/1734793

天翼手機驗證碼儲存非同步問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.