C++去除輸出行中空白的辦法。本站提示廣大學習愛好者:(C++去除輸出行中空白的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C++去除輸出行中空白的辦法正文
短信注冊和短信驗證曾經是屢見不鮮了,所以固然要進修若何應用SDK啦
MobSDK可以避免費發短信,固然就用它啦
http://www.mob.com
1.起首下載sdk
2.在項目新建一個叫lib的文件夾把4個器械放出來
3.在app的build.gradule添加以下代碼
repositories{ flatDir{ dirs 'lib' //就是你放aar的目次地址 } } dependencies { //....... //其他依附包 compile name: 'SMSSDK-2.1.0', ext: 'aar' compile name: 'SMSSDKGUI-2.1.0', ext: 'aar' compile files('lib/MobCommons-2016.0624.1326.jar') compile files('lib/MobTools-2016.0624.1326.jar') }
4.在AndroidManifest.xml中添加權限和activity
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
在application下添加
<activity android:name="com.mob.tools.MobUIShell" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|screenSize" android:windowSoftInputMode="stateHidden|adjustResize"/>
5.開端應用
初始化SDK
SMSSDK.initSDK(this, "您的appkey", "您的appsecret");
發送驗證碼
SMSSDK.getVerificationCode("86","您的手機號");
6.驗證驗證碼
收到驗證碼後要post到Mob的辦事器上驗證
起首在到官網上守舊辦事端驗證開關
要求地址為:https://webapi.sms.mob.com/sms/verify
要求方法: POST
要求參數
•appkey 運用appkey
•phone 德律風號碼
•zone 區號
•code 須要驗證的驗證碼
我曾經幫你寫好post的辦法內容,只需傳地址和參數就可以前往成果
/** * 提議https要求 * @param address post地址 * @param params 參數 * @return 成果 */ public static String requestData(String address ,String params){ HttpURLConnection conn = null; try { // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){ public X509Certificate[] getAcceptedIssuers(){return null;} public void checkClientTrusted(X509Certificate[] certs, String authType){} public void checkServerTrusted(X509Certificate[] certs, String authType){} }}; // Install the all-trusting trust manager SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new SecureRandom()); //ip host verify HostnameVerifier hv = new HostnameVerifier() { public boolean verify(String urlHostName, SSLSession session) { return urlHostName.equals(session.getPeerHost()); } }; //set ip host verify HttpsURLConnection.setDefaultHostnameVerifier(hv); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); URL url = new URL(address); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST");// POST conn.setConnectTimeout(3000); conn.setReadTimeout(3000); // set params ;post params if (params!=null) { conn.setDoOutput(true); DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.write(params.getBytes(Charset.forName("UTF-8"))); out.flush(); out.close(); } conn.connect(); //get result if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { InputStream in=conn.getInputStream(); StringBuffer out = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = in.read(b)) != -1;) { out.append(new String(b, 0, n)); } return out.toString(); } else { System.out.println(conn.getResponseCode() + " "+ conn.getResponseMessage()); } } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) conn.disconnect(); } return null; }
既然是收集要求固然要新建線程應用啦
new Thread(new Runnable() { @Override public void run() { String params="appkey=您的appkey;phone=您的手機號;zone=86;code=手機收到的驗證碼"; String result = requestData("https://webapi.sms.mob.com/sms/verify", params); //輸入成果 System.out.println(result); } }).start();
輸入成果樣例{status:200}
成果編碼
前往值 成果描寫
200 驗證勝利
405 AppKey為空
406 AppKey有效
456 國度代碼或手機號碼為空
457 手機號碼格局毛病
466 要求校驗的驗證碼為空
467 要求校驗驗證碼頻仍(5分鐘內統一個appkey的統一個號碼最多只能校驗三次)
468 驗證碼毛病
474 沒有翻開辦事端驗證開關
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐。