getAccessToken(); $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit'; $data = array_merge([ 'width' => 280 ], $param); $result = HttpClient::request('post', $url, [ 'body' => json_encode($data, JSON_UNESCAPED_UNICODE), 'query' => ["access_token" => $access_token['access_token']], 'headers' => ['Content-Type' => 'application/json'] ]); $result = $result->getBody()->getContents(); // Log::write('getWxCodeUnlimited:'.$result); return json_decode($result); } /** * 获取手机号 * @param string $code * @return array */ public function getWechatMobile($code) { $access_token = $this->getAccessToken(); $url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"; $res = HttpClient::request('post', $url, [ 'body' => json_encode(['code' => $code]), 'query' => ["access_token" => $access_token['access_token']], 'headers' => ['Content-Type' => 'application/json'] ]); $res = $res->getBody()->getContents(); $res = (array)json_decode($res, true); if (!isset($res['phone_info']) && Config::get('app_debug')) { Log::write($res, 'get_phone'); } return $res['phone_info'] ?? []; } /** * 获取Session信息 * @param string $code * @return array */ public function getWechatSession($code) { $access_token = $this->getAccessToken(); $url = "https://api.weixin.qq.com/sns/jscode2session"; $result = HttpClient::request('get', $url, [ 'query' => [ "access_token" => $access_token['access_token'], 'appid' => $this->app->app_id, 'secret' => $this->app->app_secret, 'js_code' => $code, 'grant_type' => 'authorization_code' ], ]); $result = $result->getBody()->getContents(); $result = json_decode($result, true); if ($result['errcode'] == 0) { return $result; } if (Config::get('app_debug')) { Log::write($result, 'get_session'); } return ['errmsg' => Config::get('app_debug') ? $result['errmsg'] : '网络错误']; } }