PHP code example of huo-zi / laravel-wechat-notification

1. Go to this page and download the library: Download huo-zi/laravel-wechat-notification 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/ */

    

huo-zi / laravel-wechat-notification example snippets


public function via($notifiable)
{
    /*
     * 支持的via列表
     * official_account:公众号
     * mini_program:小程序
     * open_official_account:开放平台公众号
     * open_mini_program:开放平台小程序
     * work:企业微信
     * open_work:开放平台企业微信
     */
    return ['official_account', 'mini_program'];
}

public function toOfficialAccount()
{
    return WechatMessage::officialAccount('app_name')->template('templateId')->url($url)->data(['fisrt'=>'...']);
}

public function toMiniProgram()
{
    return WechatMessage::miniProgram('app_name')->template($templateId)->formId($formId)->data([
        'first' => ''
        //
    ]);
}

public function toOpenOfficialAccount()
{
    return WechatMessage::openFlatform($name)->officateAccount($appId, $refreshToken, $accessToken)->template('templateId');
}
// 或使用闭包创建开放平台的公众号对象
public function toOpenOfficialAccount()
{
    return WechatMessage::openFlatform($name)->officateAccount(function ($open) {
        return $open->officateAccount($appId, $refreshToken, $accessToken);
    })->template('templateId');
}
// 或创建好开放平台对象后使用
public function toOpenOfficialAccount()
{
    return (new WechatPlatform($openPlatform))->officateAccount($appId, $refreshToken, $accessToken)->template($templateId);
}

public function toOpenMiniProgram()
{
    return WechatMessage::openFlatform($name)->miniProgram($appId, $refreshToken, $accessToken)->template($templateId);
}

public function toWork()
{
    return WechatMessage::work($name)->message($message)->ofAgent($agentId);
}

public function toOpenWork()
{
    return WechatMessage::openWork($name)->work($authCorpId, $permanentCode)->message($message)->ofAgent($agentId);
    // 同样也支持创建好开放平台对象后使用及闭包创建work对象
    $messenger = (new WechatOpenWork($openWork))->work(function($openWork) {
        return $openWork->work($authCorpId, $permanentCode);
    });
    return $messenger->message($message)->ofAgent($agentid);
}

public function routeNotificationForOfficialAccount($notification)
{
    // 返回当前model的公众号openid
    return $this->openid;
}

public function routeNotificationForMiniProgram($notification)
{
    // 返回当前model的小程序openid
}

public function routeNotificationForOpenOfficialAccount($notification)
{
    // 返回对应开放平台公众号用户的openid
}

public function routeNotificationForOpenMiniProgram($notification)
{
    // 返回对应开放平台小程序用户的openid
}

public function routeNotificationForWork($notification)
{
    // 返回当前model的企业微信userid
    return ;
}

public function routeNotificationForOpenWork($notification)
{
    // 返回对应开放平台企业用户userid
    return ;
}

use App\Notifications\WorkNotify;

$user->notify(new WorkNotify(new Text('你好啊~')));

Notification::send($users, new WorkNotify(new Markdown('#你好啊~')));