使用阿里雲介面進行手機號(三網)實名認證
在使用介面服務的方面我推薦使用技術實力強大的阿里雲;
首先點選:(阿里雲API介面)獲取相應的訂單後在控制檯中可以得到您的appcode;
傳送資料:
Map<String, String> bodys = new HashMap<String, String>(); bodys.put("idNo", "350298189012083221"); bodys.put("name", "張三"); bodys.put("phoneNo", "13511112222");
返回資料:
{
"name": "張三",
"idNo": "359345189012085813",
"phoneNo": "13511112222",
"respMessage": "身份證資訊匹配",
"respCode": "0000"
}
具體實現類:
public static void main(String[] args) { String host = "https://phonecheck.market.alicloudapi.com"; String path = "/phoneAuthentication"; String method = "POST"; String appcode = "你自己的AppCode"; Map<String, String> headers = new HashMap<String, String>(); //最後在header中的格式(中間是英文空格)為Authorization:APPCODE 83359fd73fe94948385f570e3c139105 headers.put("Authorization", "APPCODE " + appcode); //根據API的要求,定義相對應的Content-Type headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); Map<String, String> querys = new HashMap<String, String>(); Map<String, String> bodys = new HashMap<String, String>(); bodys.put("idNo", "350298189012083221"); bodys.put("name", "張三"); bodys.put("phoneNo", "13511112222"); try { /** * 重要提示如下: * HttpUtils請從 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java * 下載 * * 相應的依賴請參照 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml */ HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); System.out.println(response.toString()); //獲取response的body //System.out.println(EntityUtils.toString(response.getEntity())); } catch (Exception e) { e.printStackTrace(); } }
工具類HttpUtils:
package com.netgate.util.send; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import org.apache.commons.lang.StringUtils; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; public class HttpUtils { /** * get * * @param host * @param path * @param method * @param headers * @param querys * @return * @throws Exception */ public static HttpResponse doGet(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) throws Exception { HttpClient httpClient = wrapClient(host); HttpGet request = new HttpGet(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } return httpClient.execute(request); } /** * post form * * @param host * @param path * @param method * @param headers * @param querys * @param bodys * @return * @throws Exception */ public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, Map<String, String> bodys) throws Exception { HttpClient httpClient = wrapClient(host); HttpPost request = new HttpPost(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (bodys != null) { List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>(); for (String key : bodys.keySet()) { nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); } UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); request.setEntity(formEntity); } return httpClient.execute(request); } /** * Post String * * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPost request = new HttpPost(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (StringUtils.isNotBlank(body)) { request.setEntity(new StringEntity(body, "utf-8")); } return httpClient.execute(request); } /** * Post stream * * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPost request = new HttpPost(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (body != null) { request.setEntity(new ByteArrayEntity(body)); } return httpClient.execute(request); } /** * Put String * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPut request = new HttpPut(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (StringUtils.isNotBlank(body)) { request.setEntity(new StringEntity(body, "utf-8")); } return httpClient.execute(request); } /** * Put stream * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPut request = new HttpPut(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (body != null) { request.setEntity(new ByteArrayEntity(body)); } return httpClient.execute(request); } /** * Delete * * @param host * @param path * @param method * @param headers * @param querys * @return * @throws Exception */ public static HttpResponse doDelete(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) throws Exception { HttpClient httpClient = wrapClient(host); HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } return httpClient.execute(request); } private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException { StringBuilder sbUrl = new StringBuilder(); sbUrl.append(host); if (!StringUtils.isBlank(path)) { sbUrl.append(path); } if (null != querys) { StringBuilder sbQuery = new StringBuilder(); for (Map.Entry<String, String> query : querys.entrySet()) { if (0 < sbQuery.length()) { sbQuery.append("&"); } if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { sbQuery.append(query.getValue()); } if (!StringUtils.isBlank(query.getKey())) { sbQuery.append(query.getKey()); if (!StringUtils.isBlank(query.getValue())) { sbQuery.append("="); sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); } } } if (0 < sbQuery.length()) { sbUrl.append("?").append(sbQuery); } } return sbUrl.toString(); } private static HttpClient wrapClient(String host) { HttpClient httpClient = new DefaultHttpClient(); if (host.startsWith("https://")) { sslClient(httpClient); } return httpClient; } private static void sslClient(HttpClient httpClient) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] xcs, String str) { } public void checkServerTrusted(X509Certificate[] xcs, String str) { } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry registry = ccm.getSchemeRegistry(); registry.register(new Scheme("https", 443, ssf)); } catch (KeyManagementException ex) { throw new RuntimeException(ex); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } } }
相關推薦
使用阿里雲介面進行手機號(三網)實名認證
如今隨著網際網路產業的多元化發展,尤其是網際網路金融,O2O,共享經濟等新興商業形式的興起,企業對實名認證業務的資料形式和資料質量有了更高的需求。如今也衍生出手機號實名認證業務,通過介面將手機號、身份證號碼、姓名上傳至阿里雲,再與運營商系統進行匹配,判斷資訊的一致性。在使用介
阿里雲ECS彈性裸金屬(神龍)伺服器為雙11保駕護航
每年阿里巴巴天貓雙11購物節,既是一次全民的狂歡,也是阿里技術人的一次大考和閱兵場,對阿里雲ECS彈性計算團隊更是如此,作為IaaS層最核心的產品,每年雙11承擔的業務交易量也越來越大,阿里巴巴電商核心交易鏈路系統穩定、峰值交易效能、每筆交易的服務響應延遲等都對ECS彈性計算有著苛刻地要求。為了保障雙11核心
阿里雲搭建大資料平臺(3):安裝JDK和Hadoop偽分佈環境
一、安裝jdk 1.解除安裝Linux自帶的JDK rpm -qa|grep jdk #查詢原始JDK yum -y remove <舊JDK> 2.解壓縮 tar -zxvf /opt/softwares/jdk-8u151-linux-x64.t
PowerShell + docker-compose +.net core 釋出阿里雲映象庫 學習筆記(前言)
1、掌握docker-compose命令 2、掌握compose模板檔案 3、編寫docker-compose.yml檔案 4、利用PowerShell釋出映象 Compose 簡介 Compose 專案是 Docker 官方的開源專案,負責實現對 Docker
如何在阿里雲上部署django網站(3)——runserver試執行
python提供了最基本最簡單的部署方案:runserver。不過我們真正部署的時候,都不會用到它,這是因為runserver本身有很大的缺陷。不過,作為測試,使用runserver對於新手來說是一件簡單且具有里程碑意義的事件。 假設我們已經將mysite通過git克隆到阿里雲ecs上
如何在阿里雲上部署django網站(2)——使用MySQL資料庫
如果要在阿里雲上部署django網站,建議不要使用django自帶的sqlite,雖然一時省事,但帶來了很多其他的麻煩。建議使用MySQL或者PostgreSQL。由於MySQL比較流行,我就選擇了MySQL。 安裝MySQL 在使用MySQL之前,首先需要安裝。在ubuntu系
阿里雲證書服務使用教程(下篇)
產品優勢:雲盾證書服務具有以下優勢:簡潔性貼合阿里雲使用者購買習慣,提供簡潔的證書購買流程。安全性提供安全的證書和金鑰儲存方案,免去尋找其他金鑰儲存方案的煩惱。易用性和阿里雲產品聯通,實現一鍵部署數字證書到阿里雲產品。名詞解釋:數字證書數字證書是一個經證書授權中心數字簽名的包
阿里雲學生伺服器搭建網站(1)-購買阿里雲學生伺服器
(1)建立阿里雲賬號,完成實名認證和學生認證 (2)登入阿里雲賬號,點選進入“雲翼計劃”購買學生伺服器(阿里雲翼計劃) 我的目的是購買一個用於PHP網站開發的伺服器,選擇的伺服器配置是:Ubuntu 16.04 64位系統。 預設的系統的登入賬號是 root,沒有登
ESP8266連線阿里雲物聯網套件(一)
一、SDK準備 ├── bin // 存放編譯後生成的檔案 ├── esp8266-rtos-sdk // esp8266 rtos 核
input輸入框,正則格式化手機號(344)
最近有個H5手機頁面需要做344的格式化,以前沒有注意到,寫的時候發現問題很多,然後就找大神的程式碼,抄襲下。 1.html版本 /*input框使用onkeyup事件 */ function f
三網手機號實名認證查詢
dap else amp spa aliyun 實名認證 重置 bmi appcode 接口說明文檔: https://market.aliyun.com/products/57000002/cmapi028323.html?spm=5176.2020520132.101.
阿里雲上cdh5 hbase搭建(單機版)
一、簡介 HBase是一種構建在HDFS之上的分散式、面向列的儲存系統。在需要實時讀寫、隨機訪問超大規模資料集時,可以使用HBase。 儘管已經有許多資料儲存和訪問的策略和實現方法,但事實上大多數解決方案,特別是一些關係型別的,在構建時並沒有考慮超大規模和分散式的特點。許多商家通過複製和分割
阿里雲 javascript上傳檔案(圖片、視訊、壓縮包等檔案)到 物件儲存 OSS ,返回上傳檔案、圖片、音訊、視訊等URL路徑
目的:前端上傳檔案(圖片、視訊、音訊等)到阿里雲伺服器裡面,並且獲得上傳檔案的URL路徑 前提:首先要買一個阿里雲伺服器,自己百度不會; 第一步:登入阿里雲賬號,點選管理控制檯-->物件儲存 OSS 第二步:新建儲存空間(圖一、圖二) (圖一) (圖二
vue裡面上下輪播圖(app,廣告提示,手機號滾動等)
vue-seamless-scroll 外掛 1.下載外掛 npm install vue-seamless-scroll --save 2. 在main.js裡面引入使用 import scroll from 'vue-seamless-scroll' Vue.use
在阿里雲上進行域名解析
把自己已經在阿里雲備案號的域名進行解析(注意必須是已經備案的,否則外網訪問不了)。 具體步驟: 1、進入阿里雲控制檯,找到域名下的雲解析DSN。 2、找到域名列表,如果不是阿里雲購買的域名需要新增域名到該列表。然後點選解析 3、點選新增解
如何在阿里雲上進行備案?
目錄 如何在阿里雲上進行備案? 1、企業實名制認證 1.1、企業支付寶認證 1.2、企業對公銀行賬號認證 2、域名備案流程 如何在阿里雲上進行備案? 1、企業實名制認證 對於企業客戶,企業的阿里雲賬號做認證有好幾種方
阿里雲物聯網平臺體驗(樹莓派+Python篇)!
阿里雲物聯網平臺體驗 ( 樹莓派 +Python 篇 ) 雖然對阿里雲物聯網平臺比較熟悉了,從一開始就有幸參與了飛鳳平臺( Link Develop 一站式開發平臺的前身)的一些偏硬體接入的工作。但是同時也見證了阿里雲物聯網團隊從幾十人到數百人的
阿里雲ECS進行ssh時,一段時間不操作就自動斷開連線的解決方法
vim /etc/ssh/sshd_config 找到以下兩項配置 #ClientAliveInterval 0 #ClientAliveCountMax 3 修改為 ClientAliveInterval 30 ClientAliveCountMax 86400
專案初始化時可以對所有介面進行資訊記錄(比如配合註解收集介面許可權資訊存入資料庫、生成介面文件、等等)
配合自定義註解和Swagger2註解進行許可權資源初始化。 import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; impo
阿里雲Centos7 安裝 k8s 叢集(使用過程中的坑)
個人備忘 下面這個地址能滿足大部分需求 : 上文:5.2 的配置三臺伺服器都要修改 ,5.3 的命令 [[email protected] ~]# etcdctl mk /atomic.io/network/config '{ "Network": "1