PHP code example of angel-project / wechat

1. Go to this page and download the library: Download angel-project/wechat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

angel-project / wechat example snippets


  build::post('your/url',function(){

    $wx = new angel\wechat($appid,$secret,$token); //初始化微信object

    $wx->listen('text','hi',function($input,$wx){
      $wx->return('text',[
        'to' => $input->FromUserName,
        'content' => 'hello!'
      ]);
    }); //当用户输入hi时,返回字符串hello!

    $wx->listen('event','subscribe',function($input,$wx){
      $wx->return('news',[
        'to' => $input->FromUserName,
        'articles' => [[
          'title' => 'hi!',
          'description' => 'long time no see',
          'picurl' => 'yoururl.com/img.jpg',
          'url' => 'yoururl.com'
        ]]
      ]); //返回主题
    }); //当用户关注时触发,返回图文消息

    $wx->run(); //执行监听

  });

  $wx = new angel\wechat($appid,$secret,$token); //初始化微信object

  $menu = [[
    'type' => 'click',
    'name' => '欢迎光临',
    'key' => 'welcome'
  ]]; //生成一个click时间菜单,具体创建菜单指令请参考微信开发者档案

  $at = $wx->access_token();  //获取access token
  $wx->menu($at,$menu); //生成菜单