@@ -62,14 +62,14 @@ android { | |||||
- 启动服务 | - 启动服务 | ||||
```kotlin | ```kotlin | ||||
PushSdk.instance.register(userId: String) | |||||
PushSdk.instance.register(userId) | |||||
``` | ``` | ||||
- 注册消息监听(二选一) | - 注册消息监听(二选一) | ||||
1. 注册callback,自己处理消息分发 | 1. 注册callback,自己处理消息分发 | ||||
```kotlin | ```kotlin | ||||
PushSdk.instance.setMsgCallback(callback: CallbackListener) | |||||
PushSdk.instance.setMsgCallback(callback) | |||||
``` | ``` | ||||
2. 在需要监听消息的页面,使用eventbus订阅。 | 2. 在需要监听消息的页面,使用eventbus订阅。 | ||||
@@ -80,7 +80,7 @@ PushSdk.instance.setMsgCallback(callback: CallbackListener) | |||||
- 发送消息 | - 发送消息 | ||||
```kotlin | ```kotlin | ||||
PushSdk.instance.sendTextMessage(toUserId:String, msg: String) | |||||
SendMessageHelper.sendTextMessage(toUserId, msg) | |||||
``` | ``` | ||||
@@ -4,6 +4,8 @@ import android.os.Bundle | |||||
import android.widget.TextView | import android.widget.TextView | ||||
import androidx.appcompat.app.AppCompatActivity | import androidx.appcompat.app.AppCompatActivity | ||||
import cn.org.bjca.trust.push.PushSdk | import cn.org.bjca.trust.push.PushSdk | ||||
import cn.org.bjca.trust.push.common.FileHelper | |||||
import cn.org.bjca.trust.push.common.SendMessageHelper | |||||
class MainActivity : AppCompatActivity() { | class MainActivity : AppCompatActivity() { | ||||
override fun onCreate(savedInstanceState: Bundle?) { | override fun onCreate(savedInstanceState: Bundle?) { | ||||
@@ -11,9 +13,10 @@ class MainActivity : AppCompatActivity() { | |||||
setContentView(R.layout.activity_main) | setContentView(R.layout.activity_main) | ||||
PushSdk.instance.register("xuqinmin") | PushSdk.instance.register("xuqinmin") | ||||
findViewById<TextView>(R.id.register).setOnClickListener { | findViewById<TextView>(R.id.register).setOnClickListener { | ||||
FileHelper.openFile() | |||||
} | } | ||||
findViewById<TextView>(R.id.send).setOnClickListener { | findViewById<TextView>(R.id.send).setOnClickListener { | ||||
PushSdk.instance.sendTextMessage("xuqinmin", "你好啊${System.currentTimeMillis()}") | |||||
SendMessageHelper.sendTextMessage("xuqinmin", "你好啊${System.currentTimeMillis()}") | |||||
} | } | ||||
} | } | ||||
@@ -23,9 +23,10 @@ kotlin.code.style=official | |||||
# thereby reducing the size of the R class for that library | # thereby reducing the size of the R class for that library | ||||
android.nonTransitiveRClass=true | android.nonTransitiveRClass=true | ||||
systemProp.sonar.projectKey=PushDemo | systemProp.sonar.projectKey=PushDemo | ||||
sonar.sources=src/main | |||||
systemProp.sonar.sources=src/main | |||||
systemProp.sonar.host.url=http://127.0.0.1:9000 | systemProp.sonar.host.url=http://127.0.0.1:9000 | ||||
systemProp.sonar.login=sqp_ec473b95ed821e1bb108acf9b9909f46a1b037b6 | systemProp.sonar.login=sqp_ec473b95ed821e1bb108acf9b9909f46a1b037b6 | ||||
systemProp.sonar.projectVersion=1.0.0.002 | |||||
sonar.pdf.password=xuqinmin1022 | sonar.pdf.password=xuqinmin1022 | ||||
sonar.pdf.username=xuqinmin12 | sonar.pdf.username=xuqinmin12 | ||||
#sonar.androidLint.reportPaths=./build/slf/lint-results.xml | #sonar.androidLint.reportPaths=./build/slf/lint-results.xml | ||||
@@ -1,6 +1,9 @@ | |||||
package cn.org.bjca.trust.push | package cn.org.bjca.trust.push | ||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.common.SendMessageHelper | |||||
import java.io.PrintWriter | |||||
import java.io.StringWriter | |||||
import java.io.Writer | |||||
/** | /** | ||||
* 日志收集 | * 日志收集 | ||||
@@ -23,11 +26,17 @@ object CrashHandler : Thread.UncaughtExceptionHandler { | |||||
mDefaultHandler?.uncaughtException(t, e) | mDefaultHandler?.uncaughtException(t, e) | ||||
} | } | ||||
private fun handleException(e: Throwable?) { | |||||
e?.let { | |||||
LogHelper.e(BuildConfig.versionCode.toString()) | |||||
LogHelper.e(BuildConfig.versionName) | |||||
private fun handleException(ex: Throwable) { | |||||
val writer: Writer = StringWriter() | |||||
val printWriter = PrintWriter(writer) | |||||
ex.printStackTrace(printWriter) | |||||
var cause: Throwable? = ex.cause | |||||
while (cause != null) { | |||||
cause.printStackTrace(printWriter) | |||||
cause = cause.cause | |||||
} | } | ||||
printWriter.close() | |||||
SendMessageHelper.sendLogMessage(writer.toString()) | |||||
} | } | ||||
@@ -6,5 +6,6 @@ package cn.org.bjca.trust.push.common | |||||
object FileHelper { | object FileHelper { | ||||
@JvmStatic | @JvmStatic | ||||
fun openFile() { | fun openFile() { | ||||
throw Throwable("************************") | |||||
} | } | ||||
} | } |
@@ -3,9 +3,7 @@ package cn.org.bjca.trust.push.common | |||||
import cn.org.bjca.trust.push.db.DbHelper | import cn.org.bjca.trust.push.db.DbHelper | ||||
import cn.org.bjca.trust.push.db.message.SzyxMessage | import cn.org.bjca.trust.push.db.message.SzyxMessage | ||||
import cn.org.bjca.trust.push.enums.MsgType | import cn.org.bjca.trust.push.enums.MsgType | ||||
import cn.org.bjca.trust.push.message.ImManager | |||||
import cn.org.bjca.trust.push.message.bean.TextMessage | |||||
import cn.org.bjca.trust.push.message.bean.UnknownMessage | |||||
import cn.org.bjca.trust.push.message.bean.* | |||||
import cn.org.bjca.trust.push.message.msg.Message | import cn.org.bjca.trust.push.message.msg.Message | ||||
import cn.org.bjca.trust.push.message.msg.SendMessage | import cn.org.bjca.trust.push.message.msg.SendMessage | ||||
import org.json.JSONException | import org.json.JSONException | ||||
@@ -20,6 +18,27 @@ object MessageHelper { | |||||
MsgType.Text -> { | MsgType.Text -> { | ||||
TextMessage::class.java | TextMessage::class.java | ||||
} | } | ||||
MsgType.Voice -> { | |||||
VoiceMessage::class.java | |||||
} | |||||
MsgType.Image -> { | |||||
PictureMessage::class.java | |||||
} | |||||
MsgType.Location -> { | |||||
LocationMessage::class.java | |||||
} | |||||
MsgType.Video -> { | |||||
VideoMessage::class.java | |||||
} | |||||
MsgType.File -> { | |||||
FileMessage::class.java | |||||
} | |||||
MsgType.At -> { | |||||
AtMessage::class.java | |||||
} | |||||
MsgType.Other -> { | |||||
OtherMessage::class.java | |||||
} | |||||
else -> { | else -> { | ||||
UnknownMessage::class.java | UnknownMessage::class.java | ||||
} | } | ||||
@@ -55,20 +74,6 @@ object MessageHelper { | |||||
return parseMessage(sendMessage) | return parseMessage(sendMessage) | ||||
} | } | ||||
@JvmStatic | |||||
fun sendMessage(clientId: String, message: Message) { | |||||
LogHelper.d("------app端调用发送消息-----") | |||||
val sendMessage = SendMessage() | |||||
sendMessage.messageId = message.messageId ?: CommonHelper.generateMessageId() | |||||
sendMessage.timestamp = System.currentTimeMillis() | |||||
sendMessage.fromClientId = clientId | |||||
sendMessage.toClientId = message.toClientId | |||||
sendMessage.target = clientId | |||||
sendMessage.messageType = message.msgType.value | |||||
sendMessage.message = message.createContentJsonStr() | |||||
ImManager.instance.sendMessage(sendMessage) | |||||
} | |||||
fun changeStatus(msgId: String, status: Boolean): Message? { | fun changeStatus(msgId: String, status: Boolean): Message? { | ||||
val m = DbHelper.getDataBase().messageDao().getMessage(msgId) | val m = DbHelper.getDataBase().messageDao().getMessage(msgId) | ||||
if (m.isNotEmpty()) { | if (m.isNotEmpty()) { | ||||
@@ -0,0 +1,88 @@ | |||||
package cn.org.bjca.trust.push.common | |||||
import cn.org.bjca.trust.push.BuildConfig | |||||
import cn.org.bjca.trust.push.db.DbHelper | |||||
import cn.org.bjca.trust.push.message.ImManager | |||||
import cn.org.bjca.trust.push.message.bean.* | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
object SendMessageHelper { | |||||
private fun sendMessage(message: Message) { | |||||
LogHelper.d("------app端调用发送消息-----") | |||||
val sendMessage = SendMessage() | |||||
sendMessage.messageId = message.messageId ?: CommonHelper.generateMessageId() | |||||
sendMessage.timestamp = System.currentTimeMillis() | |||||
sendMessage.toClientId = message.toClientId | |||||
sendMessage.messageType = message.msgType.value | |||||
sendMessage.message = message.createContentJsonStr() | |||||
ImManager.instance.sendMessage(sendMessage) | |||||
} | |||||
@JvmStatic | |||||
fun sendTextMessage(toUserId: String, msg: String) { | |||||
sendMessage(TextMessage().apply { | |||||
toClientId = toUserId | |||||
text = msg | |||||
}) | |||||
} | |||||
@JvmStatic | |||||
fun sendImageMessage( | |||||
toUserId: String, | |||||
imageStorageId: String, | |||||
thumbnail: String, | |||||
thumbnailWidth: Int, | |||||
thumbnailHeight: Int | |||||
) { | |||||
sendMessage( | |||||
PictureMessage( | |||||
).apply { | |||||
toClientId = toUserId | |||||
this.imageStorageId = imageStorageId | |||||
this.thumbnail = thumbnail | |||||
this.thumbnailWidth = thumbnailWidth | |||||
this.thumbnailHeight = thumbnailHeight | |||||
}) | |||||
} | |||||
@JvmStatic | |||||
fun sendAtMessage( | |||||
toUserId: String, text: String, atNos: List<String> | |||||
) { | |||||
sendMessage( | |||||
AtMessage().apply { | |||||
this.text = text | |||||
this.atNos = atNos | |||||
toClientId = toUserId | |||||
}) | |||||
} | |||||
@JvmStatic | |||||
fun sendOtherMessage( | |||||
toUserId: String, msg: String | |||||
) { | |||||
sendMessage( | |||||
OtherMessage().apply { | |||||
toClientId = toUserId | |||||
this.msg = msg | |||||
}) | |||||
} | |||||
@JvmStatic | |||||
fun sendLogMessage( | |||||
msg: String, | |||||
) { | |||||
val devices = DbHelper.getDataBase().deviceDao().getAll() | |||||
if (devices.isNotEmpty()) { | |||||
sendMessage( | |||||
LogMessage().apply { | |||||
text = msg | |||||
versionName = BuildConfig.versionName | |||||
versionCode = BuildConfig.versionCode | |||||
device = devices[0] | |||||
} | |||||
) | |||||
} | |||||
} | |||||
} |
@@ -6,6 +6,7 @@ const val ERROR_DEVICE = "10001" | |||||
const val ERROR_MSG_SEND_1 = "10011" | const val ERROR_MSG_SEND_1 = "10011" | ||||
const val ERROR_MSG_SEND_2 = "10012" | const val ERROR_MSG_SEND_2 = "10012" | ||||
const val ERROR_MSG_SEND_3 = "10013" | const val ERROR_MSG_SEND_3 = "10013" | ||||
const val ERROR_MSG_SEND_4 = "10014" | |||||
const val ERROR_CONNECTED = "10021" | const val ERROR_CONNECTED = "10021" | ||||
const val SUCCESS_CONNECTED = "20001" | const val SUCCESS_CONNECTED = "20001" | ||||
@@ -1,8 +1,36 @@ | |||||
package cn.org.bjca.trust.push.enums | package cn.org.bjca.trust.push.enums | ||||
enum class MsgType(val value: Int) { | enum class MsgType(val value: Int) { | ||||
UNKNOWN(-1), | |||||
Text(1); | |||||
UNKNOWN(-1) /* 未知 */, | |||||
Text(1) /* 文本 */, | |||||
Voice(2) /* 语音 */, | |||||
Image(3) /* 图片 */, | |||||
Location(4) /* 位置 */, | |||||
Video(5) /* 视频 */, | |||||
File(6) /* 文件 */, | |||||
At(7) /* @我 */, | |||||
Log(8) /* 日志 */, | |||||
Other(10010), /* 自定义消息 */ | |||||
/** | |||||
* pc 登陆 end | |||||
*/ | |||||
/** | |||||
* 音频/视频消息 start | |||||
*/ | |||||
AVMeetingInvite(250),/*邀请通知*/ | |||||
AVMeetingRefuse(251),/*拒绝通知*/ | |||||
AVMeetingCancel(252),/*取消通知*/ | |||||
AVMeetingTimeout(253),/*超时通知*/ | |||||
AVMeetingBusy(254),/*占线通知*/ | |||||
AVMeetingSwitch(255),/*切换音频通知*/ | |||||
AVMeetingConnected(256),/* 聊天已连接通知*/ | |||||
MulAVMeetingInvite(260), /*群视频邀请*/ | |||||
MulAVMeetingRefuse(261), /*群成员拒绝通知*/ | |||||
MulAVMeetingCancel(262),/*取消通知*/ | |||||
MulAVMeetingTimeOut(263),/*超时通知 */ | |||||
Notify(999); | |||||
companion object { | companion object { | ||||
fun getMsgType(value: Int): MsgType { | fun getMsgType(value: Int): MsgType { | ||||
@@ -11,4 +11,5 @@ interface ImClientInterface { | |||||
fun isConnect(): Boolean | fun isConnect(): Boolean | ||||
fun isConnecting(): Boolean | fun isConnecting(): Boolean | ||||
fun sendMessage(msg: SendMessage) | fun sendMessage(msg: SendMessage) | ||||
fun imConnectOptions(): ImConnectOptions | |||||
} | } |
@@ -14,5 +14,4 @@ interface SdkInterface { | |||||
* 消息相关 | * 消息相关 | ||||
*/ | */ | ||||
fun setMsgCallback(callback: CallbackListener) | fun setMsgCallback(callback: CallbackListener) | ||||
fun sendTextMessage(toUserId:String, msg: String) | |||||
} | } |
@@ -3,12 +3,10 @@ package cn.org.bjca.trust.push.manager | |||||
import android.content.Context | import android.content.Context | ||||
import cn.org.bjca.trust.push.BuildConfig | import cn.org.bjca.trust.push.BuildConfig | ||||
import cn.org.bjca.trust.push.common.DeviceHelper | import cn.org.bjca.trust.push.common.DeviceHelper | ||||
import cn.org.bjca.trust.push.common.MessageHelper | |||||
import cn.org.bjca.trust.push.enums.OsType | import cn.org.bjca.trust.push.enums.OsType | ||||
import cn.org.bjca.trust.push.kit.SdkInterface | import cn.org.bjca.trust.push.kit.SdkInterface | ||||
import cn.org.bjca.trust.push.message.ImCallback | import cn.org.bjca.trust.push.message.ImCallback | ||||
import cn.org.bjca.trust.push.message.ImManager | import cn.org.bjca.trust.push.message.ImManager | ||||
import cn.org.bjca.trust.push.message.bean.TextMessage | |||||
import cn.org.bjca.trust.push.message.callback.CallbackListener | import cn.org.bjca.trust.push.message.callback.CallbackListener | ||||
import cn.org.bjca.trust.push.message.client.ImConnectOptions | import cn.org.bjca.trust.push.message.client.ImConnectOptions | ||||
@@ -59,13 +57,4 @@ class PushSdkManager : SdkInterface { | |||||
override fun setMsgCallback(callback: CallbackListener) { | override fun setMsgCallback(callback: CallbackListener) { | ||||
imConnectOptions.callback = callback | imConnectOptions.callback = callback | ||||
} | } | ||||
override fun sendTextMessage(toUserId: String, msg: String) { | |||||
MessageHelper.sendMessage(imConnectOptions.clientId, | |||||
TextMessage().apply { | |||||
toClientId = toUserId | |||||
text = msg | |||||
}) | |||||
} | |||||
} | } |
@@ -0,0 +1,50 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
import org.json.JSONArray | |||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class AtMessage : Message() { | |||||
var text: String? = null | |||||
var atNos: List<String>? = null | |||||
init { | |||||
this.msgType = MsgType.At | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
val json = sendMessage.message?.let { JSONObject(it) } | |||||
if (json != null) { | |||||
this.text = json.optString("text") | |||||
val arr = json.optJSONArray("atNos") | |||||
val atNos = arrayListOf<String>() | |||||
if (arr != null) { | |||||
for (index in 0 until arr.length()) { | |||||
atNos.add(arr.optString(index)) | |||||
} | |||||
} | |||||
this.atNos = atNos | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
val json = JSONObject() | |||||
try { | |||||
json.put("text", this.text) | |||||
val jsonArray = JSONArray(this.atNos) | |||||
json.put("atNos", jsonArray) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
} | |||||
} |
@@ -0,0 +1,45 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class FileMessage : Message() { | |||||
var fileStorageId: String? = null | |||||
var fileName: String? = null | |||||
var fileSize: Long? = null | |||||
init { | |||||
this.msgType = MsgType.File | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
val json = sendMessage.message?.let { JSONObject(it) } | |||||
if (json != null) { | |||||
this.fileStorageId = json.optString("fileStorageId") | |||||
this.fileName = json.optString("fileName") | |||||
this.fileSize = json.optLong("fileSize") | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
val json = JSONObject() | |||||
try { | |||||
json.put("fileStorageId", this.fileStorageId) | |||||
json.put("fileName", this.fileName) | |||||
json.put("fileSize", this.fileSize) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
} | |||||
} |
@@ -0,0 +1,54 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class LocationMessage : Message() { | |||||
var address: String? = null | |||||
var title: String? = null | |||||
var thumbnail: String? = null | |||||
var longitude: Double? = null | |||||
var latitude: Double? = null | |||||
var scale: Int? = null | |||||
init { | |||||
this.msgType = MsgType.Location | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
val json = sendMessage.message?.let { JSONObject(it) } | |||||
if (json != null) { | |||||
this.address = json.optString("imageStorageId") | |||||
this.title = json.optString("imageStorageId") | |||||
this.thumbnail = json.optString("imageStorageId") | |||||
this.longitude = json.optDouble("imageStorageId") | |||||
this.latitude = json.optDouble("imageStorageId") | |||||
this.scale = json.optInt("imageStorageId") | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
val json = JSONObject() | |||||
try { | |||||
json.put("address", this.address) | |||||
json.put("title", this.title) | |||||
json.put("thumbnail", this.thumbnail) | |||||
json.put("longitude", this.longitude) | |||||
json.put("latitude", this.latitude) | |||||
json.put("scale", this.scale) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
} | |||||
} |
@@ -0,0 +1,52 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.common.json.GsonImplHelp | |||||
import cn.org.bjca.trust.push.db.device.Device | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class LogMessage() : Message() { | |||||
var text: String? = null | |||||
var versionName: String? = null | |||||
var versionCode: Int? = null | |||||
var device: Device? = null | |||||
init { | |||||
this.msgType = MsgType.Log | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
val json = sendMessage.message?.let { JSONObject(it) } | |||||
if (json != null) { | |||||
this.text = json.optString("text") | |||||
this.versionName = json.optString("versionName") | |||||
this.versionCode = json.optInt("versionCode") | |||||
this.device = json.optString("device")?.let { | |||||
GsonImplHelp.get().toObject(it, Device::class.java) | |||||
} | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
val json = JSONObject() | |||||
try { | |||||
json.put("text", this.text) | |||||
json.put("versionName", this.versionName) | |||||
json.put("versionCode", this.versionCode) | |||||
json.put("device", GsonImplHelp.get().toJson(this.device)) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
} | |||||
} |
@@ -0,0 +1,29 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
class OtherMessage : Message() { | |||||
var msg: String? = null | |||||
init { | |||||
this.msgType = MsgType.Other | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
sendMessage.message?.let { | |||||
this.msg = it | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
return this.msg ?: "" | |||||
} | |||||
} |
@@ -0,0 +1,48 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class PictureMessage : Message() { | |||||
var imageStorageId: String? = null | |||||
var thumbnail: String? = null | |||||
var thumbnailWidth: Int? = null | |||||
var thumbnailHeight: Int? = null | |||||
init { | |||||
this.msgType = MsgType.Image | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
val json = sendMessage.message?.let { JSONObject(it) } | |||||
if (json != null) { | |||||
this.imageStorageId = json.optString("imageStorageId") | |||||
this.thumbnail = json.optString("imageStorageId") | |||||
this.thumbnailWidth = json.optInt("imageStorageId") | |||||
this.thumbnailHeight = json.optInt("imageStorageId") | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
val json = JSONObject() | |||||
try { | |||||
json.put("imageStorageId", this.imageStorageId) | |||||
json.put("thumbnail", this.thumbnail) | |||||
json.put("thumbnailWidth", this.thumbnailWidth) | |||||
json.put("thumbnailHeight", this.thumbnailHeight) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
} | |||||
} |
@@ -19,7 +19,7 @@ class TextMessage : Message() { | |||||
try { | try { | ||||
val json = sendMessage.message?.let { JSONObject(it) } | val json = sendMessage.message?.let { JSONObject(it) } | ||||
if (json != null) { | if (json != null) { | ||||
this.text = json.getString("text") | |||||
this.text = json.optString("text") | |||||
} | } | ||||
} catch (e: Exception) { | } catch (e: Exception) { | ||||
LogHelper.e("消息组装失败", e) | LogHelper.e("消息组装失败", e) | ||||
@@ -1,14 +1,11 @@ | |||||
package cn.org.bjca.trust.push.message.bean | package cn.org.bjca.trust.push.message.bean | ||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | import cn.org.bjca.trust.push.enums.MsgType | ||||
import cn.org.bjca.trust.push.message.msg.Message | import cn.org.bjca.trust.push.message.msg.Message | ||||
import cn.org.bjca.trust.push.message.msg.SendMessage | import cn.org.bjca.trust.push.message.msg.SendMessage | ||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class UnknownMessage : Message() { | class UnknownMessage : Message() { | ||||
private var unkonown: String? = null | |||||
var unkonown: String? = null | |||||
init { | init { | ||||
this.msgType = MsgType.UNKNOWN | this.msgType = MsgType.UNKNOWN | ||||
@@ -16,17 +13,10 @@ class UnknownMessage : Message() { | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | override fun parse(type: MsgType, sendMessage: SendMessage) { | ||||
super.parse(type, sendMessage) | super.parse(type, sendMessage) | ||||
this.unkonown = sendMessage.message | |||||
sendMessage.message?.let { this.unkonown = it } | |||||
} | } | ||||
override fun createContentJsonStr(): String { | override fun createContentJsonStr(): String { | ||||
val json = JSONObject() | |||||
try { | |||||
json.put("unkonown", this.unkonown) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
return unkonown ?: "" | |||||
} | } | ||||
} | } |
@@ -0,0 +1,57 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class VideoMessage : Message() { | |||||
var videoStorageId: String? = null | |||||
var fileName: String? = null | |||||
var fileSize: Long? = null | |||||
var duration: Long? = null | |||||
var firstFrame: String? = null | |||||
var firstFrameWidth: Int? = null | |||||
var firstFrameHeight: Int? = null | |||||
init { | |||||
this.msgType = MsgType.Video | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
val json = sendMessage.message?.let { JSONObject(it) } | |||||
if (json != null) { | |||||
this.videoStorageId = json.optString("videoStorageId") | |||||
this.fileName = json.optString("fileName") | |||||
this.firstFrame = json.optString("firstFrame") | |||||
this.fileSize = json.optLong("fileSize") | |||||
this.duration = json.optLong("duration") | |||||
this.firstFrameWidth = json.optInt("firstFrameWidth") | |||||
this.firstFrameHeight = json.optInt("firstFrameHeight") | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
val json = JSONObject() | |||||
try { | |||||
json.put("videoStorageId", this.videoStorageId) | |||||
json.put("fileName", this.fileName) | |||||
json.put("firstFrame", this.firstFrame) | |||||
json.put("fileSize", this.fileSize) | |||||
json.put("duration", this.duration) | |||||
json.put("firstFrameWidth", this.firstFrameWidth) | |||||
json.put("firstFrameHeight", this.firstFrameHeight) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
} | |||||
} |
@@ -0,0 +1,42 @@ | |||||
package cn.org.bjca.trust.push.message.bean | |||||
import cn.org.bjca.trust.push.common.LogHelper | |||||
import cn.org.bjca.trust.push.enums.MsgType | |||||
import cn.org.bjca.trust.push.message.msg.Message | |||||
import cn.org.bjca.trust.push.message.msg.SendMessage | |||||
import org.json.JSONException | |||||
import org.json.JSONObject | |||||
class VoiceMessage : Message() { | |||||
var voiceStorageId: String? = null | |||||
var duration: Long? = null | |||||
init { | |||||
this.msgType = MsgType.Voice | |||||
} | |||||
override fun parse(type: MsgType, sendMessage: SendMessage) { | |||||
super.parse(type, sendMessage) | |||||
try { | |||||
val json = sendMessage.message?.let { JSONObject(it) } | |||||
if (json != null) { | |||||
this.voiceStorageId = json.optString("voiceStorageId") | |||||
this.duration = json.optLong("duration") | |||||
} | |||||
} catch (e: Exception) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
} | |||||
override fun createContentJsonStr(): String { | |||||
val json = JSONObject() | |||||
try { | |||||
json.put("voiceStorageId", this.voiceStorageId) | |||||
json.put("duration", this.duration) | |||||
} catch (e: JSONException) { | |||||
LogHelper.e("消息组装失败", e) | |||||
} | |||||
return json.toString() | |||||
} | |||||
} |
@@ -8,10 +8,7 @@ import cn.org.bjca.trust.push.common.DeviceHelper | |||||
import cn.org.bjca.trust.push.common.LogHelper | import cn.org.bjca.trust.push.common.LogHelper | ||||
import cn.org.bjca.trust.push.common.MessageHelper | import cn.org.bjca.trust.push.common.MessageHelper | ||||
import cn.org.bjca.trust.push.common.json.GsonImplHelp | import cn.org.bjca.trust.push.common.json.GsonImplHelp | ||||
import cn.org.bjca.trust.push.constant.ERROR_CONNECTED | |||||
import cn.org.bjca.trust.push.constant.ERROR_MSG_SEND_1 | |||||
import cn.org.bjca.trust.push.constant.ERROR_MSG_SEND_2 | |||||
import cn.org.bjca.trust.push.constant.ERROR_MSG_SEND_3 | |||||
import cn.org.bjca.trust.push.constant.* | |||||
import cn.org.bjca.trust.push.db.DbHelper | import cn.org.bjca.trust.push.db.DbHelper | ||||
import cn.org.bjca.trust.push.db.message.SzyxMessage | import cn.org.bjca.trust.push.db.message.SzyxMessage | ||||
import cn.org.bjca.trust.push.enums.OsType | import cn.org.bjca.trust.push.enums.OsType | ||||
@@ -30,6 +27,9 @@ class ImClient : ImClientInterface { | |||||
private lateinit var options: MqttConnectOptions | private lateinit var options: MqttConnectOptions | ||||
private var isConnecting = false | private var isConnecting = false | ||||
private var startConnect = false | private var startConnect = false | ||||
override fun imConnectOptions(): ImConnectOptions = connectOptions | |||||
override fun connect(mImConnectOptions: ImConnectOptions) { | override fun connect(mImConnectOptions: ImConnectOptions) { | ||||
startConnect = true | startConnect = true | ||||
connectOptions = mImConnectOptions | connectOptions = mImConnectOptions | ||||
@@ -194,6 +194,17 @@ class ImClient : ImClientInterface { | |||||
} | } | ||||
override fun sendMessage(msg: SendMessage) { | override fun sendMessage(msg: SendMessage) { | ||||
if (!::connectOptions.isInitialized) { | |||||
MessageHelper.parseMessage(msg)?.let { | |||||
connectOptions.callback?.sendError( | |||||
ERROR_MSG_SEND_4, it | |||||
) | |||||
} | |||||
return | |||||
} | |||||
msg.fromClientId = connectOptions.clientId | |||||
msg.target = connectOptions.clientId | |||||
DbHelper.getDataBase().messageDao().insertAll( | DbHelper.getDataBase().messageDao().insertAll( | ||||
SzyxMessage( | SzyxMessage( | ||||
msg.messageId, | msg.messageId, | ||||
@@ -1,16 +1,16 @@ | |||||
| 序号 | 错误码 | 说明 | | |||||
| ---- | ------ | ---------------------------- | | |||||
| 1 | 10001 | 获取设备信息失败 | | |||||
| 2 | | | | |||||
| 3 | 10011 | 服务端应答超时,发送信息失败 | | |||||
| 4 | 10012 | IM未连接,发送消息失败 | | |||||
| 5 | 10013 | im客户端已连接,发送消息失败 | | |||||
| 6 | | | | |||||
| 7 | 20001 | im连接成功 | | |||||
| 8 | | | | |||||
| 9 | 10021 | im连接失败 | | |||||
| 10 | | | | |||||
| 11 | | | | |||||
| 12 | | | | |||||
| 13 | | | | |||||
| 序号 | 错误码 | 说明 | | |||||
| ---- |-------|-----------------| | |||||
| 1 | 10001 | 获取设备信息失败 | | |||||
| 2 | | | | |||||
| 3 | 10011 | 服务端应答超时,发送信息失败 | | |||||
| 4 | 10012 | IM未连接,发送消息失败 | | |||||
| 5 | 10013 | im客户端已连接,发送消息失败 | | |||||
| 6 | 10014 | sdk未初始化 | | |||||
| 7 | 20001 | im连接成功 | | |||||
| 8 | | | | |||||
| 9 | 10021 | im连接失败 | | |||||
| 10 | | | | |||||
| 11 | | | | |||||
| 12 | | | | |||||
| 13 | | | | |||||