PHP code example of yuanshe / wechat-sdk

1. Go to this page and download the library: Download yuanshe/wechat-sdk 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/ */

    

yuanshe / wechat-sdk example snippets




use Yuanshe\WeChatSDK\WeChat;

$wechat = new WeChat($config, $cacheClass);


// 以属性的形式直接调用。需使用LowerCamelCase(小写驼峰)
$wechat->oAuth;

// 通过model方法调用。需使用UpperCamelCase(大写驼峰)
$wechat->model('OAuth');

$user_list = $wechat->user->getList();

$menu = $wechat->menu->get();



if (!$wechat->checkNotifyIP($notifyIP)) {
    // 校验不通过
}




use Yuanshe\WeChatSDK\Notify;

$notify = $wechat->notify($queries, $body);
if ($notify instanceof Notify) {
    // ...
} elseif (is_string($notify)) {
    echo $notify;
}




use Yuanshe\WeChatSDK\Notify;

if (
    $notify->getType() == Notify::TYPE_MESSAGE
    && $notify->getSubType() == 'text'
) {
    echo $notify->replyText('您输入了:' . $notify->getContent('Content'));
}