示例#1
0
 /**
  * 获取配置
  */
 public function getConfig($asArray = false)
 {
     $options = array('appid' => $this->accessToken->getAppid(), 'url' => Util::getCurrentUrl(), 'timestamp' => Util::getTimestamp(), 'noncestr' => Util::getRandomString(), 'accesstoken' => $this->accessToken['access_token']);
     // 按 ASCII 码排序
     ksort($options);
     $signature = http_build_query($options);
     $signature = urldecode($signature);
     $signature = sha1($signature);
     $config = array('appId' => $options['appid'], 'scope' => 'jsapi_address', 'signType' => 'sha1', 'addrSign' => $signature, 'timeStamp' => $options['timestamp'], 'nonceStr' => $options['noncestr']);
     return $asArray ? $config : Serializer::jsonEncode($config);
 }
示例#2
0
文件: Notify.php 项目: thenbsp/wechat
 /**
  * 构造方法
  */
 public function __construct(Request $request = null)
 {
     $request = $request ?: Request::createFromGlobals();
     $content = $request->getContent();
     try {
         $options = Serializer::parse($content);
     } catch (\InvalidArgumentException $e) {
         $options = array();
     }
     parent::__construct($options);
 }
示例#3
0
文件: Jsapi.php 项目: thenbsp/wechat
 /**
  * 获取配置文件
  */
 public function getConfig($asArray = false)
 {
     $ticket = new Ticket($this->accessToken);
     if ($this->cache) {
         $ticket->setCache($this->cache);
     }
     $options = array('jsapi_ticket' => $ticket->getTicketString(), 'timestamp' => Util::getTimestamp(), 'url' => Util::getCurrentUrl(), 'noncestr' => Util::getRandomString());
     ksort($options);
     $signature = sha1(urldecode(http_build_query($options)));
     $configure = array('appId' => $this->accessToken['appid'], 'nonceStr' => $options['noncestr'], 'timestamp' => $options['timestamp'], 'signature' => $signature, 'jsApiList' => $this->api, 'debug' => (bool) $this->debug);
     return $asArray ? $configure : Serializer::jsonEncode($configure);
 }
示例#4
0
 /**
  * handle event via request
  */
 public function handle(EventListenerInterface $listener)
 {
     if (!$listener->getListeners()) {
         return;
     }
     $content = $this->request->getContent();
     try {
         $options = Serializer::parse($content);
     } catch (\InvalidArgumentException $e) {
         $options = array();
     }
     foreach ($listener->getListeners() as $namespace => $callable) {
         $event = new $namespace($options);
         if ($event->isValid()) {
             $listener->trigger($namespace, $event);
             break;
         }
     }
 }
示例#5
0
 /**
  * 获取配置
  */
 public function getConfig($asArray = false)
 {
     $config = $this->resolveConfig();
     return $asArray ? $config : Serializer::jsonEncode($config);
 }
示例#6
0
文件: Http.php 项目: thenbsp/wechat
 /**
  * Send Request
  */
 public function send($asArray = true)
 {
     $options = array();
     // query
     if (!empty($this->query)) {
         $options['query'] = $this->query;
     }
     // body
     if (!empty($this->body)) {
         $options['body'] = $this->body;
     }
     // ssl cert
     if ($this->sslCert && $this->sslKey) {
         $options['cert'] = $this->sslCert;
         $options['ssl_key'] = $this->sslKey;
     }
     $response = (new Client())->request($this->method, $this->uri, $options);
     $contents = $response->getBody()->getContents();
     if (!$asArray) {
         return $contents;
     }
     $array = Serializer::parse($contents);
     return new ArrayCollection($array);
 }
示例#7
0
 /**
  * 构造方法
  */
 public function __construct(array $options, array $headers = array(), $status = 200)
 {
     $content = Serializer::xmlEncode($options);
     $headers = array_replace($headers, array('Content-Type' => 'application/xml'));
     parent::__construct($content, $status, $headers);
 }