公众号获取微信服务器IP地址
错误代码如下
public function getwxIP(){//获取微信服务器IP地址$accessToken = $this->getwxoaiAccessToken();$userToken = new UserToken();$result = $userToken->curl_get("https: //api.weixin.qq.com/cgi-bin/get_api_domain_ip?access_token={$accessToken}");$wxResult = json_decode($result, true);if (array_key_exists('errcode', $wxResult)) {$this->error(['errorCode' => $wxResult['errcode'],'msg' => $wxResult['errmsg'],]);} else {//正确返回return $wxResult;}}
经检查,发现微信开发文档拷贝的url地址,https: 与//中间有空格,导致请求500并报错
删掉空格,代码正确返回微信服务器ip地址