GithubHelp home page GithubHelp logo

lansespirit / laravel-wechat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from overtrue/laravel-wechat

0.0 2.0 0.0 60 KB

微信 SDK for Laravel, 基于 overtrue/wechat

License: MIT License

PHP 100.00%

laravel-wechat's Introduction

laravel-wechat

微信 SDK for Laravel 5, 基于 overtrue/wechat

安装

  1. 安装包文件
composer require "overtrue/laravel-wechat:dev-master"
  1. 添加 ServiceProvider 到您项目 config/app.php 中的 providers 部分:
'Overtrue\LaravelWechat\ServiceProvider',
  1. 创建配置文件:
php artisan vendor:publish --provider="Overtrue\LaravelWechat\ServiceProvider"

然后请修改 config/wechat.php 中对应的项即可。

  1. 添加下面行到 config/app.phpaliases 部分:
'Wechat' => 'Overtrue\LaravelWechat\Facade',

使用

由于我们已经添加了外观 Wechat,那么我们可以在控制器或者其它任何地方使用 Wechat::xxx 方式调用 SDK。

下面以接收普通消息为例写一个例子:

路由:

Route::any('/wechat', 'WechatController@serve');

这里假设您的域名为 overtrue.me 那么请登录微信公众平台 “开发者中心” 修改 “URL(服务器配置)” 为: http://overtrue.me/wechat

然后创建控制器 WechatController

<?php namespace App\Http\Controllers;

class WechatController extends Controller {

    /**
     * 处理微信的请求消息
     *
     * @return string
     */
    public function serve()
    {
        Wechat::on('message', function($message){
            \Log::info("收到来自'{$message['FromUserName']}'的消息:{$message['Content']}");
        });

        return Wechat::serve();
    }
}

更多使用请参考:https://github.com/overtrue/wechat/wiki/

License

MIT

laravel-wechat's People

Contributors

overtrue avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.