app) { $this->app = new Application(config('wechat.mini_program')); } return $this->app; } /** * 获取 Utils 实例(code2Session、解密等) */ public function utils(): Utils { return $this->app()->getUtils(); } /** * 通过 code 换取 session * * @return array{openid: string, session_key: string, unionid?: string} * * @throws HttpException */ public function codeToSession(string $code): array { return $this->utils()->codeToSession($code); } /** * 解密加密数据(如用户信息、手机号) * * @return array */ public function decryptData(string $sessionKey, string $iv, string $ciphertext): array { return $this->utils()->decryptSession($sessionKey, $iv, $ciphertext); } /** * 获取用户手机号 * * @return array * * @throws HttpException */ public function getPhoneNumber(string $code): array { return $this->utils()->getPhoneNumber($code); } }