Commit 13b72b31 authored by Him188's avatar Him188

Friend image upload

parent 96d6268a
...@@ -51,7 +51,7 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin ...@@ -51,7 +51,7 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
} }
} }
override suspend fun uploadImage(image: ExternalImage): Image { override suspend fun uploadImage(image: ExternalImage): Image = try {
bot.network.run { bot.network.run {
val response = LongConn.OffPicUp( val response = LongConn.OffPicUp(
bot.client, Cmd0x352.TryUpImgReq( bot.client, Cmd0x352.TryUpImgReq(
...@@ -60,12 +60,11 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin ...@@ -60,12 +60,11 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
fileId = 0, fileId = 0,
fileMd5 = image.md5, fileMd5 = image.md5,
fileSize = image.inputSize.toInt(), fileSize = image.inputSize.toInt(),
fileName = image.md5.toUHexString("") + ".jpg", fileName = image.md5.toUHexString("") + "." + image.format,
imgOriginal = 1, imgOriginal = 1,
imgWidth = image.width, imgWidth = image.width,
imgHeight = image.height, imgHeight = image.height,
imgType = image.imageType, imgType = image.imageType
buType = 0
) )
).sendAndExpect<LongConn.OffPicUp.Response>() ).sendAndExpect<LongConn.OffPicUp.Response>()
...@@ -81,7 +80,6 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin ...@@ -81,7 +80,6 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
is LongConn.OffPicUp.Response.RequireUpload -> { is LongConn.OffPicUp.Response.RequireUpload -> {
HighwayHelper.uploadImage( HighwayHelper.uploadImage(
client = bot.client, client = bot.client,
uin = bot.uin,
serverIp = response.serverIp[0].toIpV4AddressString(), serverIp = response.serverIp[0].toIpV4AddressString(),
serverPort = response.serverPort[0], serverPort = response.serverPort[0],
imageInput = image.input, imageInput = image.input,
...@@ -103,6 +101,8 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin ...@@ -103,6 +101,8 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
is LongConn.OffPicUp.Response.Failed -> error(response.message) is LongConn.OffPicUp.Response.Failed -> error(response.message)
} }
} }
} finally {
image.input.close()
} }
override suspend fun queryProfile(): Profile { override suspend fun queryProfile(): Profile {
...@@ -355,7 +355,7 @@ internal class GroupImpl( ...@@ -355,7 +355,7 @@ internal class GroupImpl(
} }
} }
override suspend fun uploadImage(image: ExternalImage): Image { override suspend fun uploadImage(image: ExternalImage): Image = try {
bot.network.run { bot.network.run {
val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp( val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp(
bot.client, bot.client,
...@@ -393,7 +393,6 @@ internal class GroupImpl( ...@@ -393,7 +393,6 @@ internal class GroupImpl(
HighwayHelper.uploadImage( HighwayHelper.uploadImage(
client = bot.client, client = bot.client,
uin = bot.uin,
serverIp = response.uploadIpList.first().toIpV4AddressString(), serverIp = response.uploadIpList.first().toIpV4AddressString(),
serverPort = response.uploadPortList.first(), serverPort = response.uploadPortList.first(),
imageInput = image.input, imageInput = image.input,
...@@ -436,6 +435,8 @@ internal class GroupImpl( ...@@ -436,6 +435,8 @@ internal class GroupImpl(
} }
} }
} }
} finally {
image.input.close()
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
......
...@@ -104,8 +104,11 @@ internal open class QQAndroidClient( ...@@ -104,8 +104,11 @@ internal open class QQAndroidClient(
private val requestPacketRequestId: AtomicInt = atomic(1921334513) private val requestPacketRequestId: AtomicInt = atomic(1921334513)
internal fun nextRequestPacketRequestId(): Int = requestPacketRequestId.getAndAdd(2) internal fun nextRequestPacketRequestId(): Int = requestPacketRequestId.getAndAdd(2)
private val highwayDataTransSequenceId: AtomicInt = atomic(87017) private val highwayDataTransSequenceIdForGroup: AtomicInt = atomic(87017)
internal fun nextHighwayDataTransSequenceId(): Int = highwayDataTransSequenceId.getAndAdd(2) internal fun nextHighwayDataTransSequenceIdForGroup(): Int = highwayDataTransSequenceIdForGroup.getAndAdd(2)
private val highwayDataTransSequenceIdForFriend: AtomicInt = atomic(40717)
internal fun nextHighwayDataTransSequenceIdForFriend(): Int = highwayDataTransSequenceIdForFriend.getAndAdd(2)
val appClientVersion: Int = 0 val appClientVersion: Int = 0
......
...@@ -78,6 +78,9 @@ object Highway { ...@@ -78,6 +78,9 @@ object Highway {
md5: ByteArray md5: ByteArray
): ByteReadPacket { ): ByteReadPacket {
require(uKey.size == 128) { "bad uKey. Required size=128, got ${uKey.size}" } require(uKey.size == 128) { "bad uKey. Required size=128, got ${uKey.size}" }
require(data !is ByteReadPacket || data.remaining.toInt() == dataSize) { "bad input. given dataSize=$dataSize, but actual readRemaining=${(data as ByteReadPacket).remaining}" }
require(data !is IoBuffer || data.readRemaining == dataSize) { "bad input. given dataSize=$dataSize, but actual readRemaining=${(data as IoBuffer).readRemaining}" }
val dataHighwayHead = CSDataHighwayHead.DataHighwayHead( val dataHighwayHead = CSDataHighwayHead.DataHighwayHead(
version = 1, version = 1,
uin = uin.toString(), uin = uin.toString(),
...@@ -91,7 +94,7 @@ object Highway { ...@@ -91,7 +94,7 @@ object Highway {
) )
val segHead = CSDataHighwayHead.SegHead( val segHead = CSDataHighwayHead.SegHead(
datalength = dataSize, datalength = dataSize,
filesize = dataSize.toLong() and 0xFFffFFff, filesize = dataSize.toLong(),
serviceticket = uKey, serviceticket = uKey,
md5 = md5, md5 = md5,
fileMd5 = md5, fileMd5 = md5,
......
...@@ -15,7 +15,6 @@ internal object HighwayHelper { ...@@ -15,7 +15,6 @@ internal object HighwayHelper {
suspend fun uploadImage( suspend fun uploadImage(
client: QQAndroidClient, client: QQAndroidClient,
uin: Long,
serverIp: String, serverIp: String,
serverPort: Int, serverPort: Int,
uKey: ByteArray, uKey: ByteArray,
...@@ -26,14 +25,18 @@ internal object HighwayHelper { ...@@ -26,14 +25,18 @@ internal object HighwayHelper {
) { ) {
require(md5.size == 16) { "bad md5. Required size=16, got ${md5.size}" } require(md5.size == 16) { "bad md5. Required size=16, got ${md5.size}" }
require(uKey.size == 128) { "bad uKey. Required size=128, got ${uKey.size}" } require(uKey.size == 128) { "bad uKey. Required size=128, got ${uKey.size}" }
require(commandId == 2 || commandId == 1) { "bad commandId. Must be 1 or 2" }
val socket = PlatformSocket() val socket = PlatformSocket()
socket.connect(serverIp, serverPort) socket.connect(serverIp, serverPort)
socket.use { socket.use {
socket.send( socket.send(
Highway.RequestDataTrans( Highway.RequestDataTrans(
uin = uin, uin = client.uin,
command = "PicUp.DataUp", command = "PicUp.DataUp",
sequenceId = client.nextHighwayDataTransSequenceId(), sequenceId =
if (commandId == 2) client.nextHighwayDataTransSequenceIdForGroup()
else client.nextHighwayDataTransSequenceIdForFriend(),
uKey = uKey, uKey = uKey,
data = imageInput, data = imageInput,
dataSize = inputSize, dataSize = inputSize,
......
...@@ -91,7 +91,7 @@ internal class Cmd0x352 : ProtoBuf { ...@@ -91,7 +91,7 @@ internal class Cmd0x352 : ProtoBuf {
@SerialId(2) val msgTryupImgReq: List<TryUpImgReq>? = null,// optional @SerialId(2) val msgTryupImgReq: List<TryUpImgReq>? = null,// optional
@SerialId(3) val msgGetimgUrlReq: List<GetImgUrlReq>? = null,// optional @SerialId(3) val msgGetimgUrlReq: List<GetImgUrlReq>? = null,// optional
@SerialId(4) val msgDelImgReq: List<DelImgReq>? = null, @SerialId(4) val msgDelImgReq: List<DelImgReq>? = null,
@SerialId(10) val netType: Int = 0// 数据网络=5 @SerialId(10) val netType: Int = 3// 数据网络=5
) : ProtoBuf ) : ProtoBuf
@Serializable @Serializable
...@@ -117,11 +117,10 @@ internal class Cmd0x352 : ProtoBuf { ...@@ -117,11 +117,10 @@ internal class Cmd0x352 : ProtoBuf {
@SerialId(9) val innerIP: Int = 0, @SerialId(9) val innerIP: Int = 0,
@SerialId(10) val addressBook: Int = 0,//chatType == 1006为1 我觉得发0没问题 @SerialId(10) val addressBook: Int = 0,//chatType == 1006为1 我觉得发0没问题
@SerialId(11) val retry: Int = 0,//default @SerialId(11) val retry: Int = 0,//default
@SerialId(12) val buType: Int,//1或96 不确定 @SerialId(12) val buType: Int = 1,//1或96 不确定
@SerialId(13) val imgOriginal: Int,//是否为原图 @SerialId(13) val imgOriginal: Int,//是否为原图
@SerialId(14) val imgWidth: Int, @SerialId(14) val imgWidth: Int,
@SerialId(15) val imgHeight: Int, @SerialId(15) val imgHeight: Int,
@SerialId(16) val imgType: Int = 1000,
/** /**
* ImgType: * ImgType:
* JPG: 1000 * JPG: 1000
...@@ -131,7 +130,8 @@ internal class Cmd0x352 : ProtoBuf { ...@@ -131,7 +130,8 @@ internal class Cmd0x352 : ProtoBuf {
* GIG: 2000 * GIG: 2000
* APNG: 2001 * APNG: 2001
* SHARPP: 1004 * SHARPP: 1004
* */ */
@SerialId(16) val imgType: Int = 1000,
@SerialId(17) val buildVer: String = "8.2.0.1296",//版本号 @SerialId(17) val buildVer: String = "8.2.0.1296",//版本号
@SerialId(18) val fileIndex: ByteArray = EMPTY_BYTE_ARRAY,//default @SerialId(18) val fileIndex: ByteArray = EMPTY_BYTE_ARRAY,//default
@SerialId(19) val fileStoreDays: Int = 0,//default @SerialId(19) val fileStoreDays: Int = 0,//default
......
...@@ -85,7 +85,7 @@ kotlin { ...@@ -85,7 +85,7 @@ kotlin {
api(ktor("network", ktorVersion)) api(ktor("network", ktorVersion))
//implementation("io.ktor:ktor-io:1.3.0-beta-1") //implementation("io.ktor:ktor-io:1.3.0-beta-1")
runtimeOnly(files("build/classes/kotlin/metadata/main")) // classpath is not properly set by IDE //runtimeOnly(files("build/classes/kotlin/metadata/main")) // classpath is not properly set by IDE
} }
} }
commonTest { commonTest {
...@@ -93,7 +93,7 @@ kotlin { ...@@ -93,7 +93,7 @@ kotlin {
api(kotlin("test-annotations-common")) api(kotlin("test-annotations-common"))
api(kotlin("test-common")) api(kotlin("test-common"))
runtimeOnly(files("build/classes/kotlin/metadata/test")) // classpath is not properly set by IDE //runtimeOnly(files("build/classes/kotlin/metadata/test")) // classpath is not properly set by IDE
} }
} }
......
...@@ -43,13 +43,13 @@ class ExternalImage( ...@@ -43,13 +43,13 @@ class ExternalImage(
): ExternalImage = ExternalImage(width, height, md5, format, data, data.remaining, filename) ): ExternalImage = ExternalImage(width, height, md5, format, data, data.remaining, filename)
} }
private val format: String = when (val it = imageFormat.toLowerCase()) { val format: String =
"jpeg" -> "jpg" //必须转换 when (val it = imageFormat.toLowerCase()) {
else -> it "jpeg" -> "jpg" //必须转换
} else -> it
}
/** /**
*
* ImgType: * ImgType:
* JPG: 1000 * JPG: 1000
* PNG: 1001 * PNG: 1001
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment