mxc-php icon indicating copy to clipboard operation
mxc-php copied to clipboard

'network' issue when has special character

Open zonbloginc opened this issue 2 years ago • 6 comments

I perform a withdrawal with MxcSpotV3 ->privates()->withdraw($data) and everything work fine except if I try to do anything with $data = ['network' => 'BEP20(BSC)'] or any network that contains special characters, like SPACE, or ' - '.

It made the query URL to be differ than expected:

API server expected: /api/v3/capital/withdraw/apply?coin=USDT&address=zzqqqqqqqqqq&amount=10&network=BEP20(BSC)&memo=MX10086&timestamp={{timestamp}}&signature={{signature}}

The real one with the mxc repo: /api/v3/capital/withdraw/apply?coin=USDT&address=zzqqqqqqqqqq&amount=10&network=BEP20%28BSC%29&memo=MX10086&timestamp={{timestamp}}&signature={{signature}}

It seems it can't convert these characters correct when pushing to the API servers. If I use the 'network' with simple type, such as ERC20, OP, MATIC, then there is no issue at all.

Can you take a look at this?

zonbloginc avatar Nov 28 '23 18:11 zonbloginc

After spending a short time to figure out, it seems the error message would be:

{"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400} {"userId":"tony","exception":"[object] (Lin\Mxc\Exceptions\Exception(code: 0): {"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https:\/\/api.mexc.com\/api\/v3\/capital\/withdraw\/apply","_httpcode":400}

Somehow, if use special characters in query URL, it didn't work and led to this 'signature' error.

Worked version: coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

Didn't work: coin=USDT&network=EOS%28TEST%29&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231859000

I tried to build query URL manually but didn't work too: coin=USDT&network=EOS(TEST)&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

To clarify that your repo didn't have withdraw() function, I created a new one in SpotV3\Privates:

// POST /api/v3/capital/withdraw/apply // public function withdraw(array $data=[]){ $this->type='POST'; $this->path='/api/v3/capital/withdraw/apply'; $this->data=$data; return $this->exec(); }

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw

zonbloginc avatar Nov 29 '23 04:11 zonbloginc

After spending a short time to figure out, it seems the error message would be:

{"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400} {"userId":"tony","exception":"[object] (Lin\Mxc\Exceptions\Exception(code: 0): {"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400}

Somehow, if use special characters in query URL, it didn't work and led to this 'signature' error.

Worked version: coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

Didn't work: coin=USDT&network=EOS%28TEST%29&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231859000

I tried to build query URL manually but didn't work too: coin=USDT&network=EOS(TEST)&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

To clarify that your repo didn't have withdraw() function, I created a new one in SpotV3\Privates:

// POST /api/v3/capital/withdraw/apply // public function withdraw(array $data=[]){ $this->type='POST'; $this->path='/api/v3/capital/withdraw/apply'; $this->data=$data; return $this->exec(); }

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw

Signature issues, special characters, may all require no encoding, I tried to solve this problem.

zhouaini528 avatar Nov 29 '23 06:11 zhouaini528

After spending a short time to figure out, it seems the error message would be:

{"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400} {"userId":"tony","exception":"[object] (Lin\Mxc\Exceptions\Exception(code: 0): {"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400}

Somehow, if use special characters in query URL, it didn't work and led to this 'signature' error.

Worked version: coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

Didn't work: coin=USDT&network=EOS%28TEST%29&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231859000

I tried to build query URL manually but didn't work too: coin=USDT&network=EOS(TEST)&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

To clarify that your repo didn't have withdraw() function, I created a new one in SpotV3\Privates:

// POST /api/v3/capital/withdraw/apply // public function withdraw(array $data=[]){ $this->type='POST'; $this->path='/api/v3/capital/withdraw/apply'; $this->data=$data; return $this->exec(); }

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw

https://github.com/zhouaini528/mxc-php/blob/9e733bcf5b1a77be9bc7422ec72df317957f0e39/src/Request.php#L147

QQ20231129-151627

The post submission data is in the form_params way, and the special characters in it are not encoded, why is your submission data a GET URL splicing?

zhouaini528 avatar Nov 29 '23 07:11 zhouaini528

I discussed to one of MEXC supporter on this issue and he said:

  1. the URL data: http_build_query($this->data) need to be encoded, so use http_build_query is satisfy the requirement.
  2. the POST URL doesn't need encode

picpic

The post submission data is in the form_params way, and the special characters in it are not encoded, why is your submission data a GET URL splicing?

This is the log version of http_build_query($this->data) in signature() function, not the POST URL.

coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

I still can't pass this annoying issue, maybe the error came from their API server?

zonbloginc avatar Nov 29 '23 07:11 zonbloginc

I discussed to one of MEXC supporter on this issue and he said:

  1. the URL data: http_build_query($this->data) need to be encoded, so use http_build_query is satisfy the requirement.
  2. the POST URL doesn't need encode

picpic

The post submission data is in the form_params way, and the special characters in it are not encoded, why is your submission data a GET URL splicing?

This is the log version of http_build_query($this->data) in signature() function, not the POST URL.

coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

I still can't pass this annoying issue, maybe the error came from their API server?

I found a way you can try

echo $url=urldecode(http_build_query($arr));

zhouaini528 avatar Nov 29 '23 08:11 zhouaini528

Actually, I tried to build the query string for signature manually with/without encode and it still didn't work. MEXC also has recently changed the list of withdrawal networks into special character mode. Right now, most of networks have special characters in them, except several ones, such as EOS, OKT ...

So withdraw asset through API seems not possible at this moment.

zonbloginc avatar Nov 29 '23 09:11 zonbloginc