validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } // 获取平台微信配置进行初始化 $wechat_config = Option::getSaasWechat(); // $config = [ // 'app_id' => $wechat_config['sp_appid'], // 'secret' => $wechat_config['sp_key'], // 'response_type' => 'array' // ]; $config = [ 'app_id' => 'wx44a1c390fb6fbfdd', 'secret' => 'b39f12cac61ad5bf63506058752d5f49', 'response_type' => 'array' ]; \Yii::error($config); $wechat = Factory::miniProgram($config); if (!$wechat) { throw new \Exception('Wechat App Is Null', 1); } $session = $wechat->auth->session($this->code); if (!$session || empty($session['openid'])) { throw new \Exception('获取openid失败.'); } $saas_user = SaasUser::findOne(['mobile' => $this->phone]); if (!$saas_user) { $saas_user = new SaasUser(); $saas_user->store_id = $this->store_id; $saas_user->mobile = $this->phone; $saas_user->platform_open_id = $session['openid']; } else { $saas_user->platform_open_id = $session['openid']; } if (!$saas_user->save()) { return [ 'code' => 1, 'msg' => $saas_user->errors[0] ]; } return [ 'code' => 0, 'msg' => 'success' ]; } }