get('https://api.weixin.qq.com/sns/jscode2session', [ 'appid' => $appid, 'secret' => $secret, 'js_code' => $code, 'grant_type' => 'authorization_code', ])->json(); $openid = is_array($result) ? (string) ($result['openid'] ?? '') : ''; if ($openid === '') { Log::warning('微信 code2session 失败', ['response' => $result]); throw new RepositoryException('微信登录凭证校验失败:' . ($result['errmsg'] ?? '请重新进入小程序')); } return $openid; } }