不得不吐槽一下騰訊提供的官網開發文檔,真他媽跟屎同樣。php
個人智商都須要反覆看幾遍,還不懂。git
http://blog.163.com/ppy2790@126/blog/static/1032422412014022493717/github
這文章寫的還好。總算明白了。微信
另一個開源的sdk封裝不錯:app
https://github.com/dodgepudding/wechat-php-sdk微信公衆平臺
使用方法:加密
/**
* 微信公衆平臺PHP-SDK, 官方API部分
* @author dodge <dodgepudding@gmail.com>
* @link https://github.com/dodgepudding/wechat-php-sdk
* @version 1.2
* usage:
* $options = array(
* 'token'=>'tokenaccesskey', //填寫你設定的key
* 'encodingaeskey'=>'encodingaeskey', //填寫加密用的EncodingAESKey
* 'appid'=>'wxdk1234567890', //填寫高級調用功能的app id
* 'appsecret'=>'xxxxxxxxxxxxxxxxxxx' //填寫高級調用功能的密鑰
* );
* $weObj = new Wechat($options);
* $weObj->valid();
* $type = $weObj->getRev()->getRevType();
* switch($type) {
* case Wechat::MSGTYPE_TEXT:
* $weObj->text("hello, I'm wechat")->reply();
* exit;
* break;
* case Wechat::MSGTYPE_EVENT:
* ....
* break;
* case Wechat::MSGTYPE_IMAGE:
* ...
* break;
* default:
* $weObj->text("help info")->reply();
* }
*
* //獲取菜單操做:
* $menu = $weObj->getMenu();
* //設置菜單
* $newmenu = array(
* "button"=>
* array(
* array('type'=>'click','name'=>'最新消息','key'=>'MENU_KEY_NEWS'),
* array('type'=>'view','name'=>'我要搜索','url'=>'http://www.baidu.com'),
* )
* );
* $result = $weObj->createMenu($newmenu);
*/url