mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2025-04-05 19:41:44 +08:00
修改json请求方式
This commit is contained in:
parent
7eb7f6a2d8
commit
f070dd076a
2
We.php
2
We.php
@ -86,7 +86,7 @@ class We
|
||||
* 定义当前版本
|
||||
* @var string
|
||||
*/
|
||||
const VERSION = '1.2.22';
|
||||
const VERSION = '1.2.23';
|
||||
|
||||
/**
|
||||
* 静态配置
|
||||
|
@ -94,7 +94,7 @@ class BasicWeChat
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问accessToken
|
||||
* 获取访问 AccessToken
|
||||
* @return string
|
||||
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||
* @throws \WeChat\Exceptions\LocalCacheException
|
||||
@ -166,15 +166,15 @@ class BasicWeChat
|
||||
{
|
||||
try {
|
||||
return Tools::json2arr(Tools::get($url));
|
||||
} catch (InvalidResponseException $e) {
|
||||
} catch (InvalidResponseException $exception) {
|
||||
if (isset($this->currentMethod['method']) && empty($this->isTry)) {
|
||||
if (in_array($e->getCode(), ['40014', '40001', '41001', '42001'])) {
|
||||
if (in_array($exception->getCode(), ['40014', '40001', '41001', '42001'])) {
|
||||
$this->delAccessToken();
|
||||
$this->isTry = true;
|
||||
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
|
||||
}
|
||||
}
|
||||
throw new InvalidResponseException($e->getMessage(), $e->getCode());
|
||||
throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,13 +190,15 @@ class BasicWeChat
|
||||
protected function httpPostForJson($url, array $data, $buildToJson = true)
|
||||
{
|
||||
try {
|
||||
return Tools::json2arr(Tools::post($url, $buildToJson ? Tools::arr2json($data) : $data));
|
||||
} catch (InvalidResponseException $e) {
|
||||
if (!$this->isTry && in_array($e->getCode(), ['40014', '40001', '41001', '42001'])) {
|
||||
$options = [];
|
||||
if ($buildToJson) $options['headers'] = ['Content-Type: application/json'];
|
||||
return Tools::json2arr(Tools::post($url, $buildToJson ? Tools::arr2json($data) : $data, $options));
|
||||
} catch (InvalidResponseException $exception) {
|
||||
if (!$this->isTry && in_array($exception->getCode(), ['40014', '40001', '41001', '42001'])) {
|
||||
[$this->delAccessToken(), $this->isTry = true];
|
||||
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
|
||||
}
|
||||
throw new InvalidResponseException($e->getMessage(), $e->getCode());
|
||||
throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user