public function action_index() { $token = 'wxtest'; $appid = 'wxc5b1d86df49a2dc4'; $encodingAesKey = ''; $wechat = new MyWechat($token, $encodingAesKey, $appid); $wechat->run(); }
public function action_index() { $wx_config = Kohana::config('weixin.default'); $token = $wx_config['token']; $appid = $wx_config['appid']; $encodingAesKey = $wx_config['encodingAesKey']; $wechat = new MyWechat($token, $encodingAesKey, $appid); $wechat->run(); }
public function testReplyNews() { ExitTestHelper::init(); $this->fillTextMsg('收到文本消息'); $wechat = new MyWechat($this->token); $items = array(new NewsResponseItem('Travis CI', 'Free Hosted Continuous Integration Platform for the Open Source Community', 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'https://travis-ci.org/netputer/wechat-php-sdk'), new NewsResponseItem('Travis CI 2', '2 Free Hosted Continuous Integration Platform for the Open Source Community', 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'https://travis-ci.org/netputer/wechat-php-sdk')); // 回复图文消息 $wechat->publicResponseNews($items); // 截获输出,解析 $this->setResponse(ExitTestHelper::getFirstExitOutput()); // 回复的to、from与填充的传入消息的to、from相反 $this->assertEquals($this->fromUser, $this->getResponseField('tousername')); $this->assertEquals($this->toUser, $this->getResponseField('fromusername')); $this->assertEquals('0', $this->getResponseField('funcflag')); $this->assertEquals('news', $this->getResponseField('msgtype')); // 验证图文消息内容 $this->assertEquals('2', $this->getResponseField('articlecount')); $articles = (array) $this->getResponseField('articles'); $article = array_change_key_case((array) $articles['item'][0], CASE_LOWER); $this->assertEquals(array('title' => 'Travis CI', 'description' => 'Free Hosted Continuous Integration Platform for the Open Source Community', 'picurl' => 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'url' => 'https://travis-ci.org/netputer/wechat-php-sdk'), $article); $article = array_change_key_case((array) $articles['item'][1], CASE_LOWER); $this->assertEquals(array('title' => 'Travis CI 2', 'description' => '2 Free Hosted Continuous Integration Platform for the Open Source Community', 'picurl' => 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'url' => 'https://travis-ci.org/netputer/wechat-php-sdk'), $article); ExitTestHelper::clean(); }
} /** * 收到语音消息时触发,回复语音识别结果(需要开通语音识别功能) * * @return void */ protected function onVoice() { $this->responseText('收到了语音消息,识别结果为:' . $this->getRequest('Recognition')); } /** * 收到自定义菜单消息时触发,回复菜单的EventKey * * @return void */ protected function onClick() { $this->responseText('你点击了菜单:' . $this->getRequest('EventKey')); } /** * 收到未知类型消息时触发,回复收到的消息类型 * * @return void */ protected function onUnknown() { $this->responseText('收到了未知类型消息:' . $this->getRequest('msgtype')); } } $wechat = new MyWechat('weixin', TRUE); $wechat->run();
{ $status = $resultData['status']; if ("OK" == $status) { $items = array(); array_push($items, new NewsResponseItem('以下团购由大众点评提供', '以下团购由大众点评提供', "http://dp-openapi-weixin.cfapps.io/logo-weixin.png", "http://m.dianping.com/tuan")); $count = $resultData['count']; $deals = $resultData['deals']; foreach ($deals as $deal) { $title = $deal['title'] . PHP_EOL . '仅售' . $deal['list_price'] . '元'; $distance = $deal['distance']; if ($distance > 0) { $title .= PHP_EOL . '距离' . $distance . '米'; } $desc = $deal['description']; $picUrl = $deal['image_url']; $h5Url = $deal['deal_h5_url']; $newsItem = new NewsResponseItem($title, $desc, $picUrl, $h5Url); array_push($items, $newsItem); } $this->responseNews($items); } else { $this->responseText('Bad response for:' . $resultData['error']); } } } /** * Weixin Token为weixin,请自行设置,这里默认搜索上海的本地团购,其他城市请自行配置 */ $wechat = new MyWechat('weixin', TRUE); $wechat->setApiTool('http://api.dianping.com/v1/deal/find_deals', '5589931241', '16adbf199c38458f847f4c99d25cab4d', array('format' => 'json', 'city' => '上海', 'limit' => '5', 'is_local' => '1')); $wechat->run();
public static function setError($message, $code = -1) { self::$error = array('message' => $message, 'code' => $code); }