mall_id)) return $this->error('未设置Mall-Id'); // 获取微信配置 $wechat = Yii::$app->services->setting->mall->get($this->mall_id, 'wechat'); if (!($wechat['app_id'] && $wechat['secret'])) return $this->error('未配置微信公众号'); $options = [ 'app_id' => $wechat['app_id'], 'secret' => $wechat['secret'], 'log' => [ 'level' => 'debug', 'file' => '/tmp/easywechat.log', ], ]; $this->app = Factory::officialAccount($options); } /** * 用户是否订阅 * * @param integer $user_id * @return boolean */ public function isSubscribe(int $user_id) { // 查询用户openid $openid = UserInfo::getWechatOpenid($this->mall_id, $user_id); if (empty($openid)) return $this->error('未找到用户公众号信息'); // 查询微信信息 $wechat_info = $this->info($openid); if (empty($wechat_info)) return $this->error($this->getError()); return boolval($wechat_info['subscribe']); } /** * 会员详情 * * @param string $openid * @return array|false */ public function info(string $openid) { $info = $this->app->user->get($openid); if (isset($info['errcode'])) return $this->error($info['errmsg']); return $info; } }