1. 程式人生 > >關於android內建微信瀏覽器,10秒自動重複提交的大坑,簡單出爆,幹掉他

關於android內建微信瀏覽器,10秒自動重複提交的大坑,簡單出爆,幹掉他

先說說這個機制問題,10秒超時,微信瀏覽器會自動使用代理進行提交,並且會打斷第一次提交,如果你是訂單的話,你就只能呵呵了。

我就是有個功能,上傳一堆的附件到oss去,結果超過10s了,你會發現時間越來越久,原來微信給你再次提交,訂單直接報id錯誤。

移動端的ie6,不想說什麼了,直接貼程式碼:

 /**
     * 儲存車輛申請記錄
     */
    @CheckLogin
    @Certification
    @RequestMapping(value="/saveApply",method=RequestMethod.POST)
    public void saveApply(
            LoanApplicationRecord loanApplicationRecord
            ,@RequestParam String CAR_POSITIVE
            ,@RequestParam String CAR_BACK
            ,@RequestParam String CAR_LEFT
            ,@RequestParam String CAR_RIGHT
            ,@RequestParam String ENGINE_NAMEPLATE
            ,@RequestParam String VEHICLE_REGISTRATION_FRONT
            ,@RequestParam String VEHICLE_REGISTRATION_BACK
            ,@RequestParam String DRIVING_PERMIT
            ,@RequestParam String VEHICLE_PURCHASE_CONTRACT
            ,String LOAN_FILE_OTHER
            ,HttpServletRequest request
            ,HttpServletResponse response){
        ResultVO rv =  ResultVO.getFailInstance();
        try {
            /**
             * 開始儲存申請記錄
             */
            loanApplicationRecordService.submit(getSessionUserID(request)
                    ,loanApplicationRecord);
            // 登入成功
            rv.setSuccess();
        }catch(BusinessRuntimeException e){
            rv.setMsg(e.getMessage());
        }catch (Exception e) {
            // 未知異常,列印日誌,返回系統錯誤
            LogUtils.error(e.getMessage());
            rv.setSysError();
        }
        try{

  // 重點就是在這裡........   直接儲存記錄返回結果,夠簡單粗暴吧,

  //前提是你要保證下面的程式碼沒啥問題,反正我是沒法保證了。

  //反正就幾個檔案,大不了重新叫他上傳吧。哈哈

            response.getWriter().print(rv.toJson());
            response.getWriter().flush();
            response.getWriter().close();

//  這裡就不管能不能成功了。這麼多檔案,管他呢,我只能說,秒傳,what the fuck ...WX
            
            // 這裡進行檔案的上傳,時間過長,故先返回結果。
            String basePath = request.getServletContext().getRealPath("/");
            Long userId = getSessionUserID(request);
            User user = getSessionUserByDB(request);
    
            loanApplicationAttachmentService.insert(basePath, CAR_POSITIVE,
                    FileTypeEnum.APPLY_LOAN.getPath() + userId + "/", user,
                    loanApplicationRecord, LoanFileTypeEnum.CAR_POSITIVE);
            loanApplicationAttachmentService.insert(basePath, CAR_BACK,
                    FileTypeEnum.APPLY_LOAN.getPath() + userId + "/", user,
                    loanApplicationRecord, LoanFileTypeEnum.CAR_BACK);
            loanApplicationAttachmentService.insert(basePath, CAR_LEFT,
                    FileTypeEnum.APPLY_LOAN.getPath() + userId + "/", user,
                    loanApplicationRecord, LoanFileTypeEnum.CAR_LEFT);
            loanApplicationAttachmentService.insert(basePath, CAR_RIGHT,
                    FileTypeEnum.APPLY_LOAN.getPath() + userId + "/", user,
                    loanApplicationRecord, LoanFileTypeEnum.CAR_RIGHT);
            loanApplicationAttachmentService.insert(basePath, ENGINE_NAMEPLATE,
                    FileTypeEnum.APPLY_LOAN.getPath() + userId + "/", user,
                    loanApplicationRecord, LoanFileTypeEnum.ENGINE_NAMEPLATE);
            loanApplicationAttachmentService.insert(basePath,
                    VEHICLE_REGISTRATION_FRONT, FileTypeEnum.APPLY_LOAN.getPath()
                            + userId + "/", user, loanApplicationRecord,
                    LoanFileTypeEnum.VEHICLE_REGISTRATION_FRONT);
            loanApplicationAttachmentService.insert(basePath,
                    VEHICLE_REGISTRATION_BACK, FileTypeEnum.APPLY_LOAN.getPath()
                            + userId + "/", user, loanApplicationRecord,
                    LoanFileTypeEnum.VEHICLE_REGISTRATION_BACK);
            loanApplicationAttachmentService.insert(basePath, DRIVING_PERMIT,
                    FileTypeEnum.APPLY_LOAN.getPath() + userId + "/", user,
                    loanApplicationRecord, LoanFileTypeEnum.DRIVING_PERMIT);
            loanApplicationAttachmentService.insert(basePath,
                    VEHICLE_PURCHASE_CONTRACT, FileTypeEnum.APPLY_LOAN.getPath()
                            + userId + "/", user, loanApplicationRecord,
                    LoanFileTypeEnum.VEHICLE_PURCHASE_CONTRACT);
            loanApplicationAttachmentService.insert(basePath, LOAN_FILE_OTHER,
                    FileTypeEnum.APPLY_LOAN.getPath() + userId + "/", user,
                    loanApplicationRecord, LoanFileTypeEnum.LOAN_FILE_OTHER);
        }catch(Exception e){
            
        }
        
    }