| Package Data | |
|---|---|
| Maintainer Username: | mistcheng |
| Package Create Date: | 2016-09-28 |
| Package Last Update: | 2016-10-14 |
| Home Page: | http://oukei.me/Wechat-Web-Api-Based-On-Laravel-PHP-Framework/ |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-30 03:09:37 |
| Package Statistics | |
|---|---|
| Total Downloads: | 9 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 14 |
| Total Watchers: | 2 |
| Total Forks: | 4 |
| Total Open Issues: | 0 |
7*24hours no-end running,- easy to use, support sending/receiving multi type messages
- graceful system architecture, support
cross platformdevelopment and flexible customextensions- support
Restful Api,async message processingandmessage event broadcasting- based on
Php, the best language in The World! :)
- This System is composed of 3 independent components
- The
Middlecomponent is core of The System, doing qrcode scan & message listening; I do a lot of work for pupose of robust. Meantime, as a connector, it supports message-sending ability for theLeftcomponent, and pushs simple-formated message to theRightcomponent. Run commandphp artisan wechat:listento make it working.- The
Leftcomponent is used for sending message, the user can send message to any friends in his code. classApp\Console\Commands\WechatSendis a sample, run commandphp artisan wechat:sendto make it working.- The
Rightcomponent is used for processing message, the user can do anything for the coming message. The jobApp\Jobs\ProcessWechatMessageprocess each message into more formatted message(text,share,image,voice,file, etc). Next, It fires theApp\Events\WechatMessageEventevent to the subscribers, who can do some custom things with the message. classApp\Listeners\SaveWechatMessageListeneris a sample that saving the message into the DB.Advantage: The three components are 3 independent Process. this can grantee the non-ending running of theMiddlepart, at the same time, the user can do any extensions in theLeftandRightpart without disturbing theMiddlepart.
- php 5.6 or more
- php composer
- redis (optional)
- mysql (optional)
git clone https://github.com/mistcheng/sowechat.git
cd sowechat
composer install
config/wechat.php is wechat config file<?php
return [
'debug' => env('WECHAT_DEBUG', false), // debug mode
'web_api' => [
'connect_timeout' => 30, // http request timeout
'max_attempts' => 10, // max request attempts in half minutes
],
'job' => [
'connection' => env('QUEUE_DRIVER', 'database'), // wehcat message queu engine, recommend database|redis
'queue' => env('JOB_QUEUE', 'default'), // queue name
],
];
In section
2.1, the optionwechat.job.connectionshould be configured in the fileconfig/database.php.
wechat.job.connectionwithdatabase, the option database.connections.mysqlmust be configured correctly'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
wechat.job.connectionwithredis, the option database.redisshould be configured properly.'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
cd sowechat
php artisan migrate
Middlecomponent for newphp artisan wechat:listen --new
There will be a new qrcode in the folder
storage/app/wechat, use your wechat scaning it to login.
Middlecomponent without re-loginphp artisan wechat:listen
Run the command without passing argument --new
php artisan queue:work
See Job
App\Jobs\ProcessWechatMessageand sample classApp\Listeners\SaveWechatMessageListenerfor more detail.
php artisan wechat:send
See class
App\Console\Commands\WechatSendfor more detail.
php artisan wechat:serve --port=your_port
When you call the api, you must start the web server. The easiest way is start a mini server with the command above. Also, you can deploy you code use
ApacheNginxetc
there has some examples, this will return a json response {'ret':0, 'message':'xxx'}, success if the ret equals 0
# send text, POST request, need params `to` and `content`
curl -H 'Accept:application/json' --data "to=$to_user_name&content=$your_content" http://localhost:$your_port/api/wechat/messages/text
# send image, POST request, need params `to` and `path`
curl -H 'Accept:application/json' --data "to=$to_user_name&path=$image_path" http://localhost:$your_port/api/wechat/messages/image
# send emotion, POST request, need params `to` and `path`
curl -H 'Accept:application/json' --data "to=$to_user_name&path=$emotion_path" http://localhost:$your_port/api/wechat/messages/emotion
# send file, POST request, need params `to` and `path`
curl -H 'Accept:application/json' --data "to=$to_user_name&path=$file_path" http://localhost:$your_port/api/wechat/messages/file
This software shall not be used for commercial purposes only