danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.83k stars 654 forks source link

access_hash encoding #225

Closed Cosmos-Tech closed 6 years ago

Cosmos-Tech commented 6 years ago

Hi dears, I read doc.

Constructor::user access_hash is long [BigInteger -> phpseclib\Math]

When I use get_pwr_chat to get participants info: access_hash returned is string type with cp1256 encoding [contains special symbols]

I need save access_hash in database (mysql utf8) to reused.

How can i convert access_hash [string] to long type or Or vice versa?

Thanks

wecanco commented 6 years ago

@Cosmos-Tech access_hash is long value, in 32bit system shown string that have symboles. u should use 64bit system to return true long value.

Cosmos-Tech commented 6 years ago

Thanks @wecanco, But on 32-bit, How MadelineProto handle it, because application worked correctly?

wecanco commented 6 years ago

@Cosmos-Tech 32bit php handle this value and convert it.

Cosmos-Tech commented 6 years ago

Thanks @wecanco, But i need to known How 32bit php do it.

wecanco commented 6 years ago

@Cosmos-Tech i dont know how to handle it. but this link mabye help u: https://stackoverflow.com/a/2842548

danog commented 6 years ago

On 32 bit systems, MadelineProto handles 64 bit numbers as base256 numbers (aka strings, or binary numbers). Since usually there is no need to do any arithmetical manipulations to the 64 bit access hashes, MadelineProto stores and sends directly the string versions of these numbers. I suggest you store access hashes using the mysql BYTE datatype, or, if you have a 64 bit system, as BIGINT.