/** * Set attribute. * * @param string $attribute * @param mixed $value * * @return Attribute */ public function with($attribute, $value) { $attribute = Str::snake($attribute); if (!$this->validate($attribute, $value)) { throw new InvalidArgumentException("Invalid attribute '{$attribute}'."); } $this->set($attribute, $value); return $this; }
/** * Register service. * * @param Application $app * * @return mixed */ public function register(Application $app) { $app->singleton('message', function ($app) { return new MessageFactory($app); }); $messages = ['Text', 'Articles', 'Article', 'Image', 'Link', 'Location', 'Music', 'Transfer', 'ShortVideo', 'Video', 'Voice']; foreach ($messages as $message) { $app->bind('message.' . Str::snake($message), function ($app) use($message) { $class = __NAMESPACE__ . '\\' . $message; return new $class(); }, false); } }
/** * Build signature. * * @param string $url * @param string $nonce * @param int $timestamp * * @return array */ public function signature($url = null, $nonce = null, $timestamp = null) { $url = $url ? $url : $this->getUrl(); $nonce = $nonce ? $nonce : Str::quickRandom(10); $timestamp = $timestamp ? $timestamp : time(); $ticket = $this->ticket(); $sign = ['appId' => $this->getAccessToken()->getAppId(), 'nonceStr' => $nonce, 'timestamp' => $timestamp, 'url' => $url, 'signature' => $this->getSignature($ticket, $nonce, $timestamp, $url)]; return $sign; }
/** * Redirect the user of the application to the WeChat's authentication screen. * * @param string $to * @param string $scope * * @return RedirectResponse * * @throws InvalidArgumentException */ public function redirect($to, $scope = 'snsapi_userinfo') { if (!in_array($scope, $this->scopes)) { throw new InvalidArgumentException("Invalid oauth scope:'{$scope}'"); } $this->request->getSession()->set('state', $state = Str::random(40)); return new RedirectResponse($this->buildAuthUrlFromBase($to, $scope, $state) . '#wechat_redirect'); }
/** * Return random string. * * @return string */ public function getNonce() { return Str::quickRandom(10); }