protected function parseHttpResult($url, $params, $method, $force = true)
{
if (stripos($url, 'http://') === false && stripos($url, 'https://') === false) {
$url = self::WECHAT_BASE_URL . $url;
}
$return = $this->http($url, $params, $method);
$return = json_decode($return, true) ?: $return;
if (isset($return['errcode']) && $return['errcode']) {
$this->lastErrorInfo = $return;
$log = ['class' => __METHOD__, 'arguments' => func_get_args(), 'result' => $return];
switch ($return['errcode']) {
case 40001:
//access_token 失效,强制更新access_token, 并更新地址重新执行请求
if ($force) {
Yii::warning($log, 'wechat.sdk');
$url = preg_replace_callback("/access_token=([^&]*)/i", function () {
return 'access_token=' . $this->getAccessToken(true);
}, $url);
$return = $this->parseHttpResult($url, $params, $method, false);
// 仅重新获取一次,否则容易死循环
}
break;
}
Yii::error($log, 'wechat.sdk');
}
return $return;
}