极光推送 请检查参数合法性_极光小课堂 | 极光推送在人脸识别终端管理系统中的应用...
項目背景
最近開發(fā)的一款人臉識別終端管理系統(tǒng),主要包括運營平臺、企業(yè)后臺管理系統(tǒng)、APP 端、智能人臉識別終端模塊。
下圖是系統(tǒng)的架構(gòu)圖:
其中各個模塊之間都需要即時通訊,比如:
APP 端用戶注冊完成之后,企業(yè)管理員在后臺管理系統(tǒng)中將用戶邀請進入企業(yè),此時需要及時通知用戶已加入企業(yè);
當管理員將該用戶加入到指定的用戶組時,需要將該用戶的人臉信息下發(fā)到關(guān)聯(lián)了該用戶組的智能人臉識別終端中;
管理員更改用戶或者設(shè)備信息時都需要及時通知到相關(guān)的設(shè)備同步最新的數(shù)據(jù);
用戶 APP 遠程開門需要發(fā)送實時消息給到門禁(或者閘機),門禁(或閘機)收到開門消息后方可開門;
當管理員發(fā)布廣告或者公告時,需要通知到指定的門禁設(shè)備播放最新的消息;
...大概十多項通知都離不開消息的推送,此時最先想到的自然是集成第三方穩(wěn)定高效的即時推送方案(APP ?端還需要有強大的離線推送功能)。
為什么選擇極光推送
集成第三方推送無非出于以下幾點考慮:推送穩(wěn)定高效、方便集成、APP 離線模式支持更多的機型(通道)、APP 進程互相拉起、有效的數(shù)據(jù)統(tǒng)計,最重要的一點要免費,無疑極光推送都滿足了這幾方面。
本人是極光推送幾年的老用戶,并且在幾年前寫過一篇【(快速搞定)2分鐘集成極光推送(極光推送 Android 端集成)】的文章,當時使用極光推送的時候還沒有幾家推送 SDK,可以說極光推送是較早的一批推送方案了,這么多年的積累穩(wěn)定性方面毋庸置疑。
Android 快速集成極光推送
下面一步一步教大家快速集成極光推送(盡量按下面的方式進行,說不定可以少走很多彎路哦):
官方可能要考慮一些額外的情況加了個一個手動集成的教程,現(xiàn)在都2020年了當然得用依賴 jcenter 項目的方式來集成啦,如需手動集成請移步官方穩(wěn)定。
開發(fā)環(huán)境:
Android Studio 3.0.1 正式版
gradle v3.0.1
compileSdkVersion 26
targetSdkVersion 22 (減少不必要的動態(tài)權(quán)限請求)
開發(fā)者賬號注冊、創(chuàng)建應(yīng)用這些就不說了哈,根據(jù)官網(wǎng)提示即可創(chuàng)建完成。
第一步:創(chuàng)建項目名叫 smart_face_jpush 的項目(有項目的請忽略這一步)
第二步:配置 app/build.gradle 文件
apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "com.hdl.smartface"//JPush 上注冊的包名. minSdkVersion 17 targetSdkVersion 22 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" //極光推送配置----------開始----------- ndk { //一般armeabi-v7a已能適配絕大部分機型 abiFilters 'armeabi-v7a' // 還可以添加 'armeabi', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64' } manifestPlaceholders = [ JPUSH_PKGNAME: applicationId, JPUSH_APPKEY : "307d4e883d70b727687597fb", //JPush 上注冊的包名對應(yīng)的 Appkey. JPUSH_CHANNEL: "developer-default", //暫時填寫默認值即可. ] //極光推送配置----------結(jié)束----------- } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' testImplementation 'junit:junit:4.12' androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) //極光推送相關(guān)庫 implementation 'cn.jiguang.sdk:jpush:3.5.4' implementation 'cn.jiguang.sdk:jcore:2.2.6' //日志庫implementation 'com.hdl:elog:v2.0.2'}配置完成之后需要同步倉庫,如圖 Try Again:
第三步:配置清單文件
在 AndroidManifest.xml 的 application 中加入極光推送必要的配置:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.hdl.smartface"> <application android:name=".base.MyApp" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> intent-filter> activity> <activity android:name="cn.jpush.android.ui.PopWinActivity" android:exported="true" android:theme="@style/MyDialogStyle" tools:node="replace"> <intent-filter> <category android:name="android.intent.category.DEFAULT" /> <action android:name="cn.jpush.android.ui.PopWinActivity" /> <category android:name="${applicationId}" /> intent-filter> activity> <activity android:name="cn.jpush.android.ui.PushActivity" android:configChanges="orientation|keyboardHidden" android:exported="true" android:theme="@android:style/Theme.NoTitleBar" tools:node="replace"> <intent-filter> <action android:name="cn.jpush.android.ui.PushActivity" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="${applicationId}" /> intent-filter> activity> <receiver android:name=".receiver.JpushReceiver" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTRATION" /> <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <action android:name="cn.jpush.android.intent.CONNECTION" /> <category android:name="com.hdl.smartface" /> intent-filter> receiver> <receiver android:name=".receiver.MyJpushMessageReceiver"> <intent-filter> <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" /> <category android:name="com.hdl.smartface">category> intent-filter> receiver> <receiver android:name="cn.jpush.android.service.PushReceiver" android:enabled="true" android:exported="false"> <intent-filter android:priority="1000"> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <category android:name="com.hdl.smartface" /> intent-filter> <intent-filter> <action android:name="android.intent.action.USER_PRESENT" /> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" /> intent-filter> receiver> <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:exported="false" /> <service android:name="cn.jpush.android.service.PushService" android:exported="false" android:process=":pushcore"> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTER" /> <action android:name="cn.jpush.android.intent.REPORT" /> <action android:name="cn.jpush.android.intent.PushService" /> <action android:name="cn.jpush.android.intent.PUSH_TIME" /> intent-filter> service> <service android:name=".services.PushService" android:process=":pushcore"> <intent-filter> <action android:name="cn.jiguang.user.service.action" /> intent-filter> service> application> manifest>第四步:混淆配置
在 proguard-rules.pro 文件中加入以下配置:
#極光推送混淆配置-------------開始------------ -dontoptimize -dontpreverify -dontwarn cn.jpush.** -keep class cn.jpush.** { *; } -keep class * extends cn.jpush.android.helpers.JPushMessageReceiver { *; } -dontwarn cn.jiguang.** -keep class cn.jiguang.** { *; } #極光推送混淆配置-------------結(jié)束------------第五步:創(chuàng)建接收消息的廣播接收器 JpushReceiver
package com.hdl.smartface.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import com.hdl.elog.ELog; import org.json.JSONException; import org.json.JSONObject; import java.util.Iterator; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.helper.Logger; /** * 自定義接收器 * * 如果不定義這個 Receiver,則: * 1) 默認用戶會打開主界面 * 2) 接收不到自定義消息 * * @author Admin */public class JpushReceiver extends BroadcastReceiver { private static final String TAG = "JpushReceiver"; @Override public void onReceive(Context context, Intent intent) { try { Bundle bundle = intent.getExtras(); ELog.e(TAG, "[JpushReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle)); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); ELog.e(TAG, "[JpushReceiver] 接收Registration Id : " + regId); //send the Registration Id to your server... } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { ELog.e(TAG, "[JpushReceiver] 接收到推送下來的自定義消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)); // processCustomMessage(context, bundle); } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { ELog.e(TAG, "[JpushReceiver] 接收到推送下來的通知"); int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); ELog.e(TAG, "[JpushReceiver] 接收到推送下來的通知的ID: " + notifactionId); } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { ELog.e(TAG, "[JpushReceiver] 用戶點擊打開了通知"); //打開自定義的Activity // Intent i = new Intent(context, TestActivity.class); // i.putExtras(bundle); //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP ); // context.startActivity(i); } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { ELog.e(TAG, "[JpushReceiver] 用戶收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); //在這里根據(jù) JPushInterface.EXTRA_EXTRA 的內(nèi)容處理代碼,比如打開新的Activity, 打開一個網(wǎng)頁等.. } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); Logger.w(TAG, "[JpushReceiver]" + intent.getAction() + " connected state change to " + connected); } else { ELog.e(TAG, "[JpushReceiver] Unhandled intent - " + intent.getAction()); } } catch (Exception e) { } } /** * 打印所有的 intent extra 數(shù)據(jù) * * @param bundle * @return */ private static String printBundle(Bundle bundle) { StringBuilder sb = new StringBuilder(); for (String key : bundle.keySet()) { if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) { sb.append("\nkey:" + key + ", value:" + bundle.getInt(key)); } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) { sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key)); } else if (key.equals(JPushInterface.EXTRA_EXTRA)) { if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) { Logger.i(TAG, "This message has no Extra data"); continue; } try { JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA)); Iterator<String> it = json.keys(); while (it.hasNext()) { String myKey = it.next(); sb.append("\nkey:" + key + ", value: [" + myKey + " - " + json.optString(myKey) + "]"); } } catch (JSONException e) { Logger.e(TAG, "Get message extra JSON error!"); } } else { sb.append("\nkey:" + key + ", value:" + bundle.get(key)); } } return sb.toString(); } }第六步:創(chuàng)建繼承至 JPushMessageReceiver 的廣播接收器 MyJpushMessageReceiver
package com.hdl.smartface.receiver; import android.content.Context; import android.util.Log; import cn.jpush.android.api.JPushMessage; import cn.jpush.android.service.JPushMessageReceiver; /** * 自定義JPush message 接收器,包括操作tag/alias的結(jié)果返回(僅僅包含tag/alias新接口部分) * * @author Admin */public class MyJpushMessageReceiver extends JPushMessageReceiver { private static final String TAG = "MyJpushMessageReceiver"; @Override public void onTagOperatorResult(Context context, JPushMessage jPushMessage) { super.onTagOperatorResult(context, jPushMessage); Log.e(TAG, "onTagOperatorResult: code = " + jPushMessage.getErrorCode()); } @Override public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) { super.onCheckTagOperatorResult(context, jPushMessage); Log.e(TAG, "onCheckTagOperatorResult: code = " + jPushMessage.getErrorCode()); } @Override public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) { super.onAliasOperatorResult(context, jPushMessage); Log.e(TAG, "onAliasOperatorResult: code = " + jPushMessage.getErrorCode()); } @Override public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) { super.onMobileNumberOperatorResult(context, jPushMessage); Log.e(TAG, "onMobileNumberOperatorResult: code = " + jPushMessage.getErrorCode()); } }第七步:初始化 SDK
新建應(yīng)用啟動類 MyApp(繼承至 Application 的類--如已有此類請忽略新建過程)并在 onCreate 中初始化極光推送。package com.hdl.smartface.base; import android.app.Application; import cn.jpush.android.api.JPushInterface; /** * 應(yīng)用啟動類 * Created by Admin on 2020/1/11. * * @author Admin */ public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); initJpush(); } /** * 初始化極光推送 */ private void initJpush() { //調(diào)試模式開關(guān),正式版需設(shè)置未false JPushInterface.setDebugMode(true); //初始化極光推送 JPushInterface.init(this); } } 同時AndroidMenifest.xml中的application標簽加入:...... android:name=".base.MyApp" ...>....測試
本項目中智能人臉識別終端都是使用的自定義消息(不用彈出通知),通知主要是針對用戶 APP 端(會在手機通知欄彈出通知信息)。
測試?Android 端接收通知
打開極光推送后臺,“發(fā)送通知”頁面,輸入標題和內(nèi)容,點擊發(fā)送預(yù)覽即可。
此時 APP 端能收到以下信息說明集成成功:
測試?Android 端接收自定義消息
打開極光推送后臺,“自定義消息”頁面,輸入通知內(nèi)容,點擊發(fā)送預(yù)覽即可。
此時 APP 端能收到以下信息說明接收自定義消息成功:
消息接收正常,只需要根據(jù)消息內(nèi)容來處理相應(yīng)的邏輯即可,所以只需要前后端商量好消息的協(xié)議即可,倒數(shù)第二章會給出一些消息協(xié)議的定制建議以便于前端解析協(xié)議。
服務(wù)端快速集成極光推送
你可能已經(jīng)發(fā)現(xiàn),發(fā)送消息是通過極光推送的后臺管理頁面發(fā)送的,實際業(yè)務(wù)中總不能跑他們官網(wǎng)一條消息一條消息的發(fā)吧!
是的,極光推送是提供得有服務(wù)端推送 SDK 的,我們只需要集成他們的 SDK 來發(fā)送消息,APP 端負責接收消息即可。
本項目的服務(wù)端是基于 Java 開發(fā)的,所以使用極光推送服務(wù)端 SDK for Java 版來做示例。
創(chuàng)建一個 maven 項目,加入極光推送相關(guān)推送:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0modelVersion> <parent> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-parentartifactId> <version>2.2.2.RELEASEversion> <relativePath/> parent> <groupId>com.hdlgroupId> <artifactId>smartfaceartifactId> <version>0.0.1-SNAPSHOTversion> <name>smartfacename> <description>Demo project for Spring Bootdescription> <properties> <java.version>1.8java.version> properties> <dependencies> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starterartifactId> dependency> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-testartifactId> <scope>testscope> <exclusions> <exclusion> <groupId>org.junit.vintagegroupId> <artifactId>junit-vintage-engineartifactId> exclusion> exclusions> dependency> <dependency> <groupId>cn.jpush.apigroupId> <artifactId>jpush-clientartifactId> <version>3.4.3version> dependency> <dependency> <groupId>cn.jpush.apigroupId> <artifactId>jiguang-commonartifactId> <version>1.1.4version> dependency> <dependency> <groupId>io.nettygroupId> <artifactId>netty-allartifactId> <version>4.1.6.Finalversion> <scope>compilescope> dependency> <dependency> <groupId>com.google.code.gsongroupId> <artifactId>gsonartifactId> <version>2.3version> dependency> <dependency> <groupId>org.slf4jgroupId> <artifactId>slf4j-apiartifactId> <version>1.7.7version> dependency> <dependency> <groupId>org.slf4jgroupId> <artifactId>slf4j-log4j12artifactId> <version>1.7.7version> dependency> <dependency> <groupId>log4jgroupId> <artifactId>log4jartifactId> <version>1.2.17version> dependency> dependencies> <build> <plugins> <plugin> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-maven-pluginartifactId> plugin> plugins> build> project>測試服務(wù)端下發(fā)通知
同步完成,接下來開始測試消息發(fā)送:
package com.hdl.smartface; import cn.jiguang.common.ClientConfig; import cn.jiguang.common.resp.APIConnectionException; import cn.jiguang.common.resp.APIRequestException; import cn.jpush.api.JPushClient; import cn.jpush.api.push.PushResult; import cn.jpush.api.push.model.PushPayload; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static cn.jpush.api.push.model.notification.PlatformNotification.ALERT; public class JPushTest { protected static final Logger LOG = LoggerFactory.getLogger(SmartfaceApplicationTests.class); /** * 極光推送應(yīng)用管理中獲取 */ private static final String MASTER_SECRET = "6031870790216966f74410d1"; /** * 極光推送應(yīng)用管理中獲取 */ private static final String APP_KEY = "307d4e883d70b727687597fb"; public static PushPayload buildPushObject_all_all_alert() { return PushPayload.alertAll(ALERT); } @Test public void testPushMsg() { JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance()); // For push, all you need do is to build PushPayload object. PushPayload payload = buildPushObject_all_all_alert(); try { PushResult result = jpushClient.sendPush(payload); LOG.info("Got result - " + result); } catch (APIConnectionException e) { // Connection error, should retry later LOG.error("Connection error, should retry later", e); } catch (APIRequestException e) { // Should review the error, and fix the request LOG.error("Should review the error, and fix the request", e); LOG.info("HTTP Status: " + e.getStatus()); LOG.info("Error Code: " + e.getErrorCode()); LOG.info("Error Message: " + e.getErrorMessage()); } } }此時服務(wù)端控制臺輸入以下消息說明推送成功:
Android 控制臺輸入以下信息說明接收消息成功:
發(fā)送自定義消息
發(fā)送自定義消息,只需調(diào)用方法 PushPayload.Builder.setMessage(Message.content ("要發(fā)送的自定義消息"))即可
/** * 測試推送自定義消息 */ @Test public void testPushCustomMsg() { JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance()); PushPayload pushPayload = PushPayload.newBuilder() .setPlatform(Platform.all()) .setAudience(Audience.all()) .setMessage(Message.content("This is a custom msg")) .build(); try { PushResult result = jpushClient.sendPush(pushPayload); LOG.info("Got result - " + result); } catch (APIConnectionException e) { // Connection error, should retry later LOG.error("Connection error, should retry later", e); } catch (APIRequestException e) { // Should review the error, and fix the request LOG.error("Should review the error, and fix the request", e); LOG.info("HTTP Status: " + e.getStatus()); LOG.info("Error Code: " + e.getErrorCode()); LOG.info("Error Message: " + e.getErrorMessage()); } }APP 端接收到以下消息說明發(fā)送自定義消息成功:
模擬新增人員信息消息
先來看看人員信息實體類:
package com.hdl.smartface.model; /** * 人臉用戶信息 */ public class FaceUser { /** * 姓名 */ private String name; /** * 手機號 */ private String phone; /** * 人臉特征值 */ private String featrue; /** * 人臉圖片 */ private String pic; ...省略getter setter toString }公共自定義消息實體類(定義說明請看下一節(jié)介紹)
package com.hdl.smartface.base; /** * 公共自定義消息返回體 */ public class BaseCustomMessage { /** * 消息類型 */ private String type; /** * 消息簡介 */ private String msg; /** * 可變參數(shù)【擴展參數(shù)】 */ private T data; public String getType() { return type; } public void setType(String type) { this.type = type; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public T getData() { return data; } public void setData(T data) { this.data = data; } @Override public String toString() { return "BaseCustomMessage{" + "type='" + type + '\'' + ", msg='" + msg + '\'' + ", data=" + data + '}'; } }服務(wù)端發(fā)送測試消息:
/** * 測試發(fā)送新增人臉信息消息 */ @Test public void testSendAddFaceUserMessage() { JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance()); //模擬構(gòu)建需要下發(fā)的人員信息 FaceUser faceUser = new FaceUser(); faceUser.setName("大力哥"); faceUser.setPhone("155959595959"); faceUser.setFeatrue("http://face.hdl.com/featrue/155959595959.data"); faceUser.setPic("http://face.hdl.com/pic/155959595959.png"); //模擬構(gòu)建自定義消息體 BaseCustomMessage faceUserMessage = new BaseCustomMessage<>(); faceUserMessage.setType("1001001");//方便測試,這里寫死,type和msg建議按下一章的建議來制定 faceUserMessage.setMsg("新人臉更新"); faceUserMessage.setData(faceUser); PushPayload pushPayload = PushPayload.newBuilder() .setPlatform(Platform.all()) .setAudience(Audience.all()) .setMessage(Message.content(new Gson().toJson(faceUserMessage)))//使用gson將對象轉(zhuǎn)成json .build(); try { PushResult result = jpushClient.sendPush(pushPayload); LOG.info("Got result - " + result); } catch (APIConnectionException e) { // Connection error, should retry later LOG.error("Connection error, should retry later", e); } catch (APIRequestException e) { // Should review the error, and fix the request LOG.error("Should review the error, and fix the request", e); LOG.info("HTTP Status: " + e.getStatus()); LOG.info("Error Code: " + e.getErrorCode()); LOG.info("Error Message: " + e.getErrorMessage()); } }此時 APP 端會收到以下消息:
自定義消息推送協(xié)議的制定
此處只作為參考,最終還是得根據(jù)你們的實際情況來制定。
協(xié)議使用 json 來制定,分為公共參數(shù)和可變參數(shù)部分(或者叫擴展參數(shù)):
{ "type":"消息類型編號", "msg":"消息說明", "data":根據(jù)消息的類型傳遞不同的json對象 }??此處的 type 定義,建議后端使用字典來管理或者使用枚舉也行,類型的編號建議有一定的編碼信息,便于業(yè)務(wù)的統(tǒng)計與分析,如下圖:
當服務(wù)端新增人臉消息時,需要及時下發(fā)消息給相應(yīng)的人臉識別終端下載最新的人臉信息,此時消息協(xié)議可以這么定:
{ "type":"1001001", "msg":"新人臉更新", "data":{ "name":"大力哥", "phone":"155959595959", "featrue":"http://face.hdl.com/featrue/155959595959.data", "pic":"http://face.hdl.com/pic/155959595959.png" }}data 是可變參數(shù)字段(或者叫擴展參數(shù)字段),根據(jù)不同的 type 放回不同的實體即可,再來一個下發(fā)人臉識別終端廣告的協(xié)議:
{ "type":"20010658", "msg":"廣告更新通知", "data":[ { "url":"http://face.hdl.com/adv/qhkhk3g523424aqat.png", "sourceType":"img", "duration":5, "title":"恭祝大家新春快樂" }, { "url":"http://face.hdl.com/adv/ioweybzgkshywet12b34.mp4", "sourceType":"vedio", "duration":-1, "title":"給大家拜年啦" }, { "url":"http://face.hdl.com/adv/shdgwsgsd124sgs.png", "sourceType":"img", "duration":5, "title":"年貨節(jié)火熱進行中" } ]}此時的 data 可以是一個集合,表示下發(fā)三條廣告信息。
寫在最后的話
閱讀完本文相信您已經(jīng)基本了解到如何將極光推送應(yīng)用到實際項目中,并且能夠快速集成 Android 端 SDK 和 Java 服務(wù)端 SDK,限于篇幅很多功能未能一一介紹,如看完本文還有疑問可評論留言或者移步官方網(wǎng)站。
下面給出本文的 demo 地址:
極光推送 Android 端集成 Demo:
https://github.com/huangdali/smart_face_jpush
極光推送 Java 服務(wù)端集成 Demo:
https://github.com/huangdali/jpush_java_sdk_demo
關(guān)于極光
極光(Aurora Mobile,納斯達克股票代碼:JG)成立于2011年,是中國領(lǐng)先的開發(fā)者服務(wù)提供商。極光專注于為移動應(yīng)用開發(fā)者提供穩(wěn)定高效的消息推送、即時通訊、統(tǒng)計分析、極光分享、短信、一鍵認證、深度鏈接等開發(fā)者服務(wù)。截止到2019年12月份,極光已經(jīng)為超過50萬移動開發(fā)者和145.2萬款移動應(yīng)用提供服務(wù),其開發(fā)工具包(SDK)安裝量累計336億,月度獨立活躍設(shè)備13.6億部。同時,極光持續(xù)賦能開發(fā)者和傳統(tǒng)行業(yè)客戶,推出精準營銷、金融風控、市場洞察、商業(yè)地理服務(wù)產(chǎn)品,致力于為社會和各行各業(yè)提高運營效率,優(yōu)化決策制定。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的极光推送 请检查参数合法性_极光小课堂 | 极光推送在人脸识别终端管理系统中的应用...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 同花顺期权在哪里交易
- 下一篇: 印鉴卡是什么样的