demo.php 674 B

123456789101112131415161718192021
  1. <?php
  2. include "wechat.class.php";
  3. $options = array(
  4. 'token'=>'tokenaccesskey', //填写你设定的key
  5. 'encodingaeskey'=>'encodingaeskey' //填写加密用的EncodingAESKey,如接口为明文模式可忽略
  6. );
  7. $weObj = new Wechat($options);
  8. $weObj->valid();//明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败
  9. $type = $weObj->getRev()->getRevType();
  10. switch($type) {
  11. case Wechat::MSGTYPE_TEXT:
  12. $weObj->text("hello, I'm wechat")->reply();
  13. exit;
  14. break;
  15. case Wechat::MSGTYPE_EVENT:
  16. break;
  17. case Wechat::MSGTYPE_IMAGE:
  18. break;
  19. default:
  20. $weObj->text("help info")->reply();
  21. }