Esempio n. 1
0
 /**
  * 准备消息
  *
  * @param \Stoneworld\Wechat\Messages\BaseMessage $message
  *
  * @return Broadcast
  */
 public function send($message)
 {
     is_string($message) && ($message = Message::make('text')->with('content', $message));
     if (!$message instanceof BaseMessage) {
         throw new \Exception("消息必须继承自 'Stoneworld\\Wechat\\BaseMessage'");
     }
     $this->message = $message;
     return $this;
 }
Esempio n. 2
0
 /**
  * 生成回复内容
  *
  * @param mixed $response
  *
  * @return string
  */
 protected function response($response)
 {
     if (empty($response)) {
         return "";
     }
     is_string($response) && ($response = Message::make('text')->with('content', $response));
     $return = "";
     if ($response instanceof BaseMessage) {
         $response->from($this->input->get('ToUserName'))->to($this->input->get('FromUserName'));
         $this->call('responseCreated', array($response));
         $return = $response->buildForReply();
         $return = $this->getCrypt()->encryptMsg($return, $this->input->get('nonce'), $this->input->get('timestamp'));
     }
     $return = $this->call('served', array($return), $return);
     return $return;
 }
Esempio n. 3
0
<?php

require __DIR__ . "autoload.php";
use Stoneworld\Wechat\Server;
use Stoneworld\Wechat\Message;
$options = array('token' => 'stoneworld1992', 'encodingaeskey' => 'o1wze3492xoUVIc9ccTLJczO3BQ5pLfiHcKwtDEdqM9', 'appid' => 'wx8ac123b21f53d722', 'appsecret' => '4ZDHIETJ6e0oENlEkRhYwzWPTrkLdXedKcPcRjCkgQkuHtQTJ12ZhWHESowrJqS9', 'agentid' => '5');
$weObj = new Server($options);
$weObj->on('event', function ($event) {
    return Message::make('text')->content(var_export($event, true));
});
echo $weObj->server();
//注意, 企业号与普通公众号不同,必须打开验证,不要注释掉